File size: 4,056 Bytes
a2b0c04
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
"""What the trained model actually learned, per family: baselines, lenient re-score and Beam's audit in one file.

    python training/analysis.py     # writes training/kaggle/analysis.json

Baselines are answers that need no reasoning, scored on the same 200 held-out tasks as the training proof.
"""

import json
import statistics
from pathlib import Path

import reasoning_gym

ROOT = Path(__file__).resolve().parent.parent
K = ROOT / "training" / "kaggle"
SEEDS = range(100_000, 100_200)


def baseline(family: str, make_answer) -> float:
    scores = []
    for seed in SEEDS:
        ds = reasoning_gym.create_dataset(family, seed=seed, size=1)
        scores.append(ds.score_answer(answer=make_answer(ds[0]), entry=ds[0]))
    return round(statistics.mean(scores), 3)


BASELINES = {
    "letter_counting": ("always answer 1", lambda e: "1"),
    "propositional_logic": ("join the premises with 'and'", lambda e: " ∧ ".join(f"({p})" for p in e["metadata"]["premises"])),
    "word_sorting": ("repeat the input words unsorted", lambda e: ", ".join(e["metadata"]["original_words"])),
    "basic_arithmetic": ("always answer 0", lambda e: "0"),
    "chain_sum": ("always answer 0", lambda e: "0"),
}
LEARNED = {  # our reading of the evidence below, one line per family
    "basic_arithmetic": ("skill and format", "Partly skill, partly format: read leniently, the untrained model was already right on {lenient}."),
    "chain_sum": ("mostly format", "Mostly format: read leniently, the untrained model was already right on {lenient}."),
    "letter_counting": ("gamed", "It answers \"1\" to everything; that alone scores {baseline:.3f}."),
    "propositional_logic": ("gamed", "It joins the premises with \"and\"; that alone scores {baseline:.3f}."),
    "word_sorting": ("no real gain", "Repeating the input words unsorted already scores {baseline:.3f}."),
    "leg_counting": ("no change", "No reward on any attempt, so nothing to learn from; this prediction could not fail."),
}


def main() -> None:
    results = {r["family"]: r for r in json.loads((K / "results" / "results.json").read_text())}
    lenient = json.loads((K / "lenient" / "summary.json").read_text()) if (K / "lenient" / "summary.json").exists() else {}
    audit = {a["family"]: a for a in json.loads((K / "beam_audit.json").read_text())["audits"]}
    rows = []
    for family, r in sorted(results.items(), key=lambda kv: list(LEARNED).index(kv[0])):  # the write-up's order
        name, fn = BASELINES.get(family, (None, None))
        base = baseline(family, fn) if fn else None
        len_acc = lenient.get(family, {}).get("lenient", {}).get("accuracy")
        len_mean = lenient.get(family, {}).get("lenient", {}).get("mean")
        label, text = LEARNED[family]
        rows.append({
            "family": family, "prediction": r["prediction"], "held": r["held"],
            "reward_before": round(r["before"]["mean_score"], 3), "reward_after": round(r["after"]["mean_score"], 3),
            "p": r["gain"]["p"], "accuracy_before": r["before"]["accuracy"], "accuracy_after": r["after"]["accuracy"],
            "lenient_accuracy_before": len_acc, "lenient_reward_before": len_mean, "baseline": {"strategy": name, "score": base} if name else None,
            "learned": label, "learned_text": text.format(baseline=base or 0, lenient=f"{(len_acc or 0) * 100:g}%"),
            "beam_audit": audit.get(family, {}).get("verdict"), "beam_explanation": audit.get(family, {}).get("explanation"),
        })
    out = {"pre_registration": {"sha256": "d11a5928bce2f1b045b593e699370612779b6b45950cbdbee256ef6a23ccc776",
                                "committed_utc": "2026-10-30 16:23:45", "first_checkpoint_utc": "2026-10-30 16:25"},
           "held": sum(r["held"] for r in rows), "families": len(rows), "rows": rows}
    (K / "analysis.json").write_text(json.dumps(out, indent=2, ensure_ascii=False))
    for r in rows:
        print(f"{r['family']:20s} {r['learned']:16s} audit={r['beam_audit']:15s} baseline={r['baseline']}")


if __name__ == "__main__":
    main()