Datasets:
v1.1: MinerU block boxes from middle_json; weights kostat .18, tables .12, order .05, grid .02
c949561 verified Download code/koocr_total.py from schift-io/KoOCR-Bench: direct link, hf CLI and curl.
- Browser
- Download file 3 kB
-
https://huggingface.co/datasets/schift-io/KoOCR-Bench/resolve/main/code/koocr_total.py
- Command line
-
hf download hf://datasets/schift-io/KoOCR-Bench/code/koocr_total.py
-
curl -L -o koocr_total.py https://huggingface.co/datasets/schift-io/KoOCR-Bench/resolve/main/code/koocr_total.py
3 kB
| #!/usr/bin/env python3 | |
| """KoOCR-Bench v1 weighted total from koocr_score.py outputs. | |
| Usage: koocr_total.py [--bbox-override JSON] [--drop eng,eng] [--no-handwriting] SCORES.txt [SCORES2.txt ...] | |
| - Engines with several runs (name_r1, name_r2) are averaged as 'name'. | |
| - --bbox-override: {"engine": {"slice": rate}} for engines whose boxes come in a separate layout list (e.g. PaddleOCR-VL). | |
| - A component an engine has no value for is dropped for that engine and its weights renormalised (marked in the table). | |
| Higher is better everywhere: text slices use 1 - CER (CER = normalised edit distance + 2 x foreign-script chars not in | |
| the truth, capped at 1 per page), table slices use TEDS on HTML tables only.""" | |
| import json, re, sys, collections | |
| # v1.1 (2026-10-05): kostat .15->.18, tables .10->.12, order .08->.05, grid .03->.02; totals divide by the weight sum | |
| W = {"gwanbo": .15, "kostat": .18, "kdi": .12, "tables": .12, "handwriting": .10, "user": .10, | |
| "bbox": .08, "order": .05, "suneung": .05, "heading": .04, "grid": .02} | |
| a = sys.argv[1:]; ov = {}; drop = set() | |
| while a and a[0].startswith("--"): | |
| o = a.pop(0) | |
| if o == "--bbox-override": ov = json.load(open(a.pop(0))) | |
| elif o == "--drop": drop = set(a.pop(0).split(",")) | |
| elif o == "--no-handwriting": W.pop("handwriting") | |
| TXT = {"gwanbo_table": "gwanbo", "kdi_headings": "kdi", "suneung2026": "suneung", "user_real": "user", "handwritten": "handwriting"} | |
| v = collections.defaultdict(lambda: collections.defaultdict(list)) | |
| for f in a: | |
| for l in open(f): | |
| m = re.match(r"(\S+)\s+(\S+)\s+n=\s*(\d+)\s+missing=\d+\s+(.*)", l) | |
| if not m: continue | |
| sl, eng, n = m[1], re.sub(r"_r\d+$", "", m[2]), int(m[3]) | |
| if eng in drop: continue | |
| rest = dict(zip(*[iter(m[4].split())] * 2)); g = lambda k: float(rest[k]) | |
| if "cer" in rest and TXT[sl] in W: v[eng][TXT[sl]].append((1 - g("cer"), n)) | |
| if "teds" in rest: | |
| v[eng]["kostat" if sl == "kostat_wide" else "tables"].append((g("teds"), n)); v[eng]["grid"].append((g("grid_exact"), n)) | |
| if "heading_recall" in rest: v[eng]["heading"].append((g("heading_recall"), n)) | |
| if "order" in rest: v[eng]["order"].append((g("order"), n)) | |
| if sl == "handwritten" and "handwriting" not in W: continue | |
| if "bbox" in rest: v[eng]["bbox"].append((ov.get(eng, {}).get(sl, g("bbox")), n)) | |
| avg = lambda xs: sum(x * n for x, n in xs) / sum(n for x, n in xs) | |
| rows = [] | |
| for eng, c in v.items(): | |
| comp = {k: avg(x) for k, x in c.items() if k in W} | |
| ks = [k for k in W if k in comp] | |
| rows.append((sum(W[k] * comp[k] for k in ks) / sum(W[k] for k in ks), eng, comp, [k for k in W if k not in comp])) | |
| rows.sort(reverse=True) | |
| print("| rank | engine | total | " + " | ".join(W) + " |") | |
| print("|---|---|---|" + "---|" * len(W)) | |
| for i, (t, eng, comp, miss) in enumerate(rows, 1): | |
| print(f"| {i} | {eng}{' *' if miss else ''} | {t:.4f} | " + " | ".join(f"{comp[k]:.3f}" if k in comp else "–" for k in W) + " |") | |