File size: 4,948 Bytes
e1ced61
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/usr/bin/env python3
"""Recompute the manuscript's argument counts from archived per-item records.

This checks response scoring and archived finite-study outcomes. It does not
rerun inference, construct witnesses, or repeat the finite solvers.
"""
import argparse
from collections import Counter
import gzip
import json
from pathlib import Path

from analyze_visual_judges import number, valid_parsed


def records(path):
    opener = gzip.open if path.suffix == ".gz" else open
    with opener(path, "rt") as handle:
        return [json.loads(line) for line in handle if line.strip()]


def check(inputs, finite_path, solver_path):
    labels = json.loads((inputs / "plotqa/labels.json").read_text())
    by_id = {row["item_id"]: row for row in labels}
    responses = records(inputs / "plotqa/qwen38-flash-next.jsonl.gz")
    assert len(labels) == len(by_id) == len(responses) == 5000
    ids = [row["item_id"] for row in responses]
    assert len(set(ids)) == 5000 and set(ids) == set(by_id)
    counts = dict(correct=0, rejected=0, numeric_mismatch=0, unparsed=0, invalid=0)
    for row in responses:
        label = by_id[row["item_id"]]
        if not label["answerable"]:
            continue
        parsed = valid_parsed(row)
        if parsed is None:
            category = "invalid"
        elif not parsed["answerable"]:
            category = "rejected"
        elif number(parsed["answer"]) is None:
            category = "unparsed"
        elif number(parsed["answer"]) == number(label["target"]):
            category = "correct"
        else:
            category = "numeric_mismatch"
        counts[category] += 1
    assert counts == dict(correct=2473, rejected=49, numeric_mismatch=478,
                          unparsed=0, invalid=0), counts

    finite = records(finite_path)
    assert len({row["id"] for row in finite}) == len(finite) == 1024
    assert all(row["source_checks_passed"] and row["oracle_agreement"] for row in finite)
    finite_counts = dict(
        cases=len(finite),
        ambiguous=sum(row["oracle_ambiguous"] for row in finite),
        constant=sum(not row["oracle_ambiguous"] for row in finite),
        dependency_false_missing=sum(row["dependency_cut_claims_missing"]
                                     and not row["oracle_ambiguous"] for row in finite),
        endpoint_missed_ambiguity=sum(not row["endpoint_separates"]
                                     and row["oracle_ambiguous"] for row in finite),
        archived_proofs_verified=sum(row["proof_verified"] is True for row in finite),
    )
    assert finite_counts == dict(cases=1024, ambiguous=610, constant=414,
                                 dependency_false_missing=132,
                                 endpoint_missed_ambiguity=90,
                                 archived_proofs_verified=610), finite_counts
    solver = records(solver_path)
    assert len({(row["cohort"], row["id"]) for row in solver}) == len(solver) == 1456
    assert all(row["source_checks_passed"] for row in solver)
    assert all(row["truth"] == row["smt_status"] == row["enumeration_status"]
               for row in solver)
    solver_counts = Counter(row["truth"] for row in solver)
    assert dict(solver_counts) == dict(ambiguous=822, constant=634), solver_counts
    finite_truth = {row["id"]: "ambiguous" if row["oracle_ambiguous"] else "constant"
                    for row in finite}
    original_solver = {row["id"]: row["truth"] for row in solver if row["cohort"] == "original"}
    assert original_solver == finite_truth
    assert sum(row["dependency_false_missing"] for row in solver) == 225
    return {
        "status": "passed",
        "source": "archived per-response and per-case records",
        "qwen_positive_chart_views": counts,
        "finite_program_cases": finite_counts,
        "enumeration_smt_record_agreement": {
            "cases": len(solver), **dict(solver_counts), "dependency_false_missing": 225
        },
        "inference_calls": 0,
        "solvers_rerun": False,
        "proof_archive_replayed_by_this_command": False,
        "interpretation": (
            "Numeric mismatches remain task errors; no cause adjudication is inferred. "
            "Finite shortcut counts describe the author-generated distribution, "
            "not external annotation accuracy."
        ),
    }


if __name__ == "__main__":
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument("--inputs", type=Path, required=True)
    parser.add_argument("--finite-results", type=Path, required=True)
    parser.add_argument("--solver-results", type=Path, required=True)
    parser.add_argument("--output", type=Path, required=True)
    args = parser.parse_args()
    result = check(args.inputs, args.finite_results, args.solver_results)
    args.output.parent.mkdir(parents=True, exist_ok=True)
    args.output.write_text(json.dumps(result, indent=2) + "\n")
    print(json.dumps(result))