u2-bench-code-review / scripts /validate_u2_schema.py
Yiran Zhao
Prepare anonymous NeurIPS review code artifact
f71d8d8
Raw History Blame Contribute Delete
1.1 kB
#!/usr/bin/env python3
from __future__ import annotations
import argparse
import json
from pathlib import Path
REQUIRED = ("qhash", "question", "gold_answer")
def main() -> None:
ap = argparse.ArgumentParser()
ap.add_argument("--input", required=True, help="Path to non-STEM QA JSONL file")
args = ap.parse_args()
path = Path(args.input)
if not path.exists():
raise SystemExit(f"Input file does not exist: {path}")
n = 0
with path.open("r", encoding="utf-8", errors="ignore") as f:
for i, line in enumerate(f, 1):
s = line.strip()
if not s:
continue
n += 1
try:
obj = json.loads(s)
except Exception as exc: # noqa: BLE001
raise SystemExit(f"Line {i} is not valid JSON: {exc}") from exc
missing = [k for k in REQUIRED if k not in obj]
if missing:
raise SystemExit(f"Line {i} missing fields: {missing}")
print(f"OK: {n} rows validated with fields {REQUIRED}")
if __name__ == "__main__":
main()