File size: 3,005 Bytes
4b8d886
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""Verify MDU-RiskText/MDU-RiskBench row alignment and file hashes."""

from __future__ import annotations

import gzip
import hashlib
import json
from collections import Counter
from pathlib import Path

ROOT = Path(__file__).resolve().parents[1]
SETTINGS = ("video_only", "non_video_only", "all_filtered_text")
SPLITS = ("train", "validation", "test")


def digest(path: Path) -> str:
    value = hashlib.sha256()
    with path.open("rb") as handle:
        for chunk in iter(lambda: handle.read(1024 * 1024), b""):
            value.update(chunk)
    return value.hexdigest()


def rows(path: Path):
    with gzip.open(path, "rt", encoding="utf-8") as handle:
        for line in handle:
            if line.strip():
                yield json.loads(line)


def main() -> None:
    manifest = json.loads((ROOT / "MANIFEST.json").read_text(encoding="utf-8"))
    for entry in manifest["files"]:
        path = ROOT / entry["path"]
        if path.stat().st_size != entry["bytes"]:
            raise SystemExit(f"size mismatch: {entry['path']}")
        if digest(path) != entry["sha256"]:
            raise SystemExit(f"hash mismatch: {entry['path']}")

    identities = {}
    for setting in SETTINGS:
        current = {}
        for split in SPLITS:
            path = ROOT / "MDU-RiskText" / setting / f"{split}.jsonl.gz"
            for row in rows(path):
                if row["split"] != split or row["benchmark_setting"] != setting:
                    raise SystemExit(f"metadata mismatch: {path}")
                package = row["llm_evidence_package"]
                if package["sample_id"] != row["sample_id"]:
                    raise SystemExit(f"package ID mismatch: {row['sample_id']}")
                if json.loads(row["text_evidence"]) != package:
                    raise SystemExit(f"text package mismatch: {row['sample_id']}")
                current[row["sample_id"]] = (
                    split,
                    row["target_label"]["risk_level"],
                )
        if len(current) != 850:
            raise SystemExit(f"{setting}: expected 850 records, got {len(current)}")
        if identities and current != identities:
            raise SystemExit(f"cross-setting identity mismatch: {setting}")
        identities = current

    split_counts = Counter(split for split, _ in identities.values())
    label_counts = Counter(label for _, label in identities.values())
    expected_splits = {"train": 593, "validation": 131, "test": 126}
    expected_labels = {
        "no_observed_risk": 226,
        "mild_risk": 432,
        "moderate_risk": 172,
        "high_risk": 20,
    }
    if dict(split_counts) != expected_splits:
        raise SystemExit(f"split counts differ: {dict(split_counts)}")
    if dict(label_counts) != expected_labels:
        raise SystemExit(f"label counts differ: {dict(label_counts)}")
    print("Verified 850 aligned participants across 3 settings and 9 data files.")


if __name__ == "__main__":
    main()