# Copyright 2026 EdgeCase Labs # Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0 """Score answers on the ChessDrive Term benchmark, and build the prompt the text-only models were given. python evaluate.py results/claude-opus-5.5-medium.jsonl results/chessdrive-base-v1.jsonl python evaluate.py --prompt tb-0001 # print the exact system and user text for one question An answers file has one JSON object per line: {"id": "tb-0001", "answer": ""}. A missing id or a reply that does not start with yes or no counts as wrong. Reported: accuracy with a 95% Wilson interval, accuracy on yes and near-miss questions, by Term class and question type, and an exact McNemar test between each pair of files. """ import argparse, json, math, os, re HERE = os.path.dirname(os.path.abspath(__file__)) SYSTEM = ( "You answer questions about chess positions. The position is given as a FEN. Moves are written in UCI " "(from-square to-square, e.g. e2e4; a fifth letter is a promotion). When a question names moves, they are " "played in order from the given position. Reply with exactly one word, Yes or No, and nothing else. " "Do not use tools or an engine." ) def user_text(row): side = "White" if row["fen"].split()[1] == "w" else "Black" return f"Position (FEN): {row['fen']}\nSide to move: {side}\n\n{row['question']}" _LEAD = re.compile(r"^[\s\*\_\#\>\"'`“”‘’\-•:]*") def yes_no(text): """The reply's leading yes or no, after stripping markdown and quotes; None if there is none.""" if text is None: return None m = re.match(r"(yes|no)\b", _LEAD.sub("", text.strip().lower())) return m.group(1) if m else None def wilson(k, n, z=1.96): if not n: return None p = k / n d = 1 + z * z / n c = (p + z * z / (2 * n)) / d h = z * math.sqrt(p * (1 - p) / n + z * z / (4 * n * n)) / d return round(c - h, 4), round(c + h, 4) def mcnemar(a, b): """Exact two-sided McNemar test on paired right/wrong lists.""" x = sum(p and not q for p, q in zip(a, b)) y = sum(q and not p for p, q in zip(a, b)) n = x + y if not n: return x, y, 1.0 tail = sum(math.comb(n, i) for i in range(min(x, y) + 1)) / 2 ** n return x, y, min(1.0, 2 * tail) def main(): ap = argparse.ArgumentParser() ap.add_argument("answers", nargs="*") ap.add_argument("--data", default=f"{HERE}/data/test.jsonl") ap.add_argument("--prompt", metavar="ID") a = ap.parse_args() rows = [json.loads(l) for l in open(a.data)] if a.prompt: r = next(r for r in rows if r["id"] == a.prompt) print(f"[system]\n{SYSTEM}\n\n[user]\n{user_text(r)}") return right = {} for path in a.answers: ans = {} for l in open(path): x = json.loads(l) ans.setdefault(x["id"], x.get("answer")) ok = [yes_no(ans.get(r["id"])) == r["answer"].lower() for r in rows] right[path] = ok def acc(keep): sel = [o for o, r in zip(ok, rows) if keep(r)] return f"{100 * sum(sel) / len(sel):5.1f}" if sel else " - " lo, hi = wilson(sum(ok), len(ok)) print(f"{os.path.basename(path):60} {100 * sum(ok) / len(ok):5.1f}% ({100 * lo:.1f}-{100 * hi:.1f}) " f"yes {acc(lambda r: r['category'] == 'yes')} near miss {acc(lambda r: r['category'] == 'near_miss')} " f"whole-position {acc(lambda r: r['term_class'] == 'whole-position')} judgement {acc(lambda r: r['term_class'] == 'judgement')} " f"after moves {acc(lambda r: r['type'] == 'after-moves')}") names = list(right) for i, x in enumerate(names): for y in names[i + 1:]: k1, k2, p = mcnemar(right[x], right[y]) print(f"{os.path.basename(x)} vs {os.path.basename(y)}: {k1} right only in the first, {k2} only in the second, p = {p:.2g}") if __name__ == "__main__": main()