beyondnn 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (135) hide show
  1. beyondnn-0.1.0/.gitignore +40 -0
  2. beyondnn-0.1.0/CHANGELOG.md +267 -0
  3. beyondnn-0.1.0/CITATION.cff +25 -0
  4. beyondnn-0.1.0/LICENSE +202 -0
  5. beyondnn-0.1.0/PKG-INFO +560 -0
  6. beyondnn-0.1.0/README.md +523 -0
  7. beyondnn-0.1.0/beyondnn/__init__.py +82 -0
  8. beyondnn-0.1.0/beyondnn/_testing/__init__.py +7 -0
  9. beyondnn-0.1.0/beyondnn/_testing/attribution_models.py +84 -0
  10. beyondnn-0.1.0/beyondnn/_testing/audit_scenarios.py +679 -0
  11. beyondnn-0.1.0/beyondnn/_testing/causal_models.py +77 -0
  12. beyondnn-0.1.0/beyondnn/_testing/concept_models.py +84 -0
  13. beyondnn-0.1.0/beyondnn/_testing/faithfulness_models.py +97 -0
  14. beyondnn-0.1.0/beyondnn/_testing/models.py +236 -0
  15. beyondnn-0.1.0/beyondnn/attribution/__init__.py +70 -0
  16. beyondnn-0.1.0/beyondnn/attribution/captum.py +203 -0
  17. beyondnn-0.1.0/beyondnn/attribution/claims.py +171 -0
  18. beyondnn-0.1.0/beyondnn/attribution/native.py +299 -0
  19. beyondnn-0.1.0/beyondnn/attribution/runner.py +567 -0
  20. beyondnn-0.1.0/beyondnn/attribution/spec.py +246 -0
  21. beyondnn-0.1.0/beyondnn/audits/__init__.py +184 -0
  22. beyondnn-0.1.0/beyondnn/audits/engine.py +1860 -0
  23. beyondnn-0.1.0/beyondnn/audits/evidence.py +761 -0
  24. beyondnn-0.1.0/beyondnn/audits/plan.py +212 -0
  25. beyondnn-0.1.0/beyondnn/audits/render.py +183 -0
  26. beyondnn-0.1.0/beyondnn/audits/report.py +538 -0
  27. beyondnn-0.1.0/beyondnn/audits/uncertainty.py +175 -0
  28. beyondnn-0.1.0/beyondnn/concepts/__init__.py +108 -0
  29. beyondnn-0.1.0/beyondnn/concepts/_core.py +270 -0
  30. beyondnn-0.1.0/beyondnn/concepts/data.py +209 -0
  31. beyondnn-0.1.0/beyondnn/concepts/encoding.py +519 -0
  32. beyondnn-0.1.0/beyondnn/concepts/features.py +442 -0
  33. beyondnn-0.1.0/beyondnn/concepts/use.py +537 -0
  34. beyondnn-0.1.0/beyondnn/concepts/validate.py +430 -0
  35. beyondnn-0.1.0/beyondnn/concepts/verify.py +588 -0
  36. beyondnn-0.1.0/beyondnn/core/__init__.py +6 -0
  37. beyondnn-0.1.0/beyondnn/core/hooks.py +403 -0
  38. beyondnn-0.1.0/beyondnn/core/persistence.py +255 -0
  39. beyondnn-0.1.0/beyondnn/core/samples.py +61 -0
  40. beyondnn-0.1.0/beyondnn/core/sites.py +208 -0
  41. beyondnn-0.1.0/beyondnn/core/tensors.py +125 -0
  42. beyondnn-0.1.0/beyondnn/core/trace.py +896 -0
  43. beyondnn-0.1.0/beyondnn/core/units.py +101 -0
  44. beyondnn-0.1.0/beyondnn/explain/__init__.py +42 -0
  45. beyondnn-0.1.0/beyondnn/explain/bundle.py +644 -0
  46. beyondnn-0.1.0/beyondnn/explain/handle.py +125 -0
  47. beyondnn-0.1.0/beyondnn/explain/response.py +1157 -0
  48. beyondnn-0.1.0/beyondnn/explain/views.py +244 -0
  49. beyondnn-0.1.0/beyondnn/faithfulness/__init__.py +96 -0
  50. beyondnn-0.1.0/beyondnn/faithfulness/claims.py +167 -0
  51. beyondnn-0.1.0/beyondnn/faithfulness/runner.py +978 -0
  52. beyondnn-0.1.0/beyondnn/faithfulness/spec.py +494 -0
  53. beyondnn-0.1.0/beyondnn/faithfulness/stability.py +574 -0
  54. beyondnn-0.1.0/beyondnn/faithfulness/stats.py +180 -0
  55. beyondnn-0.1.0/beyondnn/faithfulness/verify.py +313 -0
  56. beyondnn-0.1.0/beyondnn/interventions/__init__.py +62 -0
  57. beyondnn-0.1.0/beyondnn/interventions/claims.py +123 -0
  58. beyondnn-0.1.0/beyondnn/interventions/metrics.py +211 -0
  59. beyondnn-0.1.0/beyondnn/interventions/runner.py +850 -0
  60. beyondnn-0.1.0/beyondnn/interventions/spec.py +282 -0
  61. beyondnn-0.1.0/beyondnn/protocols.py +98 -0
  62. beyondnn-0.1.0/beyondnn/provenance/__init__.py +18 -0
  63. beyondnn-0.1.0/beyondnn/provenance/collect.py +106 -0
  64. beyondnn-0.1.0/beyondnn/provenance/fingerprint.py +234 -0
  65. beyondnn-0.1.0/beyondnn/py.typed +0 -0
  66. beyondnn-0.1.0/beyondnn/schema/__init__.py +231 -0
  67. beyondnn-0.1.0/beyondnn/schema/_canonical.py +121 -0
  68. beyondnn-0.1.0/beyondnn/schema/_types.py +298 -0
  69. beyondnn-0.1.0/beyondnn/schema/attribution.py +272 -0
  70. beyondnn-0.1.0/beyondnn/schema/audit.py +410 -0
  71. beyondnn-0.1.0/beyondnn/schema/base.py +276 -0
  72. beyondnn-0.1.0/beyondnn/schema/claims.py +439 -0
  73. beyondnn-0.1.0/beyondnn/schema/codec.py +187 -0
  74. beyondnn-0.1.0/beyondnn/schema/concepts.py +491 -0
  75. beyondnn-0.1.0/beyondnn/schema/errors.py +55 -0
  76. beyondnn-0.1.0/beyondnn/schema/faithfulness.py +253 -0
  77. beyondnn-0.1.0/beyondnn/schema/interventions.py +347 -0
  78. beyondnn-0.1.0/beyondnn/schema/limitations.py +304 -0
  79. beyondnn-0.1.0/beyondnn/schema/provenance.py +302 -0
  80. beyondnn-0.1.0/beyondnn/schema/records.py +114 -0
  81. beyondnn-0.1.0/beyondnn/schema/status.py +205 -0
  82. beyondnn-0.1.0/beyondnn/schema/values.py +304 -0
  83. beyondnn-0.1.0/examples/01_quickstart.py +97 -0
  84. beyondnn-0.1.0/examples/02_attribution.py +38 -0
  85. beyondnn-0.1.0/examples/03_intervention.py +74 -0
  86. beyondnn-0.1.0/examples/04_faithfulness.py +97 -0
  87. beyondnn-0.1.0/examples/05_concepts.py +175 -0
  88. beyondnn-0.1.0/examples/06_audit.py +102 -0
  89. beyondnn-0.1.0/examples/07_save_reload.py +97 -0
  90. beyondnn-0.1.0/pyproject.toml +126 -0
  91. beyondnn-0.1.0/tests/conftest.py +178 -0
  92. beyondnn-0.1.0/tests/data/audit_plan_v1.json +1 -0
  93. beyondnn-0.1.0/tests/data/phase7_5_results_manifest.json +36 -0
  94. beyondnn-0.1.0/tests/test_attribution.py +805 -0
  95. beyondnn-0.1.0/tests/test_attribution_captum.py +168 -0
  96. beyondnn-0.1.0/tests/test_attribution_optional.py +42 -0
  97. beyondnn-0.1.0/tests/test_attribution_schema.py +178 -0
  98. beyondnn-0.1.0/tests/test_audit.py +884 -0
  99. beyondnn-0.1.0/tests/test_audit_75.py +450 -0
  100. beyondnn-0.1.0/tests/test_benchmark_smoke.py +74 -0
  101. beyondnn-0.1.0/tests/test_claims.py +435 -0
  102. beyondnn-0.1.0/tests/test_concepts.py +654 -0
  103. beyondnn-0.1.0/tests/test_declared_model.py +192 -0
  104. beyondnn-0.1.0/tests/test_diagnostics_kwargs.py +72 -0
  105. beyondnn-0.1.0/tests/test_estimand.py +198 -0
  106. beyondnn-0.1.0/tests/test_evidence_status.py +239 -0
  107. beyondnn-0.1.0/tests/test_examples.py +32 -0
  108. beyondnn-0.1.0/tests/test_explain.py +204 -0
  109. beyondnn-0.1.0/tests/test_faithfulness.py +839 -0
  110. beyondnn-0.1.0/tests/test_faithfulness_why.py +321 -0
  111. beyondnn-0.1.0/tests/test_fingerprint.py +564 -0
  112. beyondnn-0.1.0/tests/test_golden_workflow.py +383 -0
  113. beyondnn-0.1.0/tests/test_hooks.py +713 -0
  114. beyondnn-0.1.0/tests/test_intervention_schema.py +237 -0
  115. beyondnn-0.1.0/tests/test_intervention_units.py +207 -0
  116. beyondnn-0.1.0/tests/test_interventions.py +724 -0
  117. beyondnn-0.1.0/tests/test_limitations.py +97 -0
  118. beyondnn-0.1.0/tests/test_migration_matrix.py +204 -0
  119. beyondnn-0.1.0/tests/test_package.py +68 -0
  120. beyondnn-0.1.0/tests/test_persistence.py +414 -0
  121. beyondnn-0.1.0/tests/test_phase1_audit.py +92 -0
  122. beyondnn-0.1.0/tests/test_phase4.py +781 -0
  123. beyondnn-0.1.0/tests/test_phase75_analysis.py +109 -0
  124. beyondnn-0.1.0/tests/test_phase75_immutable.py +18 -0
  125. beyondnn-0.1.0/tests/test_phase775.py +321 -0
  126. beyondnn-0.1.0/tests/test_phase775_analysis.py +198 -0
  127. beyondnn-0.1.0/tests/test_provenance.py +339 -0
  128. beyondnn-0.1.0/tests/test_readme.py +53 -0
  129. beyondnn-0.1.0/tests/test_record_identity.py +195 -0
  130. beyondnn-0.1.0/tests/test_reference_models.py +346 -0
  131. beyondnn-0.1.0/tests/test_serialization.py +637 -0
  132. beyondnn-0.1.0/tests/test_sites.py +361 -0
  133. beyondnn-0.1.0/tests/test_trace.py +761 -0
  134. beyondnn-0.1.0/tests/test_trace_schema.py +375 -0
  135. beyondnn-0.1.0/tests/test_unit_axes.py +534 -0
