shortlist / code /training /maze_analysis.py
JagritGumber's picture
Maze forward test result: 3 of 4 claims held
ad54cd3 verified
Raw History Blame Contribute Delete
3.01 kB
"""Explain the maze forward test's result: what the collapsed answer is and how the grader pays it.
python training/maze_analysis.py # reads training/maze/results/, writes analysis.json there
Not part of the pre-registration; the claims are scored by maze_check.py exactly as published.
"""
import json
import statistics
from collections import Counter
from pathlib import Path
import reasoning_gym
ROOT = Path(__file__).resolve().parent.parent
RES = ROOT / "training" / "maze" / "results"
HELD_OUT = range(100_000, 100_200)
def main() -> None:
r = next(x for x in json.loads((RES / "results.json").read_text()) if x["family"] == "maze")
claims = json.loads((RES / "claims.json").read_text())
sets = [reasoning_gym.create_dataset("maze", seed=s, size=1) for s in HELD_OUT]
truth = [str(ds[0]["answer"]) for ds in sets]
before, after = r["before"]["answers"], r["after"]["answers"]
top, top_n = Counter(a.strip() for a in after).most_common(1)[0]
score = lambda i, a: float(sets[i].score_answer(answer=a, entry=sets[i][0]))
contains = sum(t in top for t in truth) # held-out answers that appear somewhere inside the collapsed answer
numbers = [w for w in top.replace("\n", " ").split() if w.isdigit()]
out = {
"collapsed_answer_start": top.split("\n")[0],
"collapsed_answer_numbers": f"{min(map(int, numbers))} to {max(map(int, numbers))}" if numbers else None,
"collapsed_answer_chars": len(top), "collapsed_share": top_n / len(after),
"held_out_answers_inside_it": contains, "held_out_tasks": len(truth),
"its_mean_score_if_given_everywhere": round(statistics.mean(score(i, top) for i in range(len(truth))), 3),
"constant_5_score": round(statistics.mean(score(i, "5") for i in range(len(truth))), 3),
"reward_before": round(r["before"]["mean_score"], 3), "reward_after": round(r["after"]["mean_score"], 3),
"exact_before": sum(score(i, a) >= 1 for i, a in enumerate(before)),
"exact_after": sum(score(i, a) >= 1 for i, a in enumerate(after)),
"bare_numbers_before": sum(a.strip().isdigit() for a in before),
"minutes": r["minutes"],
}
short = { # readable versions of what maze_check.py measured
"P1": f"mean reward {out['reward_before']:.3f} → {out['reward_after']:.3f}, paired p < 0.001",
"P2": f"{top_n} of {len(after)} answers are the same text",
"P3": f"the constant is not a number: a grid of the numbers {out['collapsed_answer_numbers']}, cut off at 64 tokens",
"P4": f"exact answers {out['exact_before']} → {out['exact_after']} of {len(after)}",
}
out["claims"] = [{"id": c["id"], "held": c["held"], "claim": c["claim"], "test": c["test"], "measured": short[c["id"]]}
for c in claims["claims"]]
(RES / "analysis.json").write_text(json.dumps(out, indent=2, ensure_ascii=False))
print(json.dumps(out, indent=2, ensure_ascii=False))
if __name__ == "__main__":
main()