File size: 1,797 Bytes
87d9b57
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
import json
import sys
from pathlib import Path

ROOT = Path(__file__).resolve().parents[1]
REQUIRED = {"id", "task", "messages", "source", "license", "quality_score"}

def main() -> int:
    seen, errors, count = set(), [], 0
    for split in ("train", "validation", "test"):
        path = ROOT / "data" / f"{split}.jsonl"
        with path.open(encoding="utf-8") as handle:
            for line_no, line in enumerate(handle, 1):
                count += 1
                try:
                    row = json.loads(line)
                except json.JSONDecodeError as exc:
                    errors.append(f"{path}:{line_no}: invalid JSON: {exc}")
                    continue
                if missing := REQUIRED - row.keys():
                    errors.append(f"{path}:{line_no}: missing {sorted(missing)}")
                if row.get("id") in seen:
                    errors.append(f"{path}:{line_no}: duplicate id {row.get('id')}")
                seen.add(row.get("id"))
                score = row.get("quality_score")
                if not isinstance(score, (int, float)) or not 0 <= score <= 1:
                    errors.append(f"{path}:{line_no}: quality_score must be 0..1")
                messages = row.get("messages")
                if not isinstance(messages, list) or not messages:
                    errors.append(f"{path}:{line_no}: messages must be non-empty")
                elif any(set(m) != {"role", "content"} for m in messages):
                    errors.append(f"{path}:{line_no}: invalid message schema")
    if errors:
        print("\n".join(errors), file=sys.stderr)
        return 1
    print(f"Validated {count} examples across 3 splits; all ids are unique.")
    return 0

if __name__ == "__main__":
    raise SystemExit(main())