"""Copy the extension into the public site repository and patch the page. No model call. python -m experiments.mace_extension.scripts.export_site Left out on purpose: the paper revision guide and status notes (internal), smoke rows, benchmark images, the response cache. """ from __future__ import annotations import gzip import json import re import shutil import sys from pathlib import Path import pandas as pd from .analyze import PR, RAW, ROOT, ST, TB, rows REPO = ROOT.parent.parent FINAL = ("E1_haiku", "E2", "E3cal", "E4other", "E4family", "E4matched") FIG = {"fig1_model_robustness": "ext_models", "fig2_retrieval_caption": "ext_factorial", "fig3_fallback": "ext_fallback", "fig4_collection_shift": "ext_collections"} SECTION = """
Follow-up tests

Stress tests of the main result

TestIn distributionHeld-out
Second diagnosis model: Claude Haiku 5.5, same Sonnet captions
SAGE37.0 [34.0, 39.9]42.5 [38.8, 46.2]
Labels only49.1 [46.2, 52.3]50.3 [46.5, 54.0]
MACE55.5 [52.5, 58.5]53.5 [49.8, 57.2]
Retrieval and evidence, Sonnet 5.5
DINOv2 retrieval with captions61.5 [58.6, 64.3]56.3 [52.5, 60.0]
Fallback to SAGE at low retrieval confidence, Sonnet 5.5
Frozen fallback rule61.8 [58.9, 64.6]57.8 [54.2, 61.5]
Labeled oracle (upper bound only)63.4 [60.5, 66.2]59.3 [55.5, 63.2]
Memory source, 554 in-distribution queries with the true disease in memory, Sonnet 5.5
Standard memory60.7 [56.5, 64.9]not run
Same size and disease mix61.2 [56.9, 65.3]not run
Other collections only55.7 [51.6, 59.6]not run

Equal-crop accuracy (%) with 95% bootstrap intervals. All tests were added after the main results and are not preregistered.

Second model

Haiku MACE exceeds SAGE by +18.5 points in distribution and +11.0 held-out. It does not clearly exceed DINOv2 lookup in distribution (+3.0 [−0.8, +6.6]), although it does held-out (+15.3 [+10.5, +20.3]). Haiku tests a second diagnosis model, not an independent pipeline: it reads Sonnet captions, and both are Claude models.

Captions as evidence

Captions add +6.3 points in distribution when DINOv2 selects the memory, close to the +6.4 under BM25. Held-out caption effects are inconclusive under both retrievers.

Fallback did not help

A rule frozen on 600 separate images changed accuracy by −0.4 [−1.0, +0.1] in distribution and +0.8 [−0.5, +2.2] held-out. Even an oracle would add only 1.2 and 2.3 points.

Memory source matters

Removing same-collection images costs 12.8 points, mostly because 45% of queries lose their disease from memory. With the disease kept, a bank of equal size recovers the 5.0-point loss (+5.5 [+1.9, +9.1]). The cause is unknown: it may be a shortcut such as shared background, or closer disease appearance.

Uneven held-out gain (post hoc)

Sonnet gains 0.0 [−3.8, +3.8] on the seven crops that hold out Bugwood and +21.1 [+13.9, +27.8] on the other three. With crops as the unit, the +6.3 held-out interval is [−3.2, +15.9].

Accuracy by Claude model, and per-crop gains

Two Claude models, with per-crop gains.

Retrieval by evidence accuracy, and caption effect by crop

Retrieval by evidence, with caption effects by crop.

Fallback calibration and final accuracy

Fallback threshold sensitivity and final accuracy.

Accuracy by memory source, and held-out gain against image shift

Memory source by crop, and held-out gain against image shift.

Data, statistics and the full report are in results/extension.

""" NEW_ABS = "Retrieved labels account for about two thirds of the gain, and in post hoc tests caption text adds 6.4 points in distribution, and 6.3 when an image encoder selects the captions. A second Claude model reproduces the method order. The held-out gain is uneven: Sonnet shows no gain on the seven crops that hold out one collection. MACE falls below SAGE when the true disease is not retrieved, and a retrieval-confidence fallback did not improve accuracy. " def sub(p, pat, new, count=1): s, n = re.subn(pat, lambda _: new, p, count=count, flags=re.S) assert n, pat return s def patch(s, abstract): if 'id="followup"' in s: return s s = sub(s, r"Retrieved labels account for most of the gain, caption text adds .{1,40}? points in distribution in a post hoc test, and accuracy falls below SAGE when the true disease is not retrieved\.", "Retrieved labels account for about two thirds of the gain, caption text adds 6.4 points in distribution in a post hoc test, and accuracy falls below SAGE when the true disease is not retrieved. A second Claude model keeps the method order, a confidence fallback did not help, and the held-out gain is uneven: Sonnet gains nothing on the seven crops that hold out one collection.") if abstract: s = sub(s, r"The retrieved labels account for most of the gain, and a post hoc test.*?(?=MACE adds)", NEW_ABS) s = sub(s, r"equal on one and lower on four\.", "equal on one and lower on four. In a post hoc grouping, the gain is 0.0 points on the seven crops that hold out Bugwood and +21.1 on the other three.") s = sub(s, r"the held-out difference is inconclusive\.

", "the held-out difference is inconclusive. Captions add +6.3 points when DINOv2 selects the memory.

") s = sub(s, r'Stable', 'Depends on memory') s = sub(s, r"Memory from the same collection still helps by .{1,40}? points, so shared acquisition conditions contribute\.", "A second Claude model keeps the method order. Memory from the same collection still helps, by +5.5 points at equal bank size and disease mix; the cause is unknown.") s = sub(s, r"Deployment would require a signal for retrieval failure, which we did not test\.", "A label-free fallback to SAGE at low retrieval confidence did not detectably change accuracy, and even an oracle would add at most 2.3 points.") s = sub(s, r"DINOv2 retrieval matched caption retrieval in distribution, so captions were not required for retrieval there\. Later work should separate the caption as an index from the caption as evidence\.", "Captions added as much after DINOv2 retrieval as after BM25, so in distribution the caption acts mainly as evidence and not as an index.") s = sub(s, r"
  • The tests of caption text and DINOv2 retrieval are post hoc\.
  • Each result is one run of one VLM\.
  • ", "
  • The caption, DINOv2, second-model, fallback and collection tests are post hoc.
  • Each result is one run, and both VLMs are Claude models sharing Sonnet captions.
  • Seven crops share one held-out collection, so crop and collection shift remain confounded.
  • ") s = sub(s, r'Results', 'ResultsFollow-up') s = sub(s, r'(?=
    )', SECTION.lstrip("\n") + "\n") return s def wide(): H = pd.read_csv(PR / "hero_all_methods.csv"); F = pd.read_csv(PR / "hero_fallback.csv")[["image_id", "adaptive", "oracle", "fallback"]]; X = pd.read_csv(PR / "hero_iid_cross_collection.csv")[["image_id", "covered", "other_hit", "dino_other"]] M = rows("E4matched").drop_duplicates("image_id")[["image_id", "correct"]].rename(columns={"correct": "matched"}); M["matched"] = M.matched.astype(float) c = ["image_id", "crop", "split", "label", "collection", "hit", "sage", "mace", "labels_all", "dino_labels", "dino_mace", "dino_s0", "h_sage", "h_mace", "h_labels", "other_full", "family"] return H[c].merge(F, on="image_id").merge(X, on="image_id", how="left").merge(M, on="image_id", how="left") def main(site): site = Path(site); ext = site / "results/extension"; code = site / "code" for d in ("predictions", "statistics", "tables", "processed"): (ext / d).mkdir(parents=True, exist_ok=True) for n in FINAL: with (RAW / n / "predictions.jsonl").open("rb") as f, gzip.GzipFile(ext / f"predictions/{n}.jsonl.gz", "wb", mtime=0) as g: shutil.copyfileobj(f, g) wide().to_csv(ext / "extension_wide.csv", index=False) for p in ST.glob("*.json"): shutil.copy(p, ext / "statistics" / p.name) for p in TB.iterdir(): shutil.copy(p, ext / "tables" / p.name) for n in ("calibration_signals.csv", "hero_fallback.csv", "hero_iid_cross_collection.csv", "hero_all_methods.csv"): shutil.copy(PR / n, ext / "processed" / n) for n in ("EXPERIMENT_AUDIT.md", "EXPERIMENT_PROTOCOL.md", "FAILURE_ANALYSIS.md", "BUDGET_LEDGER.csv", "RUN_MANIFEST.json"): shutil.copy(ROOT / n, ext / n) r = (ROOT / "EXPERIMENT_REPORT.md").read_text(); r = r[:r.index("## 11. Recommended paper changes")].rstrip() + "\n" (ext / "EXPERIMENT_REPORT.md").write_text(r) with (REPO / "runs/cost_ledger.jsonl").open("rb") as f, gzip.GzipFile(site / "results/cost_ledger.jsonl.gz", "wb", mtime=0) as g: shutil.copyfileobj(f, g) shutil.copy(ROOT / "scripts/verify_extension.py", site / "results/verify_extension.py") for p in (site / "code").rglob("*"): src = REPO / p.relative_to(code) if p.is_file() and src.is_file(): shutil.copy(src, p) e = code / "experiments/mace_extension"; (e / "scripts").mkdir(parents=True, exist_ok=True); (e / "configurations").mkdir(exist_ok=True) shutil.copy(REPO / "experiments/__init__.py", code / "experiments/__init__.py"); shutil.copy(ROOT / "__init__.py", e / "__init__.py") for p in (ROOT / "scripts").iterdir(): if p.suffix in (".py", ".sh") and p.name != "verify_extension.py": shutil.copy(p, e / "scripts" / p.name) for p in (ROOT / "configurations").iterdir(): shutil.copy(p, e / "configurations" / p.name) (code / "mace10/out").mkdir(exist_ok=True); (e / "processed_results").mkdir(exist_ok=True) # job lists need these derived vectors for n in ("dinov2_embeddings.npz", "dinov2_index.json"): shutil.copy(REPO / "mace10/out" / n, code / "mace10/out" / n) for n in ("dinov2_extra.npz", "dinov2_extra_index.json"): shutil.copy(PR / n, e / "processed_results" / n) for a, b in FIG.items(): shutil.copy(ROOT / f"figures/{a}.png", site / f"static/images/figures/{b}.png") (site / "index.html").write_text(patch((site / "index.html").read_text(), True)) t = REPO / "mace10/site_template.html"; t.write_text(patch(t.read_text(), False)) print("exported") if __name__ == "__main__": main(sys.argv[1])