File size: 4,208 Bytes
2faa5f6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
109
110
111
112
113
114
#!/usr/bin/env python3
"""Validate the public RAISER dataset tree."""

from __future__ import annotations

import argparse
import csv
import json
from pathlib import Path


ROLES = (
    "source", "propagator", "missed_verifier", "contract_violation",
    "symptom", "repair_leverage",
)
FORBIDDEN_RAW_FIELDS = {
    "answer", "answer_key", "content", "conversation_history", "evidence",
    "expected_answer", "ground_truth", "history", "model_text", "parsed_answer",
    "prompt", "query", "question", "rationale", "raw_content", "raw_span",
    "task_text", "thinking", "tool_output",
}


def jsonl(path: Path) -> list[dict]:
    rows = []
    for number, line in enumerate(path.read_text(encoding="utf-8").splitlines(), 1):
        if not line.strip():
            continue
        row = json.loads(line)
        leaked = FORBIDDEN_RAW_FIELDS.intersection(row)
        assert not leaked, f"{path}:{number}: raw fields {sorted(leaked)}"
        rows.append(row)
    return rows


def csv_rows(path: Path) -> list[dict]:
    with path.open(encoding="utf-8", newline="") as stream:
        rows = list(csv.DictReader(stream))
    if rows:
        leaked = FORBIDDEN_RAW_FIELDS.intersection(rows[0])
        assert not leaked, f"{path}: raw fields {sorted(leaked)}"
    return rows


def main() -> None:
    parser = argparse.ArgumentParser()
    parser.add_argument("root", type=Path, nargs="?", default=Path("."))
    root = parser.parse_args().root.resolve()

    for filename, tier, expected in (
        ("consensus_gold.jsonl", "gold", 5516),
        ("model_silver.jsonl", "silver", 43077),
    ):
        rows = jsonl(root / "data/model_benchmark" / filename)
        assert len(rows) == expected
        keys = set()
        for row in rows:
            assert row["annotation_tier"] == tier
            assert row["split"] in {"train", "dev", "test"}
            key = (row["dataset_source"], row["trace_id"], row["event_id"])
            assert key not in keys
            keys.add(key)
            for role in ROLES:
                assert row[role] in {0, 1}
                confidence = row[f"{role}_confidence"]
                assert confidence is None or 0 <= float(confidence) <= 1

    human = jsonl(root / "data/human_gold/mv_cv_test.jsonl")
    assert len(human) == 1600
    assert len({row["candidate_id"] for row in human}) == 1600
    assert {row["target_role"] for row in human} == {
        "missed_verifier", "contract_violation"
    }
    assert all(row["label"] in {0, 1} for row in human)

    source = csv_rows(root / "data/event_source/broad_cross_annotation.csv")
    assert len(source) == 1267
    assert len({row["source_gold_id"] for row in source}) == 1267
    assert all(row["label_a"] in {"0", "1", "UNCERTAIN"} for row in source)
    assert all(row[field] in {"0", "1"} for row in source for field in (
        "label_b", "strict_positive", "positive_union"
    ))

    untouched = csv_rows(root / "data/repair_evaluation/untouched_346.csv")
    assert len(untouched) == 346
    assert len({row["trace_id"] for row in untouched}) == 346
    assert all(row[field] in {"0", "1"} for row in untouched for field in (
        "raiser_repair_at_1", "query_only_repair_at_1"
    ))

    component = csv_rows(root / "data/repair_evaluation/component_1200.csv")
    assert len(component) == 4800
    by_trace: dict[str, set[str]] = {}
    for row in component:
        by_trace.setdefault(row["trace_id"], set()).add(row["configuration"])
        for field in ("oracle_at_k", "rank_at_1", "repair_at_1"):
            assert row[field] in {"0", "1"}
    assert len(by_trace) == 1200 and all(len(configs) == 4 for configs in by_trace.values())

    native = csv_rows(root / "data/repair_evaluation/native_checkpoint_150.csv")
    assert len(native) == 600
    assert {row["framework"] for row in native} == {"langgraph", "autogen"}
    assert {row["selector"] for row in native} == {"RAISER", "answer-majority"}
    groups = {(row["framework"], row["trace_id"], row["selector"]) for row in native}
    assert len(groups) == 600
    assert all(row["success"] in {"0", "1"} for row in native)

    print("RAISER dataset validation passed")


if __name__ == "__main__":
    main()