File size: 1,867 Bytes
524b0ab
 
 
 
 
 
 
 
 
 
 
7319cd6
524b0ab
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env -S uv run --script
# /// script
# requires-python = ">=3.11"
# dependencies = []
# ///
"""Inspect one fictional row and validate every local split without network access."""
import argparse
import hashlib
import json
from pathlib import Path

HERE=Path(__file__).absolute().parent

def main():
    parser=argparse.ArgumentParser()
    parser.add_argument("--self-test",action="store_true")
    args=parser.parse_args()
    meta=json.loads((HERE/"provenance.json").read_text())
    texts=set()
    families=set()
    for split,counts in meta["splits"].items():
        path=HERE/"data"/(split+".jsonl")
        assert hashlib.sha256(path.read_bytes()).hexdigest()==counts["sha256"]
        rows=[json.loads(line) for line in path.read_text().splitlines()]
        if not args.self_test:
            print(json.dumps(rows[0],indent=2,ensure_ascii=False))
            return
        assert len(rows)==counts["rows"]
        current={r["scenario"] for r in rows}
        assert not families & current
        families.update(current)
        for r in rows:
            key=" ".join(r["text"].casefold().split())
            assert key not in texts
            texts.add(key)
            if meta["task"]=="pii":
                end=0
                for s in r["gold"]:
                    assert end<=s["start"]<s["end"]<=len(r["text"]) and s["label"]
                    end=s["end"]
            else:
                words=r["text"].split()
                for s in r["gold"]:
                    words[s["index"]]+=s["mark"]
                assert " ".join(words)==r["reference"]
    if "replay" in meta:
        assert hashlib.sha256((HERE/"replay/replay.jsonl").read_bytes()).hexdigest()==meta["replay"]["sha256"]
    print(f"Verified {len(texts)} distinct messages in {len(families)} disjoint scenario families.")
if __name__=="__main__":
    main()