"""Data for the 'checking' figures on /blog/model-bench, from sourcestudy/{verify_runs,t10_funnel}.json and the T10 traces.""" import json, re, sys from pathlib import Path S = Path(sys.argv[1]); D = Path(sys.argv[2]); OUT = Path(sys.argv[3]) V = json.loads((S / "verify_runs.json").read_text()); F = json.loads((S / "t10_funnel.json").read_text()) tasks = sorted({v["task"] for v in V.values()}) grid = {t: {m: round(sum(v["verified"] for v in V.values() if v["task"] == t and v["model"] == m) / 5, 2) for m in ["P1", "DS", "GLM"]} for t in tasks} def kind(l): if re.match(r"^⚙ websearch", l) or re.match(r"^\$ .*\b(pplx|browser search)\b", l): return "s" if re.match(r"^⚙ webfetch", l) or (re.match(r"^\$ .*\b(pdftext|doctext)\b", l) and "http" in l) or re.match(r"^\$ .*\bbrowser (fetch|asset|session)\b", l) or re.match(r"^\$ .*\bcurl\b.*https?://", l): return "r" if re.match(r"^\$ .*\b(sec-filings|trade|funding|fda|biotech)\s+\w", l): return "d" if re.match(r"^⚙ (edit|write|multiedit)\b.*draft\.md", l) or re.match(r"^\$ .*(sed -i\b.*draft\.md|>\s*\S*draft\.md|tee \S*draft\.md)", l): return "w" return "o" def nv_check(l): """A check of NVIDIA's CEO against something newer than the annual report (same rule as t10_funnel).""" if re.search(r"(?i)websearch", l) and re.search(r"(?i)nvidia|huang|nvda", l): return True if re.search(r"sec-filings\b.*8-K", l) and ("NVDA" in l or "for t in" in l): return True return bool(re.search(r"(?i)webfetch|pdftext", l) and re.search(r"(?i)nvidia", l)) strips = [] for k in sorted(F, key=lambda k: (["P1", "DS", "GLM"].index(F[k]["model"]), k)): f = F[k] ev = [json.loads(l) for l in open(D / "traces" / f"{k}.jsonl")] calls = [e["line"] for e in ev if e.get("event") == "harness_said" and e.get("stream") != "timing" and (e["line"].startswith("⚙ ") or e["line"].startswith("$ "))] ks = "".join(kind(l) for l in calls) nvi = next((i for i, l in enumerate(calls) if nv_check(l)), None) strips.append({"model": f["model"], "repeat": f["repeat"], "calls": ks, "firstWrite": ks.find("w") if "w" in ks else None, "nvidiaCheck": nvi, "kress": f["verdict"] == "correct", "traced": f["has_trace"]}) # How each T10 run handled NVIDIA's CEO, read from its trace (seq numbers in sourcestudy/NOTES.md). ROUTES = { "P1-r1": "followed", "P1-r2": "followed", "P1-r3": "sweep", "P1-r4": "sweep", "P1-r5": "sweep", "DS-r1": "followed", "DS-r2": "ignored", "DS-r3": "followed", "DS-r4": "untraced", "DS-r5": "followed", "GLM-r1": "none", "GLM-r2": "none", "GLM-r3": "none", "GLM-r4": "none", "GLM-r5": "none", } for st_ in strips: st_["route"] = ROUTES[f'{st_["model"]}-{st_["repeat"]}'] if st_["route"] == "none": st_["nvidiaCheck"] = None # GLM r3's only NVIDIA query was for its address, not its CEO import random, statistics as stt, collections as co def boot(xs, n=5000, seed=3): r = random.Random(seed); ms = sorted(stt.mean(r.choices(xs, k=len(xs))) for _ in range(n)) return [round(ms[int(.025 * n)], 4), round(ms[int(.975 * n) - 1], 4)] def perm_models(feat, rs, n=5000, seed=1): def spread(rs): v = [stt.mean([x[feat] for x in rs if x["model"] == m]) for m in ["P1", "DS", "GLM"]]; return max(v) - min(v) r = random.Random(seed); obs = spread(rs); g = co.defaultdict(list) for x in rs: g[(x["task"], x["repeat"])].append(x) hit = 0 for _ in range(n): sh = [] for grp in g.values(): labs = [x["model"] for x in grp]; r.shuffle(labs); sh += [dict(x, model=l) for x, l in zip(grp, labs)] hit += spread(sh) >= obs - 1e-12 return round((hit + 1) / (n + 1), 4) def assoc(rs, n=5000, seed=2): def stat(rs): d = [] for t in {x["task"] for x in rs}: a = [x["acc"] for x in rs if x["task"] == t and x["verified"]]; b = [x["acc"] for x in rs if x["task"] == t and not x["verified"]] if a and b: d.append(stt.mean(a) - stt.mean(b)) return stt.mean(d) r = random.Random(seed); obs = stat(rs); g = co.defaultdict(list) for x in rs: g[x["task"]].append(x) hit = 0 for _ in range(n): sh = [] for grp in g.values(): labs = [x["verified"] for x in grp]; r.shuffle(labs); sh += [dict(x, verified=l) for x, l in zip(grp, labs)] hit += abs(stat(sh)) >= abs(obs) - 1e-12 return round(obs, 4), round((hit + 1) / (n + 1), 4) rs = list(V.values()) T = json.loads((S / "source_tests.json").read_text()) diff, pa = assoc(rs) stats = { "checked": {m: {"share": round(stt.mean([x["verified"] for x in rs if x["model"] == m]), 4), "ci": boot([x["verified"] for x in rs if x["model"] == m])} for m in ["P1", "DS", "GLM"]}, "checkedP": perm_models("verified", rs), "lookupsAfter": {m: round(stt.mean([x["post_checks"] for x in rs if x["model"] == m]), 2) for m in ["P1", "DS", "GLM"]}, "lookupsAfterP": perm_models("post_checks", rs), "lookupsTotal": {m: round(stt.mean([x["searches"] + x["reads"] + x["data"] for x in rs if x["model"] == m]), 2) for m in ["P1", "DS", "GLM"]}, "lookupsTotalP": perm_models("lookups_total", [dict(x, lookups_total=x["searches"] + x["reads"] + x["data"]) for x in rs]), "sourceShareMinP": min(T[k]["p"] for k in ["share_search", "share_page", "share_official", "share_data"]), "domains": T["domains"]["byModel"], "domainsP": T["domains"]["p"], "assocDiff": diff, "assocP": pa, } # T10 web searches about a CEO that name a person (the expected incumbent, as a rule) NAMES = re.compile(r"(?i)nadella|pichai|huang|jassy|mcmillon|furner|cornell|fiddelke|quincey|braun|buffett|abel|moeller|jejurikar|hill|niccol|lip-bu|tan\b|gelsinger|ortberg|dimon|bourla|kress") named = total = 0 for tf in sorted((D / "traces").glob("T10-*.jsonl")): for l in open(tf): e = json.loads(l); x = e.get("line", "") if e.get("event") == "harness_said" and x.startswith("⚙ websearch") and re.search(r"(?i)\bceo\b|chief executive", x): total += 1; named += bool(NAMES.search(x)) stats["ceoQueries"] = {"named": named, "total": total} data = {"grid": grid, "strips": strips, "stats": stats} print(json.dumps(stats, indent=1)) OUT.write_text("// Generated by scratchpad/sourcestudy/gen_check_data.py from the run traces. Do not edit.\n" "export type CheckStrip = { model: \"P1\" | \"DS\" | \"GLM\"; repeat: string; calls: string; firstWrite: number | null; nvidiaCheck: number | null; kress: boolean; traced: boolean; route: \"sweep\" | \"followed\" | \"ignored\" | \"none\" | \"untraced\" };\n" "type MK = \"P1\" | \"DS\" | \"GLM\";\nexport type CheckData = { grid: Record>; strips: CheckStrip[]; stats: { checked: Record; checkedP: number; lookupsAfter: Record; lookupsAfterP: number; lookupsTotal: Record; lookupsTotalP: number; sourceShareMinP: number; domains: Record; domainsP: number; assocDiff: number; assocP: number; ceoQueries: { named: number; total: number } } };\n" "export const CHECKS: CheckData = " + json.dumps(data, separators=(",", ":")) + ";\n")