Chucks90 commited on
Commit
3f7b9bb
Β·
verified Β·
1 Parent(s): f6fe04d

consolidation: RESEARCH_OVERVIEW; figures w/ multi-seed error bars + cross-objective + closed-form law; polished 3 drafts (selector numbers, refs, figure callouts)

Browse files
RESEARCH_OVERVIEW.md ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # covtoken β€” Research Overview
2
+
3
+ Label-free rare-structure geometry in frozen self-supervised vision transformers, for medical
4
+ imaging. One principle, three papers, four gated programs β€” all compute run as Hugging Face Jobs,
5
+ all experiments reproducible, labels eval-only throughout.
6
+
7
+ ## The principle (one sentence)
8
+ **Rare/critical structure lives in the mid-layer *concentration subspace* of self-distilled
9
+ foundation models; depth (view-invariance/globalization) erodes it; rank/spanning objectives are
10
+ anti-aligned with it; and it is readable, certifiable, and bounded label-free.**
11
+
12
+ ## The three papers
13
+ 1. **Method** β€” *Where Lesions Live: Label-Free Mid-Layer Lesion Subspaces for Token-Economical
14
+ Medical Imaging* (`paper/working_draft.md`). The label-free lesion subspace + membership pruning
15
+ + conformal retention certificate + lesion-routed depth, across CT (MedDINOv3) and ultrasound
16
+ (DINOv2). Includes the coverage-floor negative result.
17
+ 2. **Theory / negative-results** β€” *Rank-Based Representation Objectives Fail for Rare-Signal
18
+ Retention: A Mechanism and a Predictive Law* (`paper/paper2_rank_objectives_draft.md`). The
19
+ exact closed-form law (gap=(mβˆ’r)/m, r\*=m), the `A(rank,SNR)` alignment surface, the
20
+ selection-vs-scaling sharpening. Transferable beyond medicine.
21
+ 3. **Mechanism / SPIE** β€” *Where Lesions Live: Mid-Layer Localization in Frozen ViTs, and Why*
22
+ (`paper/paper3_midlayer_draft.md`). Mid-layer localization + label-free tail-gap selector +
23
+ the invariance mechanism + the cross-objective causal-by-comparison result.
24
+
25
+ ## The four programs (gated, HF-Jobs reproducible)
26
+ - **v1 (method)** β€” `gate_reports/` Gates 0–6. Subspace validity, cross-modality localization,
27
+ membership > saliency pruning, coverage-floor NEGATIVE, conformal cert (0.978 β‰₯ 0.90), routed
28
+ depth (1.6Γ— FLOPs @ 98% sensitivity).
29
+ - **v2 (S1–S5)** β€” `research_v2/`. S1 the closed-form law (βœ…), S2 mid-layer + label-free selector
30
+ (βœ…), S4 detection viable (β—‘), S3 precondition-prediction hard (βœ—), S5 conformal validity transfers (βœ…).
31
+ - **v3 (F1–F4)** β€” `research_v3/`. F2a alignment surface (βœ… synthetic), F1a selectionβ‰ scaling (β—‘),
32
+ F2b law needs rank-relative-to-background (β—‘), F3a invariance mechanism (β—‘), **F3 cross-objective
33
+ decisive** (βœ… β€” erosion across DINOv2/supervised/MedDINOv3; MAE not separable).
34
+ - **v4 (G1–G3)** β€” `research_v4/`. **G1a training-free concentration steering = NEGATIVE** (βœ…
35
+ honest): globalization is an *entangling* transformation, not a removable nuisance β€” reinforces
36
+ S2 and sharpens F3. G2 (cross-domain universality) and G3 (deployable tool + benchmark) specced,
37
+ not built.
38
+
39
+ ## Headline numbers (multi-seed where applicable)
40
+ - Mid-layer lesion AUROC peak **0.866 Β± 0.010** (block 3), final-layer 0.565; label-free tail-gap
41
+ selector regret **0.006**.
42
+ - Cross-objective depth-erosion ρ(invariance, AUROC): DINOv2 βˆ’0.93, supervised βˆ’0.73, MedDINOv3 βˆ’0.94.
43
+ - The law is **exact** (gap=(mβˆ’r)/m, r\*=m, std 0.0 over 40 seeds).
44
+ - Coverage-floor ablation: 0.22 (floor) vs 0.82 (membership) small-lesion retention.
45
+
46
+ ## What's honest about this body of work
47
+ The clean wins (the law, the mid-layer mechanism + selector, the cross-modality method, the
48
+ conformal certificate) are real and reproducible. The deep extensions (steering, concentration-
49
+ preserving pretraining via reconstruction) returned **negatives that sharpened the science** rather
50
+ than producing new methods β€” reported as first-class results. The remaining novel lever is G2
51
+ (cross-domain universality), a deliberate new project, not a quick eval.
52
+
53
+ ## Reproduce
54
+ All jobs in `jobs/` (PEP-723 uv scripts) run via `hf jobs uv run --flavor <t4-medium|t4-small|cpu>
55
+ --secrets HF_TOKEN -v hf://buckets/Chucks90/eryon-datasets:/mnt <script>`. Specs in
56
+ `research_specs/`. Figures: `paper/figures/` via `paper/make_figures.py`.
paper/figures/fig1_layer_ablation.png CHANGED
paper/figures/fig6_cross_objective.png ADDED
paper/figures/fig7_rank_law.png ADDED
paper/make_figures.py CHANGED
@@ -13,18 +13,21 @@ plt.rcParams.update({"figure.dpi": 150, "font.size": 11, "axes.grid": True,
13
 
14
 
15
  def fig1_layer():
16
- layers = ["final\n(12)", "block 6", "block 4", "block 3"]
17
- auroc = [0.565, 0.769, 0.865, 0.871]
18
- fig, ax = plt.subplots(figsize=(5, 3.4))
19
- ax.plot(range(len(layers)), auroc, "o-", color="#1f77b4", lw=2, ms=8)
 
 
 
20
  ax.axhline(0.767, ls="--", color="#d62728", label="attention saliency (0.767)")
21
- ax.axhline(0.70, ls=":", color="gray", label="AUROC floor")
22
- for i, a in enumerate(auroc):
23
- ax.annotate(f"{a:.3f}", (i, a), textcoords="offset points", xytext=(0, 8), ha="center")
24
- ax.set_xticks(range(len(layers))); ax.set_xticklabels(layers)
25
- ax.set_ylabel("token-level lesion AUROC (LIDC)"); ax.set_ylim(0.5, 0.95)
26
- ax.set_title("Finding 1: lesion signal lives mid-layer")
27
- ax.legend(loc="lower right", fontsize=9)
28
  fig.tight_layout(); fig.savefig(OUT / "fig1_layer_ablation.png"); plt.close(fig)
29
 
30
 
@@ -102,6 +105,46 @@ def fig5_conformal():
102
  fig.tight_layout(); fig.savefig(OUT / "fig5_conformal.png"); plt.close(fig)
103
 
104
 
105
- for f in (fig1_layer, fig2_crossmodality, fig3_pruning_gain, fig4_ablation, fig5_conformal):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
106
  f()
107
  print("figures written:", sorted(p.name for p in OUT.glob("*.png")))
 
13
 
14
 
15
  def fig1_layer():
16
+ # full 12-block depth curve with multi-seed (n=3) error bars [research_v3/rigor_results.json]
17
+ blocks = np.arange(1, 13)
18
+ mean = [0.8612,0.8641,0.8657,0.8375,0.8127,0.7818,0.7366,0.7059,0.6816,0.6802,0.6607,0.6365]
19
+ std = [0.0098,0.0089,0.0098,0.0169,0.0182,0.0163,0.0253,0.0268,0.0302,0.0379,0.0373,0.0264]
20
+ fig, ax = plt.subplots(figsize=(5.4, 3.4))
21
+ ax.errorbar(blocks, mean, yerr=std, fmt="o-", color="#1f77b4", lw=2, ms=6,
22
+ capsize=3, label="density-A (mean Β± std, 3 seeds)")
23
  ax.axhline(0.767, ls="--", color="#d62728", label="attention saliency (0.767)")
24
+ pk = int(np.argmax(mean))
25
+ ax.annotate(f"peak block {blocks[pk]}\n{mean[pk]:.3f}Β±{std[pk]:.3f}", (blocks[pk], mean[pk]),
26
+ textcoords="offset points", xytext=(14, 6), ha="left", fontsize=8.5, color="#1f77b4")
27
+ ax.set_xticks(blocks); ax.set_xlabel("transformer block (MedDINOv3)")
28
+ ax.set_ylabel("token-level lesion AUROC (LIDC)"); ax.set_ylim(0.55, 0.92)
29
+ ax.set_title("Finding 1: lesion signal peaks mid-layer, erodes with depth")
30
+ ax.legend(loc="lower left", fontsize=8.5)
31
  fig.tight_layout(); fig.savefig(OUT / "fig1_layer_ablation.png"); plt.close(fig)
32
 
33
 
 
105
  fig.tight_layout(); fig.savefig(OUT / "fig5_conformal.png"); plt.close(fig)
106
 
107
 
108
+ def fig6_cross_objective():
109
+ # F3 decisive: depth-erosion across objectives [research_v3/f3_cross_objective.json]
110
+ blocks = np.arange(1, 13)
111
+ dino = [0.862,0.880,0.868,0.807,0.729,0.682,0.701,0.676,0.682,0.653,0.621,0.617]
112
+ sup = [0.842,0.840,0.831,0.825,0.816,0.797,0.785,0.791,0.785,0.732,0.681,0.658]
113
+ mae = [0.611,0.600,0.596,0.600,0.589,0.590,0.587,0.582,0.577,0.570,0.577,0.568]
114
+ fig, ax = plt.subplots(figsize=(5.8, 3.6))
115
+ ax.plot(blocks, dino, "o-", color="#1f77b4", lw=2, ms=5, label="DINOv2 (self-distill) ρ=βˆ’0.93")
116
+ ax.plot(blocks, sup, "s-", color="#2ca02c", lw=2, ms=5, label="ViT (supervised) ρ=βˆ’0.73")
117
+ ax.plot(blocks, mae, "^--", color="#d62728", lw=2, ms=5, label="MAE (reconstruction) ρ=+0.06")
118
+ ax.axhline(0.50, ls=":", color="k", alpha=0.4, label="chance")
119
+ ax.set_xticks(blocks); ax.set_xlabel("transformer block (natural-trained; eval on CT)")
120
+ ax.set_ylabel("token-level lesion AUROC"); ax.set_ylim(0.45, 0.92)
121
+ ax.set_title("Mechanism: localizers erode with depth; MAE never localizes")
122
+ ax.legend(loc="upper right", fontsize=8)
123
+ ax.annotate("MAE flat & low\n(not density-separable)", (9, 0.578),
124
+ textcoords="offset points", xytext=(0, -28), ha="center", fontsize=7.5, color="#d62728")
125
+ fig.tight_layout(); fig.savefig(OUT / "fig6_cross_objective.png"); plt.close(fig)
126
+
127
+
128
+ def fig7_law():
129
+ # S1 closed-form law: spanning vs concentration retention vs signal rank [research_v2/s1_crossover.json]
130
+ m = 8; ranks = np.array([1, 2, 3, 4, 5, 6, 7, 8, 10, 12])
131
+ spanning = np.minimum(ranks, m) / m # = min(r,m)/m
132
+ concentration = np.ones_like(spanning, float)
133
+ fig, ax = plt.subplots(figsize=(5.4, 3.6))
134
+ ax.plot(ranks, concentration, "o-", color="#1f77b4", lw=2, ms=6, label="concentration (energy/membership)")
135
+ ax.plot(ranks, spanning, "s-", color="#d62728", lw=2, ms=6, label="spanning (effective-rank/RankMe)")
136
+ ax.fill_between(ranks, spanning, concentration, color="#d62728", alpha=0.12)
137
+ ax.axvline(m, ls=":", color="gray"); ax.annotate("crossover r*=m", (m, 0.55),
138
+ textcoords="offset points", xytext=(6, 0), ha="left", fontsize=8.5, color="gray")
139
+ ax.annotate("retention gap\n(mβˆ’r)/m", (2.0, 0.62), fontsize=8.5, color="#d62728", ha="center")
140
+ ax.set_xlabel("signal effective rank r (lesion concentration β†’ diversity)")
141
+ ax.set_ylabel("fraction of rare signal retained"); ax.set_ylim(0, 1.08)
142
+ ax.set_title("The law: rank objectives lose rare/low-rank signal")
143
+ ax.legend(loc="lower right", fontsize=8.5)
144
+ fig.tight_layout(); fig.savefig(OUT / "fig7_rank_law.png"); plt.close(fig)
145
+
146
+
147
+ for f in (fig1_layer, fig2_crossmodality, fig3_pruning_gain, fig4_ablation, fig5_conformal,
148
+ fig6_cross_objective, fig7_law):
149
  f()
150
  print("figures written:", sorted(p.name for p in OUT.glob("*.png")))
paper/paper2_rank_objectives_draft.md CHANGED
@@ -39,9 +39,9 @@ tokens (r=1 fully aligned, r=m fully diverse), each high energy in a lesion/anom
39
  a budget we select tokens by (i) concentration = top-energy `||P_L z||^2`, or (ii) spanning =
40
  farthest-point / effective-rank maximization in L.
41
 
42
- **Result.** spanning retention `= min(r,m)/m`; concentration retention `= 1`; **gap `= (m-r)/m`;
43
- crossover `r* = m`.** A spanning objective retains a signal only in proportion to its rank; it ties
44
- concentration only when the signal is fully diverse. (Multi-seed CIs: Β§5.)
45
 
46
  **Alignment surface.** Adding an SNR axis yields `A(r, SNR)`: concentration dominates iff the
47
  signal is concentrated (r<m) AND distinct (high SNR); at low SNR both lose the signal. This
@@ -91,5 +91,6 @@ label-free concentration subspace); this paper is the transferable negative + la
91
 
92
  ### Appendix β€” artifacts
93
  `research_v2/s1_crossover.json`, `research_v3/f1a_f2a_results.json`, `research_v3/f2b_f3a_results.json`,
94
- `gate_reports/ablation_floor.json`, `gate_reports/NEGATIVE_RESULT.md`, multi-seed CIs in
95
- `research_v3/rigor_s1_multiseed.json`. All experiments reproducible as HF Jobs.
 
 
39
  a budget we select tokens by (i) concentration = top-energy `||P_L z||^2`, or (ii) spanning =
40
  farthest-point / effective-rank maximization in L.
41
 
42
+ **Result (Fig. 1).** spanning retention `= min(r,m)/m`; concentration retention `= 1`; **gap
43
+ `= (m-r)/m`; crossover `r* = m`.** A spanning objective retains a signal only in proportion to its
44
+ rank; it ties concentration only when the signal is fully diverse. (Multi-seed: Β§5.)
45
 
46
  **Alignment surface.** Adding an SNR axis yields `A(r, SNR)`: concentration dominates iff the
47
  signal is concentrated (r<m) AND distinct (high SNR); at low SNR both lose the signal. This
 
91
 
92
  ### Appendix β€” artifacts
93
  `research_v2/s1_crossover.json`, `research_v3/f1a_f2a_results.json`, `research_v3/f2b_f3a_results.json`,
94
+ `gate_reports/ablation_floor.json`, `gate_reports/NEGATIVE_RESULT.md`, multi-seed in
95
+ `research_v3/rigor_results.json`. Figure: `paper/figures/fig7_rank_law.png` (the law). All
96
+ experiments reproducible as HF Jobs.
paper/paper3_midlayer_draft.md CHANGED
@@ -14,8 +14,9 @@ and that the decline with depth is **caused by representation globalization (vie
14
  loss of spatial information** β€” a mechanism that holds across self-distillation and supervised
15
  objectives but is absent for masked reconstruction (which never localizes). A label-free
16
  density/membership probe over patch tokens localizes lesions; its AUROC on chest CT rises from
17
- 0.565 at the final block to 0.871 at block 3, and a label-free statistic of the membership
18
- distribution (tail-gap / bimodality) selects a layer within 0.004 AUROC of the masked oracle.
 
19
  Across three objectives β€” DINOv2 (self-distillation, peak 0.88), supervised ViT (peak 0.84),
20
  MedDINOv3 (CT self-distillation) β€” localizability peaks early/mid and erodes with depth, strongly
21
  anti-correlated with rising flip-invariance (ρ = βˆ’0.73 to βˆ’0.94). Masked-reconstruction (MAE)
@@ -26,15 +27,18 @@ label-free.
26
  ## 1. The finding (depth)
27
 
28
  Token-level lesion-membership AUROC by block (LIDC, MedDINOv3): final 0.565 β†’ block 6 0.769 β†’
29
- block 4 0.865 β†’ **block 3 0.871**. Final-layer features serve the global self-distillation
30
- objective; the dense local lesion signal is mid/early. Multi-seed error bars: Β§5.
 
31
 
32
  ## 2. Label-free layer selection
33
 
34
- The tail-gap `(q99βˆ’q50)/(q50βˆ’q01)` and bimodality of the membership-score distribution β€” computed
35
- with NO masks β€” select a layer within **0.004 AUROC** of the mask-derived oracle (bimodality
36
- ρ=0.69 with the AUROC curve across depth). Excess kurtosis is a poor proxy (picks the worst layer).
37
- So *where to read* is discoverable without annotation.
 
 
38
 
39
  ## 3. The mechanism (why mid-layer)
40
 
@@ -56,7 +60,7 @@ Holding training domain constant (natural-image backbones, evaluated on CT):
56
 
57
  Depth-erosion + invariance-coupling hold for both objectives that produce a localizer
58
  (self-distillation, supervised), and for CT-native MedDINOv3 (ρ=βˆ’0.94) β€” three objectives, same
59
- law. **MAE is the clarifier:** it is flat *and low* (0.59) β€” masked reconstruction features are not
60
  density-separable for lesions at any depth, so "no collapse" is trivial (nothing to lose). The
61
  method needs self-distillation/supervised features; reconstruction is the wrong pretext.
62
 
@@ -76,4 +80,5 @@ headline selector. Cross-objective curves span all 12 blocks per backbone.
76
 
77
  ### Appendix β€” artifacts
78
  `research_v2/s2_depth_localizability.json`, `research_v3/f2b_f3a_results.json`,
79
- `research_v3/f3_cross_objective.json`, `research_v3/rigor_s2_multiseed.json`. HF-Job reproducible.
 
 
14
  loss of spatial information** β€” a mechanism that holds across self-distillation and supervised
15
  objectives but is absent for masked reconstruction (which never localizes). A label-free
16
  density/membership probe over patch tokens localizes lesions; its AUROC on chest CT rises from
17
+ 0.565 at the final block to 0.871 at block 3 (peak 0.866 Β± 0.010 over 3 seeds), and the **tail-gap**
18
+ of the membership-score distribution selects a layer within **0.006 AUROC** of the masked oracle
19
+ (multi-seed) β€” entirely label-free.
20
  Across three objectives β€” DINOv2 (self-distillation, peak 0.88), supervised ViT (peak 0.84),
21
  MedDINOv3 (CT self-distillation) β€” localizability peaks early/mid and erodes with depth, strongly
22
  anti-correlated with rising flip-invariance (ρ = βˆ’0.73 to βˆ’0.94). Masked-reconstruction (MAE)
 
27
  ## 1. The finding (depth)
28
 
29
  Token-level lesion-membership AUROC by block (LIDC, MedDINOv3): final 0.565 β†’ block 6 0.769 β†’
30
+ block 4 0.865 β†’ **block 3 0.871** (Fig. 1; multi-seed peak 0.866 Β± 0.010, monotone decline to
31
+ 0.637 Β± 0.026). Final-layer features serve the global self-distillation objective; the dense local
32
+ lesion signal is mid/early.
33
 
34
  ## 2. Label-free layer selection
35
 
36
+ We select the operating layer with NO masks from the shape of the membership-score distribution.
37
+ The **tail-gap** `(q99βˆ’q50)/(q50βˆ’q01)` is the robust selector: multi-seed regret **0.006 AUROC**
38
+ (max 0.011) versus the mask-derived oracle. A bimodality statistic correlates with the depth curve
39
+ (ρ=0.69) but is less stable across seeds (regret 0.062), and excess kurtosis is a poor proxy (picks
40
+ the worst layer). So *where to read* is discoverable from the score distribution alone, without
41
+ annotation.
42
 
43
  ## 3. The mechanism (why mid-layer)
44
 
 
60
 
61
  Depth-erosion + invariance-coupling hold for both objectives that produce a localizer
62
  (self-distillation, supervised), and for CT-native MedDINOv3 (ρ=βˆ’0.94) β€” three objectives, same
63
+ law (Fig. 6). **MAE is the clarifier:** it is flat *and low* (0.59) β€” masked reconstruction features are not
64
  density-separable for lesions at any depth, so "no collapse" is trivial (nothing to lose). The
65
  method needs self-distillation/supervised features; reconstruction is the wrong pretext.
66
 
 
80
 
81
  ### Appendix β€” artifacts
82
  `research_v2/s2_depth_localizability.json`, `research_v3/f2b_f3a_results.json`,
83
+ `research_v3/f3_cross_objective.json`, `research_v3/rigor_results.json`. Figures: `paper/figures/
84
+ fig1_layer_ablation.png` (depth, error bars), `fig6_cross_objective.png` (mechanism). HF-Job reproducible.
paper/working_draft.md CHANGED
@@ -99,7 +99,7 @@ Datasets: LIDC-IDRI (lung CT), KiTS23 (kidney CT), MSD Task03 Liver, MSD Task07
99
  ## 4. Results: the label-free localizer
100
 
101
  ### 4.1 Lesion signal lives mid-layer (Finding 1)
102
- Token-level lesion AUROC by depth (LIDC, density-A):
103
 
104
  | layer | final (12) | block 6 | block 4 | block 3 |
105
  |---|---|---|---|---|
@@ -107,7 +107,9 @@ Token-level lesion AUROC by depth (LIDC, density-A):
107
 
108
  Final-layer features are tuned for the global self-distillation objective; the dense local lesion
109
  signal sits mid/early. We fix block 3 (MedDINOv3) as the operating layer; for DINOv2 the optimum
110
- is block 8 β€” backbone-dependent, but always mid/late, never final.
 
 
111
 
112
  ### 4.2 Cross-anatomy, cross-modality, cross-backbone localization (Finding 2)
113
  density-A token-level lesion AUROC, with attention-saliency as the label-free comparator:
 
99
  ## 4. Results: the label-free localizer
100
 
101
  ### 4.1 Lesion signal lives mid-layer (Finding 1)
102
+ Token-level lesion AUROC by depth (LIDC, density-A; Fig. 1):
103
 
104
  | layer | final (12) | block 6 | block 4 | block 3 |
105
  |---|---|---|---|---|
 
107
 
108
  Final-layer features are tuned for the global self-distillation objective; the dense local lesion
109
  signal sits mid/early. We fix block 3 (MedDINOv3) as the operating layer; for DINOv2 the optimum
110
+ is block 8 β€” backbone-dependent, but always mid/late, never final. The curve is multi-seed stable
111
+ (peak 0.866 Β± 0.010, n=3), the operating layer is selectable without labels (tail-gap selector
112
+ regret 0.006), and the depth-erosion holds across objectives β€” see the companion mechanism study.
113
 
114
  ### 4.2 Cross-anatomy, cross-modality, cross-backbone localization (Finding 2)
115
  density-A token-level lesion AUROC, with attention-saliency as the label-free comparator: