shortlist / code /training /maze_check.py
JagritGumber's picture
Add the can-it-be-gamed check, the maze forward test notebook, license, and wording fixes
2c7f145 verified
Raw History Blame Contribute Delete
2.9 kB
"""Score the maze forward test's pre-registered claims (P1-P4) from the training run's saved answers.
python maze_check.py results-maze/results.json predictions.json # on Kaggle, or locally
Writes <results dir>/claims.json and prints one line per claim.
"""
import json
import sys
from collections import Counter
from pathlib import Path
import numpy as np
import reasoning_gym
HELD_OUT = range(100_000, 100_200)
def paired_p(before: list[float], after: list[float], n: int = 10000) -> tuple[float, float]:
"""Mean gain and the paired-bootstrap p-value for 'gain <= 0' (as in grpo_proof.py)."""
d = np.asarray(after, dtype=float) - np.asarray(before, dtype=float)
if len(d) == 0:
return 0.0, 1.0
boots = np.random.default_rng(0).choice(d, (n, len(d))).mean(1)
return float(d.mean()), float(np.mean(boots <= 0))
def main() -> None:
res_path, pred_path = Path(sys.argv[1]), Path(sys.argv[2])
r = next(x for x in json.loads(res_path.read_text()) if x["family"] == "maze")
before, after = r["before"]["answers"], r["after"]["answers"]
sets = [reasoning_gym.create_dataset("maze", seed=s, size=1) for s in HELD_OUT]
truth = [str(ds[0]["answer"]) for ds in sets]
solved = lambda i, a: float(sets[i].score_answer(answer=a, entry=sets[i][0]) >= 1.0) # the environment's own grader
top, top_n = Counter(a.strip() for a in after).most_common(1)[0]
others = [i for i, t in enumerate(truth) if t != top]
acc_b = [solved(i, before[i]) for i in others]
acc_a = [solved(i, after[i]) for i in others]
gain, p = paired_p(acc_b, acc_a)
claims = [
{"id": "P1", "held": r["gain"]["p"] <= 0.05 and r["gain"]["gain"] > 0,
"measured": f"mean reward {r['before']['mean_score']:.3f} -> {r['after']['mean_score']:.3f}, paired p = {r['gain']['p']:.3f}"},
{"id": "P2", "held": top_n / len(after) >= 0.5,
"measured": f"most common answer after training: {top!r}, {top_n} of {len(after)} answers"},
{"id": "P3", "held": top in ("5", "6"), "measured": f"most common answer after training: {top!r}"},
{"id": "P4", "held": p > 0.05,
"measured": f"accuracy on the {len(others)} tasks whose answer isn't {top!r}: {np.mean(acc_b):.3f} -> {np.mean(acc_a):.3f}, "
f"paired p = {p:.3f}"},
]
stated = {c["id"]: c for c in json.loads(pred_path.read_text())["predictions"][0]["claims"]}
for c in claims:
c.update(claim=stated[c["id"]]["claim"], test=stated[c["id"]]["test"])
print(f"{c['id']} {'HELD ' if c['held'] else 'FAILED'} {c['claim']} [{c['measured']}]")
out = {"most_common_after": top, "share": top_n / len(after),
"answers_after": Counter(a.strip() for a in after).most_common(8), "claims": claims}
(res_path.parent / "claims.json").write_text(json.dumps(out, indent=2))
if __name__ == "__main__":
main()