Download scripts/r5_testpass2/tp2_per_language_finalize.py from treoa/turkic-ocr-code: direct link, hf CLI and curl.
- Browser
- Download file 2.63 kB
-
https://huggingface.co/treoa/turkic-ocr-code/resolve/main/scripts/r5_testpass2/tp2_per_language_finalize.py
- Command line
-
hf download hf://treoa/turkic-ocr-code/scripts/r5_testpass2/tp2_per_language_finalize.py
-
curl -L -o tp2_per_language_finalize.py https://huggingface.co/treoa/turkic-ocr-code/resolve/main/scripts/r5_testpass2/tp2_per_language_finalize.py
2.63 kB
| """Adds label provenance and set sizes (from checks.json, plan.json and the R5 registry copy) to the cluster per-language file and writes | |
| records/R5/TESTPASS2/per_language.json. | |
| usage: tp2_per_language_finalize.py TESTPASS2_DIR CLUSTER_JSON | |
| """ | |
| import json | |
| import os | |
| import sys | |
| TP, CJ = sys.argv[1], sys.argv[2] | |
| X = json.load(open(CJ, encoding="utf-8")) | |
| K = json.load(open(os.path.join(TP, "checks.json"), encoding="utf-8")) | |
| R = {e["name"]: e for e in json.load(open(os.path.join(TP, "ref", "evalsets.json"), encoding="utf-8"))["sets"]} | |
| lab = K["label_provenance"] | |
| EXTRA = { | |
| "kohtd_test": ("crowd labels (two volunteers agreeing), registry caution; used as the R5 primary endpoint", "primary"), | |
| "print_real_test": ("exact: the born-digital PDF text layer (registry); machine-audited 50 lines per language-script, not a human", "primary (typed)"), | |
| "synth_clutter_test": ("exact by construction: empty target", "primary (invented text)"), | |
| } | |
| info = {} | |
| for s in list(X["synthetic_and_print"]) + list(X["real_sets"]): | |
| if s in lab: | |
| v = {"label_provenance": lab[s]["verdict"], "use": lab[s]["use"]} | |
| elif s in EXTRA: | |
| v = {"label_provenance": EXTRA[s][0], "use": EXTRA[s][1]} | |
| else: | |
| key = [k for k in lab if k.split(" ")[0] in s or s.split(" ")[0] in k] | |
| v = {"label_provenance": lab[key[0]]["verdict"], "use": lab[key[0]]["use"]} if key else {"label_provenance": "see checks.json", "use": ""} | |
| if s in R: | |
| v.update({"rows": R[s]["n_rows"], "groups": R[s]["n_groups"], "group_unit": R[s].get("group_unit"), "langs": R[s].get("langs")}) | |
| info[s] = v | |
| info["turkishocr_bench_handwritten_pages (tr)"] = {"label_provenance": lab["tob_hand (TurkishOCR-Bench handwritten pages)"]["verdict"], | |
| "use": "primary", "pages": 50} | |
| info["turkishocr_bench_printed_text_pages (tr)"] = {"label_provenance": lab["tob_print_text_categories"]["verdict"], "use": "descriptive", | |
| "pages": 233} | |
| kz = [k for k in lab if k.startswith("kzb_hand")] | |
| if kz: | |
| info["kz_benchmark_handwritten_pages (kk, descriptive only)"] = {"label_provenance": lab[kz[0]]["verdict"], "use": "DESCRIPTIVE ONLY", | |
| "pages": 150} | |
| info["rukopys_test"]["note"] = "Ukrainian (manifest lang 'other'): not a target language; crop/label alignment checked (checks.json rukopys_alignment)" | |
| X["set_info"] = info | |
| json.dump(X, open(os.path.join(TP, "per_language.json"), "w", encoding="utf-8"), indent=1, ensure_ascii=False) | |
| print("per_language.json written") | |