turkic-ocr-code / scripts /r5_testpass2 /tp2_a5_merge.py
treoa's picture
Release 1
24aaa76
Raw History Blame Contribute Delete
3.22 kB
"""Merges amendment-5 results (26 Nov) into records/R5/TESTPASS2/results.json and per_language.json: 'qwen_amendment5' (Qwen3-VL-2B crop
sets from their score files, TurkishOCR handwritten pages, az script measures) and 'ppocr_tob_pages' (PP-OCRv6 medium label-free on the
TurkishOCR handwritten pages). Aggregates only. Sets whose score file is missing are reported 'not run'.
usage: tp2_a5_merge.py TESTPASS2_DIR A5_DIR
"""
import json
import os
import sys
TP, A5 = sys.argv[1], sys.argv[2]
def load(p):
return json.load(open(p, encoding="utf-8")) if os.path.exists(p) else None
def crop(d):
if d is None or d.get("status") != "scored":
return {"status": "not run (not complete by the 04:36Z deadline, or not scored)"}
pl = d["profiles"]["plain"]
m = pl["groups"]["all"]["metrics"]
r = {"status": "scored", "n": d["set_info"]["n_scored"], "clusters": d["set_info"]["n_clusters"], "cluster_unit": d["set_info"]["cluster_unit"],
"coverage_complete": d["coverage"]["complete"], "pred_sha256": d["inputs"]["pred_sha256"], "scored_utc": d["scored_utc"]}
for k in ("cer", "wer", "exact_match", "cer_casefold", "hr3", "hr4", "fabricated_word_rate", "empty_output_rate"):
if k in m:
r[k] = {x: m[k].get(x) for x in ("value", "lo", "hi", "num", "den")}
r["per_language_cer"] = {g.replace("lang:", ""): {"rows": v["n_items"], **{x: v["metrics"]["cer"].get(x) for x in ("value", "lo", "hi", "num", "den")}}
for g, v in pl["groups"].items() if g.startswith("lang:") and "cer" in v["metrics"]}
return r
def page(d):
if d is None:
return {"status": "not run"}
d = dict(d)
d.pop("per_page_counts", None)
return d
q = {"note": ("plan amendment 5 of 26 Nov (plan entry n 6); Qwen3-VL-2B R5 leader on an H100 (job 55694) with the test pass 2 inference "
"code; descriptive; plain-profile CER, 95% cluster bootstrap of the R5 scorer"),
"crops": {s: crop(load(os.path.join(A5, "q_%s.json" % s))) for s in ("synth_typed_test", "rukopys_test", "synth_hand_test", "school_test")},
"turkishocr_handwritten_pages": page(load(os.path.join(A5, "page_score_tob_hand_qwen.json"))),
"az_localdoc_script": load(os.path.join(A5, "qwen_az_script.json"))}
pp = {"note": ("plan amendment 5 of 26 Nov: PP-OCRv6 medium (A1 long2x, release infer.py) label-free batching on the 50 TurkishOCR-Bench "
"handwritten pages, existing test pass 2 detector boxes and reading order; page scorer as for M1 (job 55695); descriptive"),
"greedy": page(load(os.path.join(A5, "page_score_tob_hand_ppocr_greedy.json"))),
"gated_lm": page(load(os.path.join(A5, "page_score_tob_hand_ppocr_lm.json")))}
lat = load(os.path.join(A5, "m1latin_az_pair.json"))
for fn in ("results.json", "per_language.json"):
p = os.path.join(TP, fn)
R = json.load(open(p, encoding="utf-8"))
R["qwen_amendment5"] = q
R["ppocr_tob_pages"] = pp
if lat:
R["m1_latin_only_az_amendment6"] = lat
json.dump(R, open(p, "w", encoding="utf-8"), indent=1, ensure_ascii=False)
print(json.dumps({s: (v.get("status"), (v.get("cer") or {}).get("value")) for s, v in q["crops"].items()}))