KoOCR-Bench / code /engines /export_preds.py
ubermensch1218's picture
KoDocBench v1 data + scoring code (private staging)
fa8b928 verified
Raw History Blame Contribute Delete
652 Bytes
#!/usr/bin/env python3
"""raw client rows -> predictions.jsonl {id: kbench id with '/', text}. Usage: export_preds.py MANIFEST_JSON... -- RAW_JSONL... -- OUT"""
import json, sys
a = sys.argv[1:]; i = a.index("--"); j = a.index("--", i + 1)
kid = {p["id"]: p["kid"] for m in a[:i] for p in json.load(open(m))["pages"]}
rows = {}
for raw in a[i + 1:j]:
for l in open(raw):
r = json.loads(l); rows[r["id"]] = r
with open(a[j + 1], "w") as f:
for k, r in rows.items(): f.write(json.dumps({"id": kid[k], "text": r["text"], "finish": r["finish"], "error": r["error"]}, ensure_ascii=False) + "\n")
print("exported", len(rows), "of", len(kid))