dfm11-mathagentic-tinygsm-python / validate_dataset.py
peter-sk's picture
Add files using upload-large-folder tool
c0c3a41 verified
Raw
History Blame Contribute Delete
1.43 kB
#!/usr/bin/env python3
import gzip, hashlib, json
from pathlib import Path
root = Path(__file__).parent
manifest = json.loads((root / "metadata/manifest.json").read_text())
rows = 0
seen = set()
for item in manifest["data_files"]:
path = root / item["file"]
digest = hashlib.sha256(path.read_bytes()).hexdigest()
if digest != item["sha256"]:
raise ValueError(f"checksum mismatch: {path}")
with gzip.open(path, "rt", encoding="utf-8") as handle:
for line in handle:
row = json.loads(line)
sid = row.get("source_id")
if not sid or sid in seen:
raise ValueError(f"missing or duplicate source_id: {sid}")
seen.add(sid)
messages = row.get("messages")
if [message.get("role") for message in messages] != ["user", "assistant", "tool", "assistant"]:
raise ValueError(f"invalid roles: {sid}")
call = messages[1]["tool_calls"][0]
if call["id"] != messages[2].get("tool_call_id"):
raise ValueError(f"call/result mismatch: {sid}")
if not str(messages[3].get("content") or "").startswith("\\boxed{"):
raise ValueError(f"missing boxed answer: {sid}")
rows += 1
if rows != manifest["rows"]:
raise ValueError(f"row count mismatch: {rows} != {manifest['rows']}")
print(json.dumps({"rows": rows, "valid": True}, sort_keys=True))