No human rater exists, so protocol v3 makes the automatic score against the XML answer the G3 reference; the kappa threshold of 0.6 is unchanged. A fixed stratified sample of 100 free-text T4 answers is judged blind by session subagents. Sonnet reaches kappa 0.98 and Haiku 0.90 against the automatic score; T4 headline numbers remain automatic. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
73 lines
3.4 KiB
Python
73 lines
3.4 KiB
Python
from __future__ import annotations
|
|
|
|
import json
|
|
|
|
import pandas as pd
|
|
import pytest
|
|
|
|
from volve_dia import m5_judge as mj
|
|
|
|
|
|
def pool(n_string_wrong=3):
|
|
rows = []
|
|
spec = {("enumeration", True): 30, ("enumeration", False): 30, ("list", True): 20, ("list", False): 20,
|
|
("string", True): 20, ("string", False): n_string_wrong}
|
|
for (kind, ok), n in spec.items():
|
|
for i in range(n):
|
|
rows.append({"item": f"{kind}-{ok}-{i}", "mode": "rag", "modality": "xml", "well": f"W{i % 4}",
|
|
"template": f"T{i % 3}-{kind}", "answer_type": kind, "question": "q", "reference": "r",
|
|
"candidate": f"a{i}", "unit": "", "auto_correct": ok})
|
|
return pd.DataFrame(rows)
|
|
|
|
|
|
def test_draw_is_deterministic_and_moves_shortfall_to_same_score():
|
|
a, b = mj.draw(pool(), 7), mj.draw(pool(), 7)
|
|
assert a.equals(b) and len(a) == 100 and a["judge_id"].is_unique
|
|
sizes = a.groupby(["answer_type", "auto_correct"]).size().to_dict()
|
|
assert sizes[("string", False)] == 3 and sizes[("enumeration", False)] == 30 and sizes[("list", False)] == 17
|
|
assert int(a["auto_correct"].sum()) == 50
|
|
|
|
|
|
def test_draw_drops_identical_answers_to_one_question():
|
|
frame = pool()
|
|
frame = pd.concat([frame, frame.iloc[[0]].assign(candidate=" A0 ")], ignore_index=True)
|
|
out = mj.draw(frame, 1)
|
|
assert not out.duplicated(["item", "candidate"]).any()
|
|
assert len(mj.draw(frame, 1)) == 100
|
|
|
|
|
|
def test_judge_view_hides_score_and_condition(tmp_path):
|
|
sample = mj.draw(pool(), 3)
|
|
items = mj.judge_items(sample)
|
|
assert set(items[0]) == {"id", "question", "reference_answer", "candidate_answer", "candidate_unit"}
|
|
names = mj.write_batches(sample, tmp_path, 50)
|
|
assert names == ["batch_01", "batch_02"]
|
|
body = json.loads((tmp_path / "batch_01.json").read_text())
|
|
assert body["instruction"] == mj.JUDGE_INSTRUCTION and len(body["items"]) == 50
|
|
assert "auto_correct" not in (tmp_path / "batch_01.txt").read_text()
|
|
|
|
|
|
def test_read_verdicts_rejects_bad_files(tmp_path):
|
|
ids = {"J001", "J002"}
|
|
(tmp_path / "batch_01.json").write_text(json.dumps([{"id": "J001", "verdict": "Correct"}]))
|
|
with pytest.raises(ValueError, match="without a verdict"):
|
|
mj.read_verdicts(tmp_path, ids)
|
|
(tmp_path / "batch_02.json").write_text(json.dumps([{"id": "J002", "verdict": "maybe"}]))
|
|
with pytest.raises(ValueError, match="invalid verdict"):
|
|
mj.read_verdicts(tmp_path, ids)
|
|
(tmp_path / "batch_02.json").write_text(json.dumps([{"id": "J002", "verdict": "incorrect"}]))
|
|
assert mj.read_verdicts(tmp_path, ids) == {"J001": "correct", "J002": "incorrect"}
|
|
|
|
|
|
def test_summary_kappa_and_gate():
|
|
sample = pd.DataFrame({"judge_id": [f"J{i}" for i in range(8)], "well": ["A", "A", "B", "B", "C", "C", "D", "D"],
|
|
"answer_type": ["list"] * 8, "auto_correct": [True, False] * 4})
|
|
perfect = {f"J{i}": ("correct" if i % 2 == 0 else "incorrect") for i in range(8)}
|
|
flipped = {**perfect, "J0": "incorrect", "J1": "correct"}
|
|
report, frame = mj.summarise(sample, {"sonnet": perfect, "haiku": flipped}, "sonnet", 0.6, 200, 1)
|
|
assert report["judges"]["sonnet"]["kappa"] == pytest.approx(1.0)
|
|
assert report["judges"]["haiku"]["kappa"] == pytest.approx(0.5)
|
|
assert report["g3"]["passed"] is True and report["between_judges"]["n"] == 8
|
|
report, _ = mj.summarise(sample, {"sonnet": flipped}, "sonnet", 0.6, 200, 1)
|
|
assert report["g3"]["passed"] is False
|