Datasets:
Download scripts/analyze.py from perpetual-research/shadowbench: direct link, hf CLI and curl.
- Browser
- Download file 5.12 kB
-
https://huggingface.co/datasets/perpetual-research/shadowbench/resolve/main/scripts/analyze.py
- Command line
-
hf download hf://datasets/perpetual-research/shadowbench/scripts/analyze.py
-
curl -L -o analyze.py https://huggingface.co/datasets/perpetual-research/shadowbench/resolve/main/scripts/analyze.py
5.12 kB
| """Reproduce the leaderboard and the report's headline numbers from the episode and task tables. | |
| uv run python scripts/analyze.py | |
| Scores are rounded to two decimals per episode, as in the report, and the 95% intervals are bootstrap intervals over | |
| the 20 plates (10,000 resamples, seed 20261105, drawn in the report's order), so every number printed here matches | |
| the report and the `leaderboard` config exactly. The script exits with an error if one does not. | |
| """ | |
| import json | |
| from pathlib import Path | |
| import numpy as np | |
| import pyarrow.parquet as pq | |
| DATA = Path(__file__).resolve().parents[1] / "data" | |
| MODELS = ["claude-opus-5.5", "claude-sonnet-5.5", "gpt-6.1-sol", "gpt-6.1-terra", "claude-haiku-5.5", "gpt-6-luna"] | |
| EFFORTS = ["medium", "high", "max"] | |
| rng = np.random.default_rng(20261105) | |
| def r(x, d=2): | |
| return float(round(float(x), d)) | |
| def boot(v): | |
| m = v[rng.integers(0, len(v), size=(10000, len(v)))].mean(axis=1) | |
| return r(np.percentile(m, 2.5)), r(np.percentile(m, 97.5)) | |
| def read(path): | |
| return pq.read_table(path).to_pylist() | |
| episodes = [x for e in EFFORTS for x in read(DATA / "episodes" / f"{e}_effort.parquet")] | |
| tasks = {t["task_id"]: t for t in read(DATA / "tasks" / "tasks.parquet")} | |
| board = {(x["model"], x["effort"]): x for x in read(DATA / "leaderboard" / "leaderboard.parquet") if x["kind"] == "model"} | |
| refs = {x["model"]: x for x in read(DATA / "leaderboard" / "leaderboard.parquet") if x["kind"] == "reference"} | |
| plates = sorted(tasks) | |
| name = {x["model"]: x["model_name"] for x in episodes} | |
| def pick(m=None, e=None): | |
| return sorted((x for x in episodes if (m is None or x["model"] == m) and (e is None or x["effort"] == e)), | |
| key=lambda x: x["task_id"]) | |
| rows, failures = {}, [] | |
| for m in MODELS: | |
| for e in EFFORTS: | |
| xs = pick(m, e) | |
| s = np.array([r(x["score"]) for x in xs]) | |
| lo, hi = boot(s) | |
| rows[(m, e)] = dict(score=r(s.mean()), ci_low=lo, ci_high=hi, | |
| cost_usd_per_episode=r(np.mean([x["cost_usd"] for x in xs]), 4), | |
| minutes_per_episode=r(np.mean([x["seconds"] for x in xs]) / 60, 1), | |
| plates_above_blob=sum(r(x["score_before_peeks"]) > r(tasks[x["task_id"]]["blob_score"]) for x in xs)) | |
| for m in MODELS: | |
| a = np.array([r(x["score"]) for x in pick(m, "medium")]) | |
| b = np.array([r(x["score"]) for x in pick(m, "max")]) | |
| lo, hi = boot(b - a) | |
| rows[(m, "max")].update(gain_vs_medium=r((b - a).mean()), gain_ci_low=lo, gain_ci_high=hi, | |
| plates_improved_vs_medium=int((b > a).sum())) | |
| search = np.array([r(tasks[t]["search_score"]) for t in plates]) | |
| slo, shi = boot(search) | |
| for key, row in rows.items(): | |
| for k, v in row.items(): | |
| if board[key][k] != v: | |
| failures.append(f"{key} {k}: {v} != {board[key][k]}") | |
| if (r(search.mean()), slo, shi) != (refs["search"]["score"], refs["search"]["ci_low"], refs["search"]["ci_high"]): | |
| failures.append("search reference differs") | |
| for ref, col in (("blob", "blob_score"), ("rest", "rest_score")): | |
| if r(np.mean([r(tasks[t][col]) for t in plates])) != refs[ref]["score"]: | |
| failures.append(f"{ref} reference differs") | |
| usd = lambda v: f"${v:.3f}" if v < 0.1 else f"${v:.2f}" | |
| print("| Model | Medium | High | Max | Cost per episode (medium · high · max) |") | |
| print("| --- | ---: | ---: | ---: | ---: |") | |
| for m in sorted(MODELS, key=lambda m: -rows[(m, "max")]["score"]): | |
| sc = [f"{rows[(m, e)]['score']:.1f} [{rows[(m, e)]['ci_low']:.1f}, {rows[(m, e)]['ci_high']:.1f}]" for e in EFFORTS] | |
| cost = " · ".join(usd(rows[(m, e)]["cost_usd_per_episode"]) for e in EFFORTS) | |
| print(f"| {name[m]} | {' | '.join(sc)} | {cost} |") | |
| print() | |
| print("| Model | Max minus medium [95% CI] | Plates better at max |") | |
| print("| --- | ---: | ---: |") | |
| for m in sorted(MODELS, key=lambda m: -rows[(m, "max")]["gain_vs_medium"]): | |
| g = rows[(m, "max")] | |
| print(f"| {name[m]} | {g['gain_vs_medium']:+.1f} [{g['gain_ci_low']:+.1f}, {g['gain_ci_high']:+.1f}] | {g['plates_improved_vs_medium']} of 20 |") | |
| print() | |
| print(f"References: blob {refs['blob']['score']:.1f}, blind search {r(search.mean()):.1f} [{slo:.1f}, {shi:.1f}], " | |
| f"hands at rest {refs['rest']['score']:.1f}") | |
| two = [x for x in episodes if x["both_hands_cast_shadow"]] | |
| moves = np.array([[x["moves_better"], x["moves_worse"], x["moves_unchanged"]] for x in episodes]).sum(axis=0) | |
| print(f"Episodes: {len(episodes)}, solved {sum(x['solved'] for x in episodes)}, total cost {usd(sum(x['cost_usd'] for x in episodes))}") | |
| print(f"Final poses with both hands casting a shadow: {len(two)}, hands together: " | |
| f"{sum(1 for x in two if x['hand_gap_cm'] < 2 and x['hand_depth_gap_cm'] < 5)}, " | |
| f"median gap {np.median([x['hand_gap_cm'] for x in two]):.1f} cm, median depth gap {np.median([x['hand_depth_gap_cm'] for x in two]):.1f} cm") | |
| print(f"Accepted hand moves: {moves.sum()}, better {moves[0]}, worse {moves[1]}, unchanged {moves[2]}") | |
| if failures: | |
| raise SystemExit("MISMATCH\n" + "\n".join(failures)) | |
| print("\nAll leaderboard numbers reproduced exactly.") | |