Download scripts/r5_testpass2/tp2_az_latin_pair.py from treoa/turkic-ocr-code: direct link, hf CLI and curl.
- Browser
- Download file 2.12 kB
-
https://huggingface.co/treoa/turkic-ocr-code/resolve/main/scripts/r5_testpass2/tp2_az_latin_pair.py
- Command line
-
hf download hf://treoa/turkic-ocr-code/scripts/r5_testpass2/tp2_az_latin_pair.py
-
curl -L -o tp2_az_latin_pair.py https://huggingface.co/treoa/turkic-ocr-code/resolve/main/scripts/r5_testpass2/tp2_az_latin_pair.py
2.12 kB
| """Amendment 6: CER with interval of M1 Latin-only vs M1 unconstrained on az_localdoc_test (same 442 rows), paired source-page bootstrap | |
| (r5eval.stats.paired_ratio_difference, B 10000, seed 20261121) from the scorer's per-cluster sums. Aggregates only. | |
| usage: tp2_az_latin_pair.py LATIN_SCORE_JSON M1_SCORE_JSON SCRIPT_JSON OUT_JSON | |
| """ | |
| import json | |
| import sys | |
| sys.path.insert(0, "/path/to/TURKIC_OCR_CODE/src") | |
| from r5eval import stats # noqa: E402 | |
| L, M, SC, OUT = sys.argv[1:5] | |
| dl, dm = json.load(open(L, encoding="utf-8")), json.load(open(M, encoding="utf-8")) | |
| pl, pm = dl["profiles"]["plain"], dm["profiles"]["plain"] | |
| assert pl["cluster_ids"] == pm["cluster_ids"] | |
| pr = stats.paired_ratio_difference(pl["cluster_sums"]["all"]["dist"], pl["cluster_sums"]["all"]["ref_len"], | |
| pm["cluster_sums"]["all"]["dist"], pm["cluster_sums"]["all"]["ref_len"]) | |
| pr.pop("_rel_reps", None) | |
| g = lambda d, k: {x: d["profiles"]["plain"]["groups"]["all"]["metrics"][k].get(x) for x in ("value", "lo", "hi", "num", "den")} # noqa: E731 | |
| res = {"note": "plan amendment 6 of 26 Nov (plan entry n 7): M1 with Latin-only decoding vs M1 unconstrained (test pass 2), all 442 lines; descriptive", | |
| "n": dl["set_info"]["n_scored"], "coverage_complete": dl["coverage"]["complete"], | |
| "latin_only": {k: g(dl, k) for k in ("cer", "wer", "exact_match", "hr3", "hr4", "fabricated_word_rate", "empty_output_rate")}, | |
| "unconstrained": {k: g(dm, k) for k in ("cer", "wer", "exact_match", "hr3", "hr4", "fabricated_word_rate", "empty_output_rate")}, | |
| "paired_latin_only_minus_unconstrained": pr, "script_and_edit_types_latin_only": json.load(open(SC, encoding="utf-8")), | |
| "latin_only_pred_sha256": dl["inputs"]["pred_sha256"], "unconstrained_pred_sha256": dm["inputs"]["pred_sha256"]} | |
| json.dump(res, open(OUT, "w", encoding="utf-8"), indent=1, ensure_ascii=False) | |
| print(json.dumps({"latin_cer": res["latin_only"]["cer"], "m1_cer": res["unconstrained"]["cer"]["value"], "d_abs": pr["d_abs"], "d_abs_ci": pr["d_abs_ci95"], | |
| "d_rel": pr["d_rel"], "d_rel_ci": pr["d_rel_ci95"]})) | |