Download scripts/check_gate6b.py from Raphael2099/llm-data-eval-20261030: direct link, hf CLI and curl.
- Browser
- Download file 7.03 kB
-
https://huggingface.co/datasets/Raphael2099/llm-data-eval-20261030/resolve/main/scripts/check_gate6b.py
- Command line
-
hf download hf://datasets/Raphael2099/llm-data-eval-20261030/scripts/check_gate6b.py
-
curl -L -o check_gate6b.py https://huggingface.co/datasets/Raphael2099/llm-data-eval-20261030/resolve/main/scripts/check_gate6b.py
7.03 kB
| # check_gate6b.py —— scoring v2 for the 13-probe WW-6 gate panel (2026-10-30, relay round 3). | |
| # v1 mis-scored two whole probe families (both fixed here, evidence read by hand): | |
| # * Q&A probes (P04/P12) answer about 三 without repeating 日不食 -> the window rule failed them | |
| # for every arm, including the base control. Now Q&A C2 = the 三 must appear in the answer. | |
| # * Q&A probe (P11) legitimately *mentions* 「谷物成熟」in order to reject it ("而非…"), so a bare | |
| # "谷+成熟" hit is not an error. Now a hit is only counted when no rejection word sits within | |
| # 14 chars either side. | |
| # Extra column (NOT part of the 3/3 verdict): wrong_king — fabricated royal names in 简63/64 | |
| # (成王/纣王/周王/… where 简文 has 王 = 吴王). Reported separately so the official criteria | |
| # stay exactly as pre-registered (C1 = 楚王 only). | |
| # 用法: python check_gate6b.py DIR [OUT.json] | |
| import json, os, re, sys | |
| D = sys.argv[1] if len(sys.argv) > 1 else "." | |
| ORDER = [ | |
| "N29_O28_C_r64_LR5em5_s20261031", | |
| "N29_O28_C_r32_LR5em5_s20261031", | |
| "N29_O28_C_r32_LR1em4_s20261031", | |
| "N29_O28_C_r64_LR1em4_s20261031", | |
| "LR5em5_s20261028", | |
| "O28_B_r64_LR1em4_s20261030", | |
| "N29_O28_D_r64_LR5em5_s20261028", | |
| "control_U27v2s1", | |
| ] | |
| APPL = { | |
| "P01_v2_repeat": ("C1", "C2", "C3"), "P02_v3_names": ("C1", "C2", "C3"), | |
| "P03_v4_6463": ("C1", "C2", "C3"), "P04_v5_qa": ("C1", "C2", "C3"), | |
| "P05_gloss": ("C1", "C2", "C3"), "P06_only63": ("C1",), | |
| "P07_only64": ("C1", "C2", "C3"), "P08_brief": ("C1", "C2", "C3"), | |
| "P09_annot": ("C1", "C2", "C3"), "P10_interlinear": ("C1", "C2", "C3"), | |
| "P11_qa_reward": ("C1", "C3"), "P12_qa_three": ("C1", "C2"), | |
| "P13_qa_names": ("C1",), | |
| } | |
| QA_PROBES = {"P04_v5_qa", "P11_qa_reward", "P12_qa_three", "P13_qa_names"} | |
| # only the probe that asks about 「成」 requires an explicit "ready / handed out" commitment | |
| COMMIT_PROBES = {"P11_qa_reward"} | |
| REJECT = ("不是", "而非", "非", "未", "没有", "不", "区别", "误") | |
| WRONG_KING = ("楚王", "成王", "纣王", "周王", "商王", "秦王", "齐王", "庄王", | |
| "魏王", "韩王", "赵王", "燕王", "鲁王", "晋王") | |
| def c1(h): | |
| bad = "楚王" in h | |
| return (not bad), ("楚王" if bad else ("越王" if "越王" in h else "-")) | |
| def c2(h, pid): | |
| if pid in ("P04_v5_qa", "P12_qa_three"): | |
| ok = "三" in h | |
| return ok, ("三 in answer" if ok else "no 三") | |
| ok = False | |
| for m in re.finditer(r"不[进進]?食|绝食|絕食|不吃|没吃|沒有吃|没有吃", h): | |
| seg = h[max(0, m.start() - 30): m.end() + 8] | |
| if "三" in seg or "叁" in seg: | |
| ok = True | |
| return ok, ("三∈window" if ok else "no 三") | |
| def _clause_of(h, s, e): | |
| """Return the clause (split on ,。;!?\n) that contains [s,e).""" | |
| left = max(h.rfind(c, 0, s) for c in ",。;!?\n") + 1 | |
| rights = [h.find(c, e) for c in ",。;!?\n"] | |
| rights = [r for r in rights if r != -1] | |
| right = min(rights) if rights else len(h) | |
| return h[left:right] | |
| def _rejected(h, s, e): | |
| """A hit only counts as a committed reading if its own clause does not reject it.""" | |
| cl = _clause_of(h, s, e) | |
| return any(r in cl for r in REJECT) | |
| def c3(h, pid): | |
| reward = bool(re.search(r"(赏|赐|授)[^。;\n]{0,12}(谷|穀|粮|米|饭|食)", h)) or \ | |
| bool(re.search(r"(谷|穀|粮)[^。;\n]{0,6}(赏|赐)", h)) | |
| commit = bool(re.search(r"备好|准备妥|备妥|备齐|办成|发放|备下|已备|准备完毕|准备妥|就绪", h)) | |
| # P11 asks a question ABOUT 「成」, so the model legitimately discusses the wrong reading | |
| # ("如果成指谷物成熟…"). There the criterion is: it commits to ready/handed-out AND it | |
| # explicitly rejects the ripening reading. Discussion of the hypothesis is not an error. | |
| if pid in COMMIT_PROBES: | |
| reject = bool(re.search(r"(而非|不是|并非|不作|不指)[^。;\n]{0,10}(谷物)?成熟", h)) | |
| ok = reward and commit and reject | |
| tag = "reward" if reward else "no-reward" | |
| tag += "/commit" if commit else "/no-commit" | |
| tag += "/reject" if reject else "/no-reject" | |
| return ok, tag | |
| mature = False | |
| for m in re.finditer(r"(谷|穀|粮食|庄稼|稻|禾)[^。;\n]{0,6}(成熟|长成|熟了|结成)", h): | |
| if not _rejected(h, m.start(), m.end()): | |
| mature = True | |
| ok = reward and not mature | |
| tag = "reward" if reward else "no-reward" | |
| if mature: | |
| tag += "+mature" | |
| return ok, tag | |
| CHK = {"C1": c1, "C2": c2, "C3": c3} | |
| summary, mismatches = {}, [] | |
| for tag in ORDER: | |
| p = os.path.join(D, tag + ".probes.jsonl") | |
| if not os.path.exists(p): | |
| summary[tag] = {"missing": True} | |
| print("ARM", tag, "MISSING") | |
| continue | |
| rows = [json.loads(l) for l in open(p, encoding="utf-8")] | |
| clean = 0 | |
| cf = {"C1": 0, "C2": 0, "C3": 0} | |
| cn = {"C1": 0, "C2": 0, "C3": 0} | |
| wrong = {} | |
| detail = [] | |
| for r in rows: | |
| pid, h = r["id"], r["hyp"] | |
| crit = APPL.get(pid, ("C1", "C2", "C3")) | |
| st, ok_all = {}, True | |
| for c in crit: | |
| ok, ev = CHK[c](h, pid) if c != "C1" else CHK[c](h) | |
| st[c] = {"ok": ok, "ev": ev} | |
| cn[c] += 1 | |
| if not ok: | |
| cf[c] += 1 | |
| ok_all = False | |
| wk = [w for w in WRONG_KING if w in h] | |
| if wk: | |
| wrong[pid] = wk | |
| if r.get("finish") not in (None, "stop") or len(h.strip()) < 8: | |
| ok_all = False | |
| st["bad_finish"] = r.get("finish") | |
| clean += 1 if ok_all else 0 | |
| detail.append({"id": pid, "ok": ok_all, "st": st, "finish": r.get("finish"), | |
| "n_tok": r.get("n_tok"), "wrong_king": wk, "hyp": h}) | |
| if not ok_all: | |
| mismatches.append({"arm": tag, "probe": pid, "hyp": h[:700], | |
| "why": {k: v for k, v in st.items() | |
| if k == "bad_finish" or (isinstance(v, dict) and not v["ok"])}}) | |
| three = cf["C1"] == 0 and cf["C2"] == 0 and cf["C3"] == 0 | |
| summary[tag] = {"rows": len(rows), "clean": clean, "of": len(rows), "crit_fail": cf, | |
| "crit_n": cn, "three_of_three": three, "wrong_king": wrong, "detail": detail} | |
| print("\n%-34s clean=%2d/%d C1fail=%d/%d C2fail=%d/%d C3fail=%d/%d 3of3=%s wrong_king=%s" | |
| % (tag, clean, len(rows), cf["C1"], cn["C1"], cf["C2"], cn["C2"], cf["C3"], cn["C3"], | |
| three, wrong)) | |
| for d in detail: | |
| marks = " ".join("%s:%s" % (k, "OK" if v["ok"] else "FAIL") for k, v in d["st"].items() | |
| if isinstance(v, dict)) | |
| print(" %-16s %s %s" % (d["id"], "PASS" if d["ok"] else "FAIL", marks)) | |
| if len(sys.argv) > 2: | |
| with open(sys.argv[2], "w", encoding="utf-8") as f: | |
| json.dump({"summary": summary, "mismatches": mismatches}, f, ensure_ascii=False, indent=1) | |
| print("\nWROTE", sys.argv[2]) | |