@@ -0,0 +1,40 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *.egg-info/
5
+ build/
6
+ dist/
7
+ .eggs/
8
+
9
+ # Environments
10
+ .venv/
11
+ venv/
12
+ .env
13
+
14
+ # Tooling caches
15
+ .pytest_cache/
16
+ .mypy_cache/
17
+ .ruff_cache/
18
+ .coverage
19
+ coverage.xml
20
+ htmlcov/
21
+
22
+ # Trace / benchmark outputs (never commit large artifacts)
23
+ *.pt
24
+ *.safetensors
25
+ benchmarks/results/
26
+ runs/
27
+
28
+ # OS / editors
29
+ .DS_Store
30
+ .idea/
31
+ .vscode/
32
+
33
+ # Phase 5.5 experiment artifacts (checkpoints, downloads, raw per-test traces)
34
+ experiments/phase5_5/artifacts/
35
+ # Phase 6 experiment logs
36
+ experiments/phase6/artifacts/
37
+
38
+ experiments/phase7/artifacts/
39
+ experiments/phase7_5/artifacts/
40
+ experiments/phase7_75/artifacts/
@@ -0,0 +1,267 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project are documented here. The format follows
4
+ [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and the project will use
5
+ [Semantic Versioning](https://semver.org/) once released. The trace `schema_version` is versioned separately
6
+ (see `docs/design/TRACE_SCHEMA_PROPOSAL.md`).
7
+
8
+ ## [Unreleased]
9
+
10
+ ## [0.1.0] - 2026-10-01
11
+
12
+ **The first public release.** Pre-1.0 research software; the public API is frozen ([`docs/API_FREEZE.md`](docs/API_FREEZE.md)). Not yet published on PyPI at the time of tagging.
13
+
14
+ ### Added
15
+ - **Provenance-aware tracing** (`bnn.trace`, `bnn.recording`, `bnn.instrument`): structured, content-addressed, versioned records bound to the model checkpoint, the sample identity and the software environment; persistence with full re-validation on load.
16
+ - **Explicit evidence statuses** on every record: OBSERVED, MEASURED, ATTRIBUTED, INTERVENTIONAL, ESTIMATED_CAUSAL (reserved), VALIDATED_CONCEPT, GENERATED.
17
+ - **Attribution** (`bnn.attribute`): gradient, input × gradient and integrated gradients (native, and via an optional Captum adapter), recorded as ATTRIBUTED evidence with baselines and diagnostics.
18
+ - **Controlled interventions** (`bnn.intervene`): INTERVENTIONAL effects with declared claims and threshold tests.
19
+ - **Faithfulness protocols** (`beyondnn.faithfulness`): comprehensiveness and sufficiency with explicit replacements and matched random controls; curves, stability and diagnostics.
20
+ - **Concepts** (`beyondnn.concepts`): features (neurons, directions, SAE latents), concept datasets, proposals, encoding and use tests, and validation under a declared policy (UNLABELED_FEATURE → PROPOSED_CONCEPT → VALIDATED_CONCEPT).
21
+ - **Scientific audits** (`bnn.audit`, `beyondnn.audits`):
22
+ - deterministic, model-free classification of declared claims from re-derived, in-scope evidence: standings and typed findings;
23
+ - PRIMARY / ALTERNATIVE / STRESS_TEST configuration roles;
24
+ - sensitivity profiles; uncertainty intervals;
25
+ - declared unit eligibility (e.g. content tokens vs all tokens);
26
+ - control-attainability checks.
27
+ - **Save / reload / re-audit / verify:** `audits.save_evidence`, `load_evidence`, `verify_report`; reports record the BeyondNN version and audit semantics that produced them.
28
+ - **Structured WHY** (`bnn.compose`): recorded evidence arranged by kind, never merged into a narrative or a score, with what was not evaluated.
29
+ - **Reproducibility and migrations:** tested migrations for every older record version; `uv.lock`.
30
+
31
+ ### Scientific safeguards
32
+ - **Attribution is not causal evidence:** attribution-only causal claims are UNSUPPORTED.
33
+ - **Decodability is not causal use:** decodable-but-unused concepts stay PROPOSED, and generated labels are never upgraded.
34
+ - **Replacements are always explicit;** there is no implicit zero.
35
+ - **Evidence from another checkpoint, sample or dataset scope is excluded and reported,** never silently counted.
36
+ - **Alternative and stress-test configurations never rewrite the PRIMARY standing.**
37
+ - **No global explanation, interpretability, trust or confidence score.**
38
+
39
+ ### Documentation and release
40
+ - **Documentation:** a public README (concepts, quickstart, end-to-end example, validation with its scope, limitations); a topic-organised `docs/`; a reproducibility guide; the full research record (pre-registered plans, reports, negative results).
41
+ - **Examples:** numbered, public-API examples (`examples/01_quickstart.py` … `07_save_reload.py`), all executed in CI.
42
+ - **CI:** tests on Python 3.10 / 3.12 / 3.14 (Linux), a Captum job, lint, mypy --strict, build and a clean-wheel check.
43
+ - **Release:** a manual-only PyPI Trusted Publishing workflow ([`docs/release/PYPI_RELEASE.md`](docs/release/PYPI_RELEASE.md)).
44
+ - **Community files:** `CONTRIBUTING.md`, `SECURITY.md`, `CODE_OF_CONDUCT.md`, `CITATION.cff`.
45
+
46
+ ## Development history before 0.1.0
47
+
48
+ The entries below record the pre-registered development stages in detail, including negative results and deviations (see [`docs/README.md`](docs/README.md#development-history)).
49
+
50
+ ### Public release preparation
51
+ - **Documentation:**
52
+ - README rewritten for external users: concepts, installation, quickstart, end-to-end example, validation (scoped) and limitations;
53
+ - documentation index reorganised by topic;
54
+ - `docs/REPRODUCIBILITY.md` and `experiments/README.md` added.
55
+ - **Examples:** numbered public-API examples `01_quickstart.py` … `07_save_reload.py`, all executed by the test suite. The earlier examples were renamed: `phase4_redundant_path.py` → `03_intervention.py`, `phase6_concepts.py` → `05_concepts.py`, `phase7_audit.py` → `06_audit.py`.
56
+ - **Packaging:**
57
+ - project URLs, author, classifiers;
58
+ - a `dev` dependency group for `uv sync`;
59
+ - `uv.lock`;
60
+ - the wheel contains only the `beyondnn` package;
61
+ - the sdist include list is anchored.
62
+ - **Community files:** `CONTRIBUTING.md` (uv workflow, scientific rules, invariants, migrations), `SECURITY.md` (GitHub private vulnerability reporting), Code of Conduct contact route, `CITATION.cff` (software).
63
+ - **GitHub:** CI (tests on Python 3.10 / 3.12 / 3.14, a Captum job, lint, mypy, build and clean-wheel checks), a manual build-only release workflow, issue and PR templates, Dependabot.
64
+
65
+ ### Changed (pre-Phase-8 hardening)
66
+ - **Audit reports (format 3)** record their `producer` (BeyondNN version, audit semantics; ADR-056). Format 2 still loads. `verify_report` compares scientific content and names a semantics difference.
67
+ - **Trace load errors** name the trace directory.
68
+
69
+ ### Added (pre-Phase-8 hardening)
70
+ - A permanent golden scientific-workflow test, a migration-matrix test, provenance-completeness and named-claim-lookup tests.
71
+ - `docs/PRE_PHASE8_INVARIANTS.md`.
72
+
73
+ ### Added
74
+ - **Phase 7.75: scientific fixes** (ADR-053 to ADR-055):
75
+ - declared unit eligibility for selections, controls and selection claims (`eligible=` / `eligibility=`; `evidence_selection` v3, `audit_plan` v3, with migrations);
76
+ - the audit treats unattainable control criteria as inconclusive (`control_criterion_unattainable`);
77
+ - the audit distinguishes competitive-only failure (`effect_without_competitive_advantage`) and never uses evidence of another eligibility (`eligibility_mismatch`);
78
+ - concept `min_change` is declared in target units (policy);
79
+ - experiments in `experiments/phase7_75/` (TD programs with program-defined truth, concept calibration, D1/D2 and C1/C2, InterpBench re-audit, NLI stratification).
80
+
81
+ ### Added (Phase 7.5)
82
+ - **Phase 7.5: audit refinement, uncertainty, external validation, API freeze** (ADR-048 to ADR-052):
83
+ - declared configuration roles (`audits.role`; PRIMARY / ALTERNATIVE / STRESS_TEST) with PRIMARY-only standings;
84
+ - `alternative_reverses` / `stress_test_reverses` / `undeclared_configuration` / `primary_untested` findings;
85
+ - a `SensitivityProfile` per group; `configuration_level_disagreement` findings;
86
+ - `audit_plan` v2 (v1 migrates); report format v2;
87
+ - uncertainty: `audits.wilson` / `bootstrap` / `paired_bootstrap` and `Interval`; per-sample claims carry Wilson intervals;
88
+ - evidence helpers `audits.sample_id` / `traces_of` / `save_evidence` / `load_evidence`;
89
+ - `concepts.load_validation` (a WHY and an audit from saved traces); `protocols.PROTOCOL_VERSIONS`;
90
+ - `interventions.metrics.margin`; named replacements (`faithfulness.replacement(t, name=...)`);
91
+ - `docs/API_FREEZE.md`.
92
+ - **Experiments:** `experiments/phase7_5/`: InterpBench / Tracr external validation, central A–D, e-SNLI rationales, token probes, the external-researcher workflow, mutations, performance, hypothesis evaluation and figure data.
93
+
94
+ ### Changed
95
+ - **Breaking (ADR-052):** `faithfulness.comprehensiveness`, `sufficiency` and `curve` require `replacement=`; there is no implicit zero replacement.
96
+ - `Interval.describe()` prints non-integer levels as declared (98.75%, not 99%).
97
+
98
+ ### Added (Phase 7 and earlier)
99
+ - **Phase 7: scientific audits** (`bnn.audit`, `bnn.audits`, ADR-044 to ADR-047):
100
+ - a deterministic, model-free audit of recorded traces (or saved trace paths) under a pre-declared `AuditPlan` (record kind `audit_plan` v1);
101
+ - integrity and re-derivation of every result; provenance and scope exclusion;
102
+ - 7 standings and 13 finding kinds with categorical severities; no score;
103
+ - assumption-axis sensitivity (protocol, threshold, replacement, k, null, method, dataset);
104
+ - re-evaluation under declared alternative thresholds;
105
+ - structural overclaims (attribution → causal, decodable → used, generated → validated, narrower estimand, untested invariance, missing controls);
106
+ - per-sample distributions with counterexample identities and caps;
107
+ - concept audits; coverage;
108
+ - deterministic report JSON, `verify_report`, and an AUDIT section in the WHY (`bnn.compose(..., audit=report)`).
109
+ - **Trace-level concept re-derivation** (`concepts.verify.verify_*_trace`, `verify_feature_record`): a partial fix of P6-4 (audits work from saved traces).
110
+ - **Documentation and experiments:** Phase 7 literature review, differentiation, plan, report, `docs/audit/`, `examples/phase7_audit.py`, `benchmarks/bench_audit.py`, `experiments/phase7/`, and `docs/roadmap/TRACE3B_FUTURE.md` (a boundary note only).
111
+ - **Phase 6: concepts and concept validation** (`bnn.concepts`, ADR-039 to ADR-043):
112
+ - features: neurons, directions, SAE latents (a tensor-only adapter);
113
+ - train-only discovery (`fit_direction`, `search_neurons`);
114
+ - concept datasets and proposals (always PROPOSED), and GENERATED labels;
115
+ - `encoding_test` (ENCODES; held-out AUROC against mandatory controls; counterexamples);
116
+ - `use_test` (DECREASES/INCREASES by removal, SUFFICIENT_FOR by retention; the intervention and reference are required; mandatory random-feature controls);
117
+ - `validate` (derived semantic status under `POLICY_V1`; no global REJECTED state);
118
+ - `activation` (VALIDATED_CONCEPT records only for validated concepts);
119
+ - full re-derivation (`concepts.verify`) and a CONCEPTS section in the structured WHY (`bnn.compose(concepts=[...])`);
120
+ - `Coverage.concepts_evaluated`.
121
+ - **DIRECTION interventions** (`interventions.direction`; `InterventionRecord` v4): projection removal and retention against a declared reference.
122
+ - **`Subject.feature`** (`Claim` v3; the golden claim id changes).
123
+ - **Documentation:** Phase 6 literature review, plan, report, `docs/concepts/`, and `examples/phase6_concepts.py`.
124
+ - **Phase 5.5: realistic faithfulness validation.** Pre-registered experiments (`docs/PHASE_5_5_PLAN.md`) on a trained MLP, a trained CNN and BERT-tiny/SST-2 (`experiments/phase5_5/`, with its own pinned requirements; nothing added to the core install). Also `docs/PHASE_5_5_API_REVIEW.md` and `docs/PHASE_5_5_REPORT.md`.
125
+ - **Declared unit axes (ADR-034):**
126
+ - `unit_axes` on interventions, selections (`ranking`, `top_k`, `units`, `selector`) and claim subjects, for pixels, channels and token positions;
127
+ - an explicit `reduce` (`sum`/`abs_sum`/`l2`) for per-unit attribution scores;
128
+ - diagnostics accept the same.
129
+ - Record versions: `InterventionRecord` v3, `Claim` v2, `EvidenceSelection` v2, with migrations. The golden claim id changes.
130
+ - **Perturbation-magnitude-matched controls (ADR-035):** `faithfulness.controls(n, seed=, match="magnitude", strata=4)`. The magnitudes are recorded and re-derived in composition.
131
+ - **Keyword model inputs** in `stability`, `method_agreement`, `baseline_sensitivity` and `ig_step_sensitivity` (ADR-037).
132
+ - **Phase 5: faithfulness tests** (`bnn.faithfulness`, ADR-032, ADR-033):
133
+ - unit-level and model-input interventions and comparison families (`InterventionRecord` v2);
134
+ - `comprehensiveness`/`sufficiency` claim tests with matched random controls;
135
+ - removal/retention curves;
136
+ - `stability` under caller-declared transformations;
137
+ - dataset runs with `counterexample` and `paired_control` summaries;
138
+ - method diagnostics;
139
+ - `EvidenceSelection` and `ProtocolResult` records; no new evidence status;
140
+ - composition into the structured WHY, with re-derivation of every result;
141
+ - `Coverage.faithfulness_protocols`;
142
+ - ground-truth models;
143
+ - protocol documentation;
144
+ - a faithfulness benchmark and the Phase 5 report.
145
+ - **Phase 4: structured WHY / evidence synthesis** (`bnn.compose`, ADR-031, ADR-026 amended):
146
+ - `EvidenceBundle` validates one explanation context (model, declaration, exact input sample, instance scope, one target) and refuses anything incompatible;
147
+ - recorded claim-test results are re-derived from their evidence;
148
+ - `Why` sections by epistemic status over the original records, with claims, tests, and policy assessments (MIXED preserved), the limitations union, `Coverage` (faithfulness and concepts never evaluated), `by_status`, and `origin`;
149
+ - deterministic `render()` and `to_dict()`;
150
+ - README walk-through, `examples/phase4_redundant_path.py`, a synthesis benchmark, and the Phase 4 report (gate: GO WITH EXPLICIT LIMITATIONS).
151
+ - ADR-030 and ADR-031 finalized (owner approval of `InputRecord.sample_id`).
152
+ - `InputRecord.sample_id` (record version 3): the exact input identity, with a migration from v2.
153
+
154
+ ### Fixed
155
+ - `TraceResult` lookups by record kind and pass were linear scans, which made comparison families of thousands of passes quadratic (ADR-043; 8× faster on a concept use test).
156
+ - Attribution no longer refuses deterministic models whose grad-enabled and no-grad forwards differ by rounding: the tolerance is scaled to the output precision (ADR-036; found on a trained CNN).
157
+ - Curves over declared units keep `unit_axes`/`unit_reduction` in their selection record, and a declared reduction is recorded even when each unit is one element. Both were found by composition on realistic models.
158
+ - `intervention_threshold` can decide only NECESSARY_FOR/DECREASES/INCREASES, independent of the protocol registry. Composition refuses decisive results from protocols that do not justify the claim's relation (found by the Phase 4 mutation audit).
159
+ - **Phase 3: attribution** (`bnn.attribute`, `bnn.attribution`, ADR-030):
160
+ - ATTRIBUTED `AttributionRecord` and `AttributionReduction` records, with container checks for site/call/pass and shape;
161
+ - native gradient, input × gradient, and Integrated Gradients (explicit baseline, declared rule, completeness diagnostic) on float inputs or one call of a module output;
162
+ - explicit scalar targets (built-in metrics, never an implicit sum) and explicit reductions;
163
+ - guards on model state, gradients, caller tensors, hooks, and RNG;
164
+ - Captum 0.9 adapters (optional extra `beyondnn[captum]`) cross-checked against native;
165
+ - the `attribution_threshold` protocol (ATTRIBUTED_TO only) in a central protocol registry (`beyondnn.protocols`);
166
+ - four attribution limitations;
167
+ - `Why.attributions`;
168
+ - an attribution benchmark and the Phase 3 report (gate: GO WITH EXPLICIT LIMITATIONS).
169
+ - **Phase 2: causal interventions** (`bnn.intervene`, `bnn.interventions`, ADR-028):
170
+ - `InterventionRecord`/`CausalEffect` schema;
171
+ - zero, constant, and patch interventions on module outputs, via BeyondNN-owned hooks inside one recording;
172
+ - paired baseline/intervention passes with refusal of training mode, RNG consumption, and state drift;
173
+ - INSTANCE and FINITE_SAMPLE INTERVENTIONAL effects (`intervention − baseline`);
174
+ - scalar metrics;
175
+ - the `intervention_threshold` claim protocol with a protocol registry;
176
+ - ground-truth causal models;
177
+ - four intervention limitations.
178
+ - Caller metrics carry a declared identity (ADR-029): `metrics.custom(name, fn, *, implementation_revision, config)`, `MetricDeclaration`, and `MetricSpec.target()`. Unversioned caller metrics are refused. `causal_effect` is now record version 2, with a migration.
179
+ - Phase 2 benchmark (`benchmarks/bench_interventions.py`), a README intervention example executed by tests, and the Phase 2 report (gate: GO WITH EXPLICIT LIMITATIONS).
180
+ - Comparisons also refuse input modification in place and drift in execution conditions between the paired passes.
181
+ - **M1.1: trace schema 0.1** (`beyondnn.schema`):
182
+ - immutable records with content-derived ids;
183
+ - evidence status bound to record kind, with explicit derivation rules;
184
+ - `InputRecord`, `OutputRecord`, `ActivationRecord`, `TensorRef`, `TraceLimitation`;
185
+ - `Claim`, `ClaimTestSpec`, `ClaimTestResult`, and derived `Assessment` under explicit policies;
186
+ - estimand scopes (instance / finite sample / population);
187
+ - a strict, versioned JSON envelope.
188
+ - ADR-016 to ADR-018, accepted after review: record identity (identity ≠ semantic equivalence), status mechanism (measured state under intervention stays MEASURED; INTERVENTIONAL is reserved for effects), assessment policies (no universal thresholds).
189
+
190
+ - **M1.2: provenance and model fingerprinting**:
191
+ - schema types `ModelIdentity`, `EnvironmentIdentity`, `ExecutionContext` (CLEAN/INTERVENTION), `Randomness`, `MethodIdentity`, `ProvenanceRecord`, `ExecutionOccurrence`;
192
+ - `beyondnn.provenance` with the FULL v1 model fingerprint (structure plus bitwise state, tied-parameter and shared-module topology), environment collection without machine identity, read-only CPU RNG digest, and provenance and occurrence builders;
193
+ - ADR-019 and ADR-020;
194
+ - ADR-016 amendment: expectation wording and the no-Unicode-normalisation decision.
195
+
196
+ - **M1.10: Phase 1 audit and gate report** (`docs/PHASE_1_REPORT.md`: GO WITH EXPLICIT LIMITATIONS).
197
+ - Public recording now refuses module replacement or structural change between passes (ADR-027).
198
+ - Audit tests (`tests/test_phase1_audit.py`) guard the public surface and the Phase-1 evidence statuses.
199
+ - README corrected to state that only observed and measured evidence exist today.
200
+ - Installed-wheel smoke test run in a clean virtualenv.
201
+ - **M1.9: `benchmarks/bench_trace_overhead.py`**: CPU characterisation of baseline, trace none/summary/cpu, fingerprint, save/load, and exact byte sizes. Results are in the experiment log. There is no pass/fail threshold and no optimisation.
202
+ - **M1.8: `bnn.instrument(model)`**: a frozen handle referencing the original model.
203
+ - `handle.trace`/`recording` are exactly the public pipeline.
204
+ - `handle.explain(...)` gives `ExplainResponse` (INPUT → WHY → OUTPUT) over one single-pass trace. Phase-1 `why` is measured evidence (activations, limitations, provenance) with `NO_ATTRIBUTION`/`NO_CAUSAL_EVIDENCE`/`NO_CLAIMS_TESTED`, never a causal explanation.
205
+ - A deterministic `render()`.
206
+ - README examples are executed by the test suite. ADR-026.
207
+ - **Trace occurrence and hook provenance fixes (ADR-025):**
208
+ - `ExecutionOccurrence` v2 carries `pass_index`, one per pass, with v1 migrating to `None`.
209
+ - Public `trace()`/`recording()` refuse foreign forward/forward-pre hooks (local or global), checked at entry and at every pass start/end.
210
+ - Models whose tensors are on several devices are refused instead of being labelled with one device.
211
+ - **M1.7: trace persistence:** `TraceResult.save(dir)` and `bnn.load_trace(dir)`.
212
+ - Deterministic `trace.json` with an optional `tensors.pt`, read only with `weights_only=True`. No paths are taken from JSON, and symlinks are refused.
213
+ - Atomic save; the target is never overwritten.
214
+ - Full re-validation on load: ids, references, provenance, and tensor dtype/shape/digest.
215
+ - Migrations with deterministic reference remapping.
216
+ - The codec now verifies stored ids before migrating. ADR-024.
217
+ - **M1.6: trace pipeline:** public `bnn.trace`, `bnn.recording`, `bnn.TraceResult`.
218
+ - Per-pass provenance, with the model fingerprinted at the start of each root call.
219
+ - OBSERVED root input/output and MEASURED activations, one per tensor leaf, with deterministic paths.
220
+ - Retention `summary`/`cpu`/`none`; no live tensors are retained.
221
+ - Container validation of every record and reference.
222
+ - Refusal of out-of-pass and aliased executions; honest limitations (`SELECTED_SITE_NOT_EXECUTED`, `NON_TENSOR_LEAVES_IGNORED`).
223
+ - `InputRecord`/`OutputRecord` v2 (`pass_index`). ADR-023.
224
+ - **M1.5 fix: recursive pre-hook invocation bookkeeping.** A prepended guard pre-hook claims each attempt's call index, and the observation pre-hook (after user pre-hooks) emits INPUT. A user pre-hook raising inside recursion can no longer release the enclosing frame. Sessions refuse to start while global module forward pre-hooks are registered.
225
+ - **Caller-declared model provenance** (M1.6 gate, ADR-022):
226
+ - `ModelDeclaration` (config, implementation revision, checkpoint revision) in `ProvenanceRecord.declared_model`;
227
+ - `ProvenanceRecord` record_version 2, with a v1→v2 migration;
228
+ - `make_provenance(declared_model=…)`;
229
+ - migration errors now raise `DecodeError`.
230
+
231
+ Resolves the M1.3 `n_heads` identity gap without changing FULL v1.
232
+ - **M1.5: safe hook session** (`beyondnn.core.hooks`, internal):
233
+ - scoped hooks, removed on every exit path (normal exit, exceptions, sink errors, partial install);
234
+ - physical-module dedup;
235
+ - pass/call indices with failure consumption, out-of-pass `-1`, and stack-paired INPUT/OUTPUT;
236
+ - aliased modules refused by default (internal `GROUP` mode);
237
+ - values neither modified nor retained;
238
+ - autograd, outputs, and BatchNorm state identical to baseline. ADR-021.
239
+ - **M1.4: deterministic module site resolution** in `beyondnn.core.sites` (not exported):
240
+ - segment-based `*` / `**` pattern language; the root is selected only by `""`;
241
+ - strict (unmatched or invalid patterns raise);
242
+ - traversal-order results, deduplicated by exact path;
243
+ - alias paths preserved as distinct sites;
244
+ - no forward, hooks, or RNG use.
245
+
246
+ Also: a hard roadmap gate before M1.6 for caller-declared model config/revision.
247
+ - **M1.3: deterministic tiny reference models** in the internal, unstable `beyondnn._testing.models`:
248
+ - `TinyMLP` (139 params; shared module called twice; functional op; keyword-only `scale`);
249
+ - `TinyCNN` (396; BatchNorm buffers; tuple output);
250
+ - `TinyTransformer` (5,120; tied `lm_head`/`token_embedding`; non-persistent `position_ids`/`causal_mask` used in forward; dict output).
251
+
252
+ Construction is seeded without changing the caller's global RNG. The models are not exported from `beyondnn`.
253
+
254
+ ### Fixed (M1.2 review)
255
+ - The FULL fingerprint now hashes the values of **all** registered buffers, including non-persistent ones, which can affect `forward`. Buffer persistence is recorded as metadata. The v1 golden digests were updated before any release (ADR-020 correction).
256
+ - Access to PyTorch's private buffer-persistence field is isolated in one helper, with a compatibility test.
257
+ - Docs: the definition of FULL (Python code is not hashed); `schema` is stdlib-only; an implementation-revision roadmap item.
258
+
259
+ ### Changed (M1.1 review fixes)
260
+ - `ActivationRecord` / `MEASURED` semantics: directly observed state, including during intervened executions.
261
+ - `derived_from` and `ClaimTestResult.evidence` are sorted at construction, and `-0.0` is normalised, so ids no longer depend on order or on the sign of zero.
262
+ - The codec no longer imports the schema package from inside itself (the apparent import cycle is removed). Dead code is removed.
263
+ - Second, independent guard tests added for derivation rules, population matching, policy coverage, and id integrity.
264
+ - Design documentation: ecosystem audit, differentiation, interpretability definition, architecture proposal,
265
+ trace schema proposal, roadmap, Phase 1 plan, research questions, experiment log.
266
+ - Architecture decision records ADR-001 to ADR-015 (ADR-012 claims, ADR-013 estimand scope, ADR-014 incremental schema versioning, ADR-015 single-execution traces).
267
+ - Project scaffolding: `pyproject.toml`, CI workflow, pre-commit configuration, package placeholder.
@@ -0,0 +1,25 @@
1
+ cff-version: 1.2.0
2
+ message: "If you use BeyondNN in your research, please cite the software as below."
3
+ type: software
4
+ title: "BeyondNN: auditable interpretability evidence for PyTorch"
5
+ abstract: >-
6
+ BeyondNN turns claims about neural-network computation into structured,
7
+ provenance-aware, testable objects and audits them against recorded evidence:
8
+ epistemic status for every record, declared claims, controlled interventions with
9
+ explicit replacements, configuration roles, and deterministic, re-derivable audits
10
+ without a global score.
11
+ authors:
12
+ - family-names: Roufas
13
+ given-names: Nikolaos
14
+ version: 0.1.0
15
+ date-released: "2026-10-01"
16
+ license: Apache-2.0
17
+ repository-code: "https://github.com/NikolasRoufas/beyondnn"
18
+ url: "https://github.com/NikolasRoufas/beyondnn"
19
+ keywords:
20
+ - interpretability
21
+ - pytorch
22
+ - mechanistic interpretability
23
+ - provenance
24
+ - causal interventions
25
+ - research software
beyondnn-0.1.0/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.