| |
| 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()) |
|
|