File size: 2,315 Bytes
54c192e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
"""Score named typed answers for Structured State Reasoning Probe."""
import argparse
import json
from pathlib import Path


def load_jsonl(path):
    return [json.loads(line) for line in Path(path).read_text().splitlines() if line.strip()]


def normalize(spec, raw):
    if spec["type"] == "choice":
        return raw.get("choice") if isinstance(raw, dict) else raw
    if spec["type"] == "noul":
        if isinstance(raw, bool):
            return raw
        if isinstance(raw, dict) and isinstance(raw.get("noul"), (int, float)):
            return raw["noul"] >= 0.5
    return None


def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("predictions", help="JSONL rows: task_id and answers map")
    parser.add_argument("--dataset", default=str(Path(__file__).resolve().parent / "test.jsonl"))
    args = parser.parse_args()
    dataset = load_jsonl(args.dataset)
    predictions = load_jsonl(args.predictions)
    tasks = {row["task_id"]: row for row in dataset}
    pred = {row["task_id"]: row for row in predictions}
    if len(tasks) != len(dataset) or len(pred) != len(predictions):
        raise SystemExit("Duplicate task_id in data or predictions")
    if set(tasks) != set(pred):
        raise SystemExit(f"Prediction coverage mismatch: missing={sorted(set(tasks)-set(pred))}, extra={sorted(set(pred)-set(tasks))}")
    task_pass = question_correct = question_total = 0
    per_task = []
    for tid, row in tasks.items():
        questions = json.loads(row["questions_json"])
        gold = json.loads(row["gold_json"])
        answers = pred[tid]["answers"]
        if set(answers) != set(questions):
            raise SystemExit(f"Question coverage mismatch for {tid}")
        checks = {qid: normalize(spec, answers[qid]) == gold[qid] for qid, spec in questions.items()}
        passed = all(checks.values())
        task_pass += passed
        question_correct += sum(checks.values())
        question_total += len(checks)
        per_task.append({"task_id": tid, "pass": passed, "questions": checks})
    print(json.dumps({"tasks_passed": task_pass, "tasks_total": len(tasks),
                      "questions_correct": question_correct, "questions_total": question_total,
                      "per_task": per_task}, indent=2))


if __name__ == "__main__":
    main()