File size: 2,122 Bytes
24aaa76
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
"""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"]}))