Download build_tables.py from SporeLabs/cue-benchmark: direct link, hf CLI and curl.
- Browser
- Download file 4.92 kB
-
https://huggingface.co/datasets/SporeLabs/cue-benchmark/resolve/main/build_tables.py
- Command line
-
hf download hf://datasets/SporeLabs/cue-benchmark/build_tables.py
-
curl -L -o build_tables.py https://huggingface.co/datasets/SporeLabs/cue-benchmark/resolve/main/build_tables.py
4.92 kB
| """Render the tables of BENCHMARK_CARD.md from data files. No number in the card is typed by hand: | |
| results tables <- results/summary_public.json | |
| inventory <- items/*.jsonl.gz | |
| Usage: python build_tables.py (reads BENCHMARK_CARD.template.md, writes BENCHMARK_CARD.md and tables.md) | |
| Markers in the template look like <!--TABLE:name--> .""" | |
| import collections | |
| import gzip | |
| import json | |
| import re | |
| from pathlib import Path | |
| H = Path(__file__).resolve().parent | |
| S = json.load(open(H / "results/summary_public.json")) | |
| IT = H / "items" | |
| def rgz(p): | |
| with gzip.open(p, "rt", encoding="utf-8") as f: | |
| return [json.loads(l) for l in f if l.strip()] | |
| def f(x, d=4): # summary values are stored at 4 decimals; rounding them again would round twice | |
| return "-" if x is None else (f"{x:.{d}f}" if isinstance(x, float) else str(x)) | |
| def md(header, rows): | |
| out = ["| " + " | ".join(header) + " |", "|" + "---|" * len(header)] | |
| out += ["| " + " | ".join(str(c) for c in r) + " |" for r in rows] | |
| return "\n".join(out) | |
| def item_table(task): | |
| rows = [] | |
| for sysname, res in S[task].items(): | |
| if sysname.startswith("_") or not isinstance(res, dict): | |
| continue | |
| for key, m in res.items(): | |
| if key.startswith("_") or not isinstance(m, dict) or "f1" not in m or (m.get("coverage") or 0) < 0.99: | |
| continue # partial-coverage systems are compared on their own items in subset_table | |
| rows.append((sysname, key, m)) | |
| rows.sort(key=lambda t: (t[1], -(t[2].get("f1") or 0))) | |
| return md(["system", "gold key", "n", "positives", "AUROC", "F1", "precision", "recall", "caught", "coverage"], | |
| [(s, k, m["n"], m["positives"], f(m.get("auroc")), f(m["f1"]), f(m["precision"]), f(m["recall"]), | |
| m["caught"], f(m["coverage"], 2)) for s, k, m in rows]) | |
| SUBSET = "same_ids_as:claude-sonnet-5" # the items both Claude baselines answered (the same ids for Haiku) | |
| def subset_table(task): | |
| rows = [] | |
| for sysname, res in S[task].items(): | |
| if sysname.startswith("_") or not isinstance(res, dict): | |
| continue | |
| for key, m in res.items(): | |
| v = (m.get("subsets") or {}).get(SUBSET) if isinstance(m, dict) else None | |
| if key.startswith("_") or not v or (v.get("coverage") or 0) < 0.99: | |
| continue | |
| rows.append((sysname, key, v)) | |
| rows.sort(key=lambda t: (t[1], -(t[2].get("f1") or 0))) | |
| return md(["system", "gold key", "n", "positives", "AUROC", "F1", "precision", "recall", "caught"], | |
| [(s, k, m["n"], m["positives"], f(m.get("auroc")), f(m["f1"]), f(m["precision"]), f(m["recall"]), m["caught"]) | |
| for s, k, m in rows]) | |
| def inventory(): | |
| rows = [] | |
| for p in sorted(IT.glob("*.jsonl.gz")): | |
| r = rgz(p) | |
| pos = collections.Counter() | |
| for x in r: | |
| for k, v in (x.get("gold") or {}).items(): | |
| pos[k] += int(bool(v)) | |
| meet = len({x.get("meeting_id") for x in r if x.get("meeting_id")}) | |
| gs = ", ".join(sorted({x.get("gold_source") or "-" for x in r})) | |
| rows.append((p.name.replace(".jsonl.gz", ""), len(r), "; ".join(f"{k}: {v}" for k, v in sorted(pos.items())) or "-", | |
| meet or "-", sum(bool(x.get("in_sporelabs_training")) for x in r), gs)) | |
| return md(["file", "rows", "positives by gold key", "meetings / documents", "rows also in SporeLabs training text (flagged)", "gold_source"], rows) | |
| RELEASED = [("cue-text", "cue-text (released)"), ("jev-1.13-openrouter", "Jev 1.13 (TypeSafe, via OpenRouter)")] | |
| def released(): | |
| """The released model next to Jev: AUROC / F1 at each system's own threshold.""" | |
| def cell(task, sysname, key): | |
| m = (S.get(task) or {}).get(sysname) | |
| if not isinstance(m, dict): | |
| return "-" | |
| v = m.get(key) | |
| if not isinstance(v, dict) or v.get("f1") is None: | |
| return "-" | |
| return f"{f(v.get('auroc'))} / {f(v['f1'])}" | |
| cols = [("commitment_ami", "commitment_ami", "commitment"), ("question_ami", "question_ami", "open_question"), | |
| ("question_icsi", "question_icsi", "open_question")] | |
| rows = [(f"`{s}`", label, *[cell(t, s, k) for _, t, k in cols]) for s, label in RELEASED] | |
| return md(["system", "what", *[c[0] for c in cols]], rows) | |
| TABLES = {"released": released, "inventory": inventory} | |
| for t in ["commitment_ami", "question_ami", "question_icsi"]: | |
| TABLES[t] = (lambda t=t: item_table(t)) | |
| for t in ["commitment_ami", "question_icsi"]: | |
| TABLES[t + "_claude"] = (lambda t=t: subset_table(t)) | |
| tpl = (H / "BENCHMARK_CARD.template.md").read_text() | |
| out = re.sub(r"<!--TABLE:(\w+)-->", lambda m: TABLES[m.group(1)](), tpl) | |
| (H / "BENCHMARK_CARD.md").write_text(out) | |
| (H / "tables.md").write_text("\n\n".join(f"### {k}\n\n{fn()}" for k, fn in TABLES.items())) | |
| print("wrote BENCHMARK_CARD.md and tables.md") | |