Download paper/aggregate.py from data-scale-paper/slt2026-code: direct link, hf CLI and curl.
- Browser
- Download file 32.1 kB
-
https://huggingface.co/datasets/data-scale-paper/slt2026-code/resolve/main/paper/aggregate.py
- Command line
-
hf download hf://datasets/data-scale-paper/slt2026-code/paper/aggregate.py
-
curl -L -o aggregate.py https://huggingface.co/datasets/data-scale-paper/slt2026-code/resolve/main/paper/aggregate.py
32.1 kB
| #!/usr/bin/env python3 | |
| """Recompute every WER aggregate reported in the paper from a single | |
| JSON file of per-cell WERs (``wer_results.json``, shipped alongside | |
| this script). | |
| This script is self-contained: it reads only the per-cell WER values | |
| from the JSON and re-derives every table and figure number in the | |
| paper that depends on those WERs alone. Quantities that need inputs | |
| beyond the per-cell WER table -- the per-utterance paired-bootstrap | |
| significance markers in Table~\\ref{tab:main160}, or convergence-epoch | |
| counts taken from the training logs -- are out of scope here and are | |
| not recomputed. | |
| Each check below is keyed to a stable LaTeX ``\\label`` (its ``\\ref`` | |
| target), which does not change if the paper is reordered; the ``[N]`` | |
| markers are just this script's own output tags, not paper section | |
| numbers: | |
| [1] tab:main160 FLEURS WER (%) @ 160 ms, per-(lang, hours). | |
| [2] sec:hours intro seen / unseen group mean Δ trajectory. | |
| [3] tab:latency_effect mean EN-ML gap per (tier, hours), FLEURS. | |
| [4] tab:abs_wer mean ML-init absolute WER per (tier, hours). | |
| [5] tab:lst per-lang Δ + LST per hours; macro mean. | |
| [6] sec:from_pl HR-from-PL pivot vs direct ML, 160 ms. | |
| [7] sec:reinitjoint joiner-reinit Δ, 560 ms FLEURS/VP. | |
| [8] tab:quant INT4 vs FP32 @ 560 ms FLEURS, paired stats. | |
| [9] tab:5000h_es ES 5000h vs 2500h ML deltas, and ES 5000h | |
| vs Nemotron-3.5 ML (tab:supp:es5000h). | |
| [10] fig:gap_powerlaw fit Δ(h) = a·h^(-β) at 160 ms; | |
| language-bootstrap 95% CI on β; R². | |
| [11] tab:hybrid hybrid-encoder 100h/560ms FLEURS table. | |
| [12] tab:seed + sec:seed HR/PT main-grid seed deltas + 16-cell 100h | |
| re-run @ 560 ms (FLEURS + VP); IS-EN excursion. | |
| [13] streaming penalty per (tier, hours, init), FLEURS. | |
| [14] tab:per_dataset per-dataset 160 ms WER appendix. | |
| Usage: | |
| # with wer_results.json sitting next to this script: | |
| python3 aggregate.py | |
| # or pass an explicit path to a results JSON: | |
| python3 aggregate.py /path/to/wer_results.json | |
| """ | |
| from __future__ import annotations | |
| import json | |
| import statistics | |
| import sys | |
| from pathlib import Path | |
| HERE = Path(__file__).resolve().parent | |
| # Default to wer_results.json sitting next to this script; fall back to | |
| # the in-repository ``paper/`` layout when run from a full checkout. | |
| DEFAULT_JSON = next( | |
| (p for p in (HERE / "wer_results.json", | |
| HERE.parent / "paper" / "wer_results.json") | |
| if p.is_file()), | |
| HERE / "wer_results.json", | |
| ) | |
| LANGS = ["de", "es", "fr", "hr", "is", "nl", "pl", "pt"] | |
| SEEN = ["de", "es", "fr", "nl"] | |
| UNSEEN = ["pt", "hr", "is", "pl"] | |
| HOURS = ["100h", "250h", "500h", "1000h", "2500h"] | |
| TIERS = ["160ms", "560ms", "1120ms", "offline"] | |
| # --------------------------------------------------------------------------- | |
| # JSON helpers | |
| # --------------------------------------------------------------------------- | |
| def wer(d, lang, hours, init, tier, dataset): | |
| """Return the WER (float) at d[lang][hours][init][tier][dataset], or None.""" | |
| try: | |
| cell = d[lang][hours][init][tier][dataset] | |
| if isinstance(cell, dict): | |
| v = cell.get("wer") | |
| return float(v) if v is not None else None | |
| except (KeyError, TypeError): | |
| pass | |
| return None | |
| def delta(d, lang, hours, tier, dataset): | |
| """EN - ML WER gap; None if either side missing.""" | |
| ml = wer(d, lang, hours, "ml", tier, dataset) | |
| en = wer(d, lang, hours, "enc", tier, dataset) | |
| if ml is None or en is None: | |
| return None | |
| return en - ml | |
| def fmt(x, signed=False, w=7): | |
| if x is None: | |
| return f"{'--':>{w}s}" | |
| return f"{x:+{w}.2f}" if signed else f"{x:{w}.2f}" | |
| def mean(xs): | |
| xs = [x for x in xs if x is not None] | |
| return statistics.fmean(xs) if xs else None | |
| def hr(title): | |
| print() | |
| print("=" * 78) | |
| print(title) | |
| print("=" * 78) | |
| # --------------------------------------------------------------------------- | |
| # [1] Table :main160 — FLEURS WER (%) at 160 ms streaming, per-(lang, hours) | |
| # --------------------------------------------------------------------------- | |
| def t_main160(d): | |
| hr("[1] Table tab:main160 — FLEURS WER (%) @ 160 ms") | |
| head = "lang " + "".join(f"{h:>27s}" for h in HOURS) | |
| print(head) | |
| sub = " " + "".join(f"{'ml':>9s}{'enc':>9s}{'Δ':>9s}" for _ in HOURS) | |
| print(sub) | |
| for lang in LANGS: | |
| row = f"{lang.upper():<6s}" | |
| for h in HOURS: | |
| ml = wer(d, lang, h, "ml", "160ms", "fleurs") | |
| en = wer(d, lang, h, "enc", "160ms", "fleurs") | |
| dl = (en - ml) if (ml is not None and en is not None) else None | |
| row += fmt(ml, w=9) + fmt(en, w=9) + fmt(dl, signed=True, w=9) | |
| print(row) | |
| print("-" * len(head)) | |
| # macro means | |
| row = f"{'mean':<6s}" | |
| for h in HOURS: | |
| mls = [wer(d, l, h, "ml", "160ms", "fleurs") for l in LANGS] | |
| ens = [wer(d, l, h, "enc", "160ms", "fleurs") for l in LANGS] | |
| dls = [(e - m) for m, e in zip(mls, ens) if m is not None and e is not None] | |
| row += fmt(mean(mls), w=9) + fmt(mean(ens), w=9) \ | |
| + fmt(mean(dls) if dls else None, signed=True, w=9) | |
| print(row) | |
| n_per_h = {h: sum(1 for l in LANGS | |
| if wer(d, l, h, "ml", "160ms", "fleurs") is not None | |
| and wer(d, l, h, "enc", "160ms", "fleurs") is not None) | |
| for h in HOURS} | |
| print(" K per hours: " + ", ".join(f"{h}={n_per_h[h]}" for h in HOURS)) | |
| # --------------------------------------------------------------------------- | |
| # [2] sec:hours — seen / unseen group mean Δ trajectory, FLEURS @ 160 ms | |
| # --------------------------------------------------------------------------- | |
| def t_seen_unseen(d): | |
| hr("[2] sec:hours — seen vs unseen group mean Δ, FLEURS @ 160 ms") | |
| print(f" {'group':<10s}" + "".join(f"{h:>10s}" for h in HOURS)) | |
| for label, group in (("seen", SEEN), ("unseen", UNSEEN), ("all", LANGS)): | |
| row = f" {label:<10s}" | |
| for h in HOURS: | |
| dls = [delta(d, l, h, "160ms", "fleurs") for l in group] | |
| row += fmt(mean(dls), signed=True, w=10) | |
| print(row) | |
| # --------------------------------------------------------------------------- | |
| # [3] Table :latency_effect — mean EN-ML gap per (tier, hours), FLEURS | |
| # --------------------------------------------------------------------------- | |
| def t_latency_effect(d): | |
| hr("[3] Table tab:latency_effect — mean Δ (EN-ML) per (tier, hours), FLEURS") | |
| print(f" {'tier':<10s}" + "".join(f"{h:>10s}" for h in HOURS) | |
| + f"{'range':>10s}") | |
| per_h = {h: [] for h in HOURS} | |
| for tier in TIERS: | |
| row = f" {tier:<10s}" | |
| for h in HOURS: | |
| dls = [delta(d, l, h, tier, "fleurs") for l in LANGS] | |
| m = mean(dls) | |
| per_h[h].append(m) | |
| row += fmt(m, signed=True, w=10) | |
| print(row) | |
| # cross-tier range of mean Δ at each hours (paper sentence) | |
| print(f" {'tier-range':<10s}", end="") | |
| for h in HOURS: | |
| vs = [v for v in per_h[h] if v is not None] | |
| rng = max(vs) - min(vs) if vs else None | |
| print(fmt(rng, w=10), end="") | |
| print() | |
| # --------------------------------------------------------------------------- | |
| # [4] Table :abs_wer — mean ML-init absolute FLEURS WER per (tier, hours) | |
| # --------------------------------------------------------------------------- | |
| def t_abs_wer(d): | |
| hr("[4] Table tab:abs_wer — mean ML-init FLEURS WER (%) per (tier, hours)") | |
| print(f" {'tier':<10s}" + "".join(f"{h:>10s}" for h in HOURS)) | |
| for tier in TIERS: | |
| row = f" {tier:<10s}" | |
| for h in HOURS: | |
| mls = [wer(d, l, h, "ml", tier, "fleurs") for l in LANGS] | |
| row += fmt(mean(mls), w=10) | |
| print(row) | |
| # --------------------------------------------------------------------------- | |
| # [5] Table :lst — per-lang Δ + LST per hours; macro mean | |
| # LST(lang, h) = max_tier Δ_tier(lang, h) - min_tier Δ_tier(lang, h) | |
| # Δ(lang, h) = mean_tier Δ_tier(lang, h) | |
| # Both are taken over the THREE streaming tiers only (160/560/1120 ms); | |
| # offline is excluded by definition (eq. lst / Table tab:lst caption). | |
| # --------------------------------------------------------------------------- | |
| def t_lst(d): | |
| hr("[5] Table tab:lst — per-lang Δ , LST on FLEURS (per hours)") | |
| stream_tiers = ["160ms", "560ms", "1120ms"] # LST excludes offline | |
| h_show = ["100h", "250h", "500h", "1000h"] # paper omits 2500h here | |
| head = f" {'lang':<6s}" + "".join(f"{h:>20s}" for h in h_show) | |
| print(head) | |
| print(f" {'':<6s}" + "".join(f"{'Δ':>10s}{'LST':>10s}" for _ in h_show)) | |
| barD = {h: [] for h in h_show} | |
| lst = {h: [] for h in h_show} | |
| for lang in LANGS: | |
| row = f" {lang.upper():<6s}" | |
| for h in h_show: | |
| ds = [delta(d, lang, h, t, "fleurs") for t in stream_tiers] | |
| ds = [x for x in ds if x is not None] | |
| if not ds: | |
| row += fmt(None, w=10) + fmt(None, w=10); continue | |
| bd = sum(ds) / len(ds) | |
| ls = max(ds) - min(ds) | |
| barD[h].append(bd); lst[h].append(ls) | |
| row += fmt(bd, signed=True, w=10) + fmt(ls, w=10) | |
| print(row) | |
| print(" " + "-" * 76) | |
| row = f" {'mean':<6s}" | |
| for h in h_show: | |
| row += fmt(mean(barD[h]), signed=True, w=10) + fmt(mean(lst[h]), w=10) | |
| print(row) | |
| # --------------------------------------------------------------------------- | |
| # [6] Sec :from_pl — HR-from-PL pivot vs direct ML, 160 ms FLEURS/VP | |
| # --------------------------------------------------------------------------- | |
| def t_from_pl(d): | |
| hr("[6] Sec sec:from_pl — HR PL-pivot vs direct ML (160 ms)") | |
| rows = ["100h", "250h", "500h", "1000h"] | |
| print(f" {'hours':<6s}{'direct ml FL':>14s}{'pivot ml FL':>14s}{'Δ FL':>8s}" | |
| f"{'direct ml VP':>14s}{'pivot ml VP':>14s}{'Δ VP':>8s}") | |
| for h in rows: | |
| dml_fl = wer(d, "hr", h, "ml", "160ms", "fleurs") | |
| piv_fl = wer(d, "hr", h, "from_pl_ml", "160ms", "fleurs") | |
| dml_vp = wer(d, "hr", h, "ml", "160ms", "voxpopuli") | |
| piv_vp = wer(d, "hr", h, "from_pl_ml", "160ms", "voxpopuli") | |
| dfl = (piv_fl - dml_fl) if (dml_fl is not None and piv_fl is not None) else None | |
| dvp = (piv_vp - dml_vp) if (dml_vp is not None and piv_vp is not None) else None | |
| print(f" {h:<6s}{fmt(dml_fl,w=14)}{fmt(piv_fl,w=14)}{fmt(dfl,signed=True,w=8)}" | |
| f"{fmt(dml_vp,w=14)}{fmt(piv_vp,w=14)}{fmt(dvp,signed=True,w=8)}") | |
| # PL(EN) pivot only at 100h | |
| piv_en_fl = wer(d, "hr", "100h", "from_pl_enc", "160ms", "fleurs") | |
| den_fl = wer(d, "hr", "100h", "enc", "160ms", "fleurs") | |
| if piv_en_fl is not None and den_fl is not None: | |
| print(f" PL(EN) pivot @100h FLEURS: direct enc={den_fl:.2f} " | |
| f"pivot={piv_en_fl:.2f} Δ={piv_en_fl - den_fl:+.2f} pp") | |
| # --------------------------------------------------------------------------- | |
| # [7] Sec :reinitjoint — joiner re-init Δ at 100 h, 560 ms FLEURS/VP | |
| # --------------------------------------------------------------------------- | |
| def t_reinitjoint(d): | |
| hr("[7] Sec sec:reinitjoint — joiner-reinit Δ vs baseline @ 100h, 560 ms") | |
| deltas_fl = {"ml": [], "enc": []} | |
| deltas_vp = {"ml": [], "enc": []} | |
| rows = [] | |
| for lang in LANGS: | |
| for init in ("ml", "enc"): | |
| base_fl = wer(d, lang, "100h", init, "560ms", "fleurs") | |
| rj_fl = wer(d, lang, "100h", f"{init}_reinitjoint", "560ms", "fleurs") | |
| base_vp = wer(d, lang, "100h", init, "560ms", "voxpopuli") | |
| rj_vp = wer(d, lang, "100h", f"{init}_reinitjoint", "560ms", "voxpopuli") | |
| dfl = (rj_fl - base_fl) if (base_fl is not None and rj_fl is not None) else None | |
| dvp = (rj_vp - base_vp) if (base_vp is not None and rj_vp is not None) else None | |
| if dfl is not None: deltas_fl[init].append(dfl) | |
| if dvp is not None: deltas_vp[init].append(dvp) | |
| rows.append((lang, init, dfl, dvp)) | |
| if not (deltas_fl["ml"] or deltas_fl["enc"]): | |
| print(" (no reinitjoint cells found in JSON)") | |
| return | |
| print(f" {'lang':<4s} {'init':<4s} {'Δ FL':>8s} {'Δ VP':>8s}") | |
| for lang, init, dfl, dvp in rows: | |
| print(f" {lang:<4s} {init:<4s} {fmt(dfl,signed=True,w=8)} {fmt(dvp,signed=True,w=8)}") | |
| all_fl = deltas_fl["ml"] + deltas_fl["enc"] | |
| all_vp = deltas_vp["ml"] + deltas_vp["enc"] | |
| hurt_fl = sum(1 for x in all_fl if x > 0) | |
| hurt_vp = sum(1 for x in all_vp if x > 0) | |
| print(f"\n mean Δ FL (all 16): {mean(all_fl):+0.2f} pp ({hurt_fl}/{len(all_fl)} hurt)") | |
| print(f" mean Δ FL (ml arm): {mean(deltas_fl['ml']):+0.2f} pp") | |
| print(f" mean Δ FL (enc arm):{mean(deltas_fl['enc']):+0.2f} pp") | |
| print(f" mean Δ VP (all): {mean(all_vp):+0.2f} pp ({hurt_vp}/{len(all_vp)} hurt)") | |
| print(f" mean Δ VP (ml arm): {mean(deltas_vp['ml']):+0.2f} pp") | |
| print(f" mean Δ VP (enc arm):{mean(deltas_vp['enc']):+0.2f} pp") | |
| if deltas_fl["enc"] and deltas_fl["ml"]: | |
| worst_enc = max(rows, key=lambda r: r[2] if r[1] == "enc" and r[2] is not None else -1) | |
| worst_ml = max(rows, key=lambda r: r[2] if r[1] == "ml" and r[2] is not None else -1) | |
| print(f" worst Δ FL enc: {worst_enc[0]}-{worst_enc[1]} {worst_enc[2]:+0.2f}") | |
| print(f" worst Δ FL ml: {worst_ml[0]}-{worst_ml[1]} {worst_ml[2]:+0.2f}") | |
| # --------------------------------------------------------------------------- | |
| # [8] Table :quant — INT4 vs FP32 @ 560 ms FLEURS | |
| # --------------------------------------------------------------------------- | |
| def t_quant(d): | |
| hr("[8] Table tab:quant — INT4 vs FP32 @ 560 ms FLEURS") | |
| rows = {h: {"ml": [], "enc": []} for h in HOURS} | |
| all_cells = [] # (lang, hours, init, Δ_int4-fp32) | |
| paired = [] # (lang, hours, Δ_ml, Δ_enc) | |
| for h in HOURS: | |
| per_lang_paired = {} | |
| for lang in LANGS: | |
| for init in ("ml", "enc"): | |
| i4 = wer(d, lang, h, init, "560ms", "fleurs_int4") | |
| f3 = wer(d, lang, h, init, "560ms", "fleurs_fp32") | |
| if i4 is None or f3 is None: | |
| continue | |
| dq = i4 - f3 | |
| rows[h][init].append(dq) | |
| all_cells.append((lang, h, init, dq)) | |
| per_lang_paired.setdefault(lang, {})[init] = dq | |
| for lang, cells in per_lang_paired.items(): | |
| if "ml" in cells and "enc" in cells: | |
| paired.append((lang, h, cells["ml"], cells["enc"])) | |
| print(f" {'hours':<6s}{'Δ_ml':>9s}{'n_ml':>6s}{'Δ_enc':>9s}{'n_enc':>6s}") | |
| for h in HOURS: | |
| ml = rows[h]["ml"]; en = rows[h]["enc"] | |
| print(f" {h:<6s}{fmt(mean(ml),signed=True,w=9)}{len(ml):>6d}" | |
| f"{fmt(mean(en),signed=True,w=9)}{len(en):>6d}") | |
| # pooled stats over all (lang, hours, init) | |
| dq_all = [c[3] for c in all_cells] | |
| if dq_all: | |
| dq_sorted = sorted(dq_all) | |
| med = statistics.median(dq_sorted) | |
| n = len(dq_all) | |
| within05 = sum(1 for x in dq_all if abs(x) <= 0.5) | |
| within10 = sum(1 for x in dq_all if abs(x) <= 1.0) | |
| worse = sum(1 for x in dq_all if x > 0) | |
| better = sum(1 for x in dq_all if x < 0) | |
| print() | |
| print(f" pooled (n={n}): mean={mean(dq_all):+0.2f} median={med:+0.2f}" | |
| f" range=[{min(dq_all):+0.2f},{max(dq_all):+0.2f}]") | |
| print(f" |Δ| ≤ 0.5 pp: {within05}/{n} |Δ| ≤ 1.0 pp: {within10}/{n}") | |
| print(f" INT4 worse than FP32: {worse}/{n} INT4 better: {better}/{n}") | |
| # paired ML vs EN quant cost | |
| if paired: | |
| diffs = [p[3] - p[2] for p in paired] # Δ_enc - Δ_ml | |
| enc_costlier = sum(1 for x in diffs if x > 0) | |
| print(f"\n paired ML vs EN (same lang, same hours, n={len(paired)}):") | |
| print(f" mean (Δ_enc - Δ_ml) = {mean(diffs):+0.2f} pp") | |
| print(f" EN costlier than ML in {enc_costlier}/{len(paired)} cells") | |
| print(f" range = [{min(diffs):+0.2f}, {max(diffs):+0.2f}] pp") | |
| # 100h breakdown (paper says 'weakest at 100h, EN costlier in 5 of 8') | |
| for h in HOURS: | |
| sub = [(p[2], p[3]) for p in paired if p[1] == h] | |
| if not sub: | |
| continue | |
| sub_diffs = [b - a for a, b in sub] | |
| print(f" {h}: paired n={len(sub)} mean Δ_enc-Δ_ml={mean(sub_diffs):+0.2f}" | |
| f" EN costlier in {sum(1 for x in sub_diffs if x > 0)}/{len(sub)}") | |
| # --------------------------------------------------------------------------- | |
| # [9] ES 5000h ML deltas vs ES 2500h ML (tab:5000h_es), plus ES 5000h ML | |
| # vs the Nemotron-3.5 ML baseline (tab:supp:es5000h); all four test | |
| # sets, 560 ms streaming. | |
| # --------------------------------------------------------------------------- | |
| def t_es_5000h(d): | |
| if "5000h" not in d.get("es", {}): | |
| return | |
| hr("[9] Sec sec:hours — ES 5000h vs 2500h ML, 560 ms streaming") | |
| for dataset in ("fleurs", "cv", "mls", "voxpopuli"): | |
| a = wer(d, "es", "5000h", "ml", "560ms", dataset) | |
| b = wer(d, "es", "2500h", "ml", "560ms", dataset) | |
| delta_ = (a - b) if (a is not None and b is not None) else None | |
| print(f" {dataset:<10s} 5000h={fmt(a)} 2500h={fmt(b)}" | |
| f" Δ={fmt(delta_, signed=True)}") | |
| # tab:supp:es5000h — ES 5000h (ML) vs contemporaneous Nemotron-3.5 ML | |
| # baseline, 560 ms streaming. Δ = WER_5000h − WER_Nemotron (negative: | |
| # our 5000h model better). | |
| if "nvidia-nemotron-3.5-asr" in d.get("es", {}).get("5000h", {}): | |
| print(" -- tab:supp:es5000h — ES 5000h (ML) vs Nemotron-3.5 ML:") | |
| for dataset in ("fleurs", "cv", "mls", "voxpopuli"): | |
| a = wer(d, "es", "5000h", "ml", "560ms", dataset) | |
| n = wer(d, "es", "5000h", "nvidia-nemotron-3.5-asr", "560ms", dataset) | |
| delta_ = (a - n) if (a is not None and n is not None) else None | |
| print(f" {dataset:<10s} 5000h={fmt(a)} nemotron={fmt(n)}" | |
| f" Δ={fmt(delta_, signed=True)}") | |
| # --------------------------------------------------------------------------- | |
| # [10] fig:gap_powerlaw — fit Δ(h) = a · h^(-β) on the 160 ms macro means | |
| # with a language-bootstrap 95% CI on β. | |
| # --------------------------------------------------------------------------- | |
| def t_powerlaw(d, B=10000, seed=0): | |
| hr("[10] fig:gap_powerlaw — transfer-gap power-law fit (160 ms FLEURS)") | |
| import math | |
| import random as _rand | |
| rng = _rand.Random(seed) | |
| hours_int = [int(h[:-1]) for h in HOURS] | |
| def fit(deltas_by_h): | |
| """Return (β, log_a, R²) from least-squares fit on log(h) vs log(Δ) | |
| across hours where Δ > 0 (so log is defined).""" | |
| xs, ys = [], [] | |
| for h, dl in zip(hours_int, deltas_by_h): | |
| if dl is None or dl <= 0: | |
| continue | |
| xs.append(math.log(h)); ys.append(math.log(dl)) | |
| if len(xs) < 2: | |
| return None, None, None | |
| n = len(xs) | |
| mx = sum(xs)/n; my = sum(ys)/n | |
| sxy = sum((x-mx)*(y-my) for x, y in zip(xs, ys)) | |
| sxx = sum((x-mx)**2 for x in xs) | |
| if sxx == 0: | |
| return None, None, None | |
| slope = sxy / sxx # = -β | |
| intercept = my - slope * mx | |
| beta = -slope | |
| # R² | |
| syy = sum((y-my)**2 for y in ys) | |
| if syy == 0: | |
| r2 = 1.0 | |
| else: | |
| ss_res = sum((y - (slope*x + intercept))**2 for x, y in zip(xs, ys)) | |
| r2 = 1 - ss_res/syy | |
| return beta, intercept, r2 | |
| # point estimate from the full 8-lang macro means | |
| macro = [mean([delta(d, l, h, "160ms", "fleurs") for l in LANGS]) for h in HOURS] | |
| beta, log_a, r2 = fit(macro) | |
| if beta is None: | |
| print(" (insufficient points for power-law fit)") | |
| return | |
| print(f" hours mean Δ (160 ms FLEURS)") | |
| for h, m in zip(HOURS, macro): | |
| print(f" {h:<8s} {fmt(m, signed=True)}") | |
| print(f"\n β_TG = {beta:.3f} R² = {r2:.4f} " | |
| f"(fit on log Δ vs log h, where Δ>0)") | |
| # language-bootstrap CI: resample 8 languages with replacement, recompute | |
| # macro means per hours, refit, collect β. | |
| betas = [] | |
| n_lang = len(LANGS) | |
| for _ in range(B): | |
| sample = [LANGS[rng.randrange(n_lang)] for _ in range(n_lang)] | |
| ms = [mean([delta(d, l, h, "160ms", "fleurs") for l in sample]) for h in HOURS] | |
| b, _, _ = fit(ms) | |
| if b is not None and math.isfinite(b): | |
| betas.append(b) | |
| if betas: | |
| betas.sort() | |
| lo = betas[int(0.025 * len(betas))] | |
| hi = betas[int(0.975 * len(betas))] | |
| frac_below = sum(1 for b in betas if b < 0.5) / len(betas) | |
| print(f" language-bootstrap 95% CI on β (B={B}): [{lo:.2f}, {hi:.2f}]") | |
| print(f" P(β < 0.5) = {frac_below:.4f} ({100 * frac_below:.2f}%)") | |
| # off-tier residuals (paper Fig. fig:gap_powerlaw caption: 0.23/0.29/0.13 pp) | |
| import math as _m | |
| print("\n Off-tier residuals against the 160 ms-fitted curve:") | |
| for tier in ("560ms", "1120ms", "offline"): | |
| mac = [mean([delta(d, l, h, tier, "fleurs") for l in LANGS]) for h in HOURS] | |
| res = [] | |
| for h, m in zip(hours_int, mac): | |
| if m is None or m <= 0: | |
| continue | |
| pred = _m.exp(log_a + (-beta) * _m.log(h)) | |
| res.append((m - pred) ** 2) | |
| if res: | |
| rms = (sum(res) / len(res)) ** 0.5 | |
| print(f" {tier:<8s} RMS={rms:.2f} pp (n={len(res)})") | |
| # --------------------------------------------------------------------------- | |
| # [11] tab:hybrid — hybrid-encoder, 100h training, 560 ms FLEURS | |
| # Splices: hybrid_0to12 / hybrid_last / hybrid_first / hybrid_middle | |
| # Reference rows are seed-45 ml / enc (paper: same common seed). | |
| # --------------------------------------------------------------------------- | |
| def t_hybrid(d): | |
| hr("[11] tab:hybrid — hybrid encoder @ 100h, 560 ms FLEURS") | |
| rows = [ | |
| ("ML (s45)", "ml_s45"), | |
| ("0:12", "hybrid_0to12"), | |
| ("last", "hybrid_last"), | |
| ("first", "hybrid_first"), | |
| ("middle", "hybrid_middle"), | |
| ("EN (s45)", "enc_s45"), | |
| ] | |
| # header | |
| print(f" {'row':<10s}" + "".join(f"{l.upper():>7s}" for l in LANGS) | |
| + f"{'mean':>9s}{'Δ vs ML':>10s}") | |
| ml_row = None | |
| table = [] | |
| for label, init in rows: | |
| cells = [wer(d, l, "100h", init, "560ms", "fleurs") for l in LANGS] | |
| mn = mean(cells) | |
| table.append((label, init, cells, mn)) | |
| if init == "ml_s45": | |
| ml_row = cells | |
| for label, init, cells, mn in table: | |
| if ml_row is None or any(c is None for c in cells) or any(m is None for m in ml_row): | |
| d_vs_ml = None | |
| else: | |
| pairwise = [c - m for c, m in zip(cells, ml_row)] | |
| d_vs_ml = sum(pairwise) / len(pairwise) | |
| row = f" {label:<10s}" + "".join(fmt(c, w=7) for c in cells) + fmt(mn, w=9) | |
| row += fmt(d_vs_ml, signed=True, w=10) if d_vs_ml is not None else f"{'--':>10s}" | |
| print(row) | |
| # seen / unseen group means | |
| print("\n group means:") | |
| for label, init, cells, _ in table: | |
| seen_m = mean([wer(d, l, "100h", init, "560ms", "fleurs") for l in SEEN]) | |
| unseen_m = mean([wer(d, l, "100h", init, "560ms", "fleurs") for l in UNSEEN]) | |
| print(f" {label:<10s} seen={fmt(seen_m, w=7)} unseen={fmt(unseen_m, w=7)}") | |
| # --------------------------------------------------------------------------- | |
| # [12] tab:seed + sec:seed — seed comparison | |
| # (a) HR/PT main-grid 160 ms FLEURS + VP, default seed vs seed 45 | |
| # (b) 16-cell 100h re-run @ 560 ms across all 8 langs × 2 inits; | |
| # stats: mean |Δ|, median, max on FLEURS and VP | |
| # (c) HR-100h FLEURS swing collapse at 560 ms | |
| # (d) Largest seed-induced EN-ML gap excursion (IS at 100h) | |
| # --------------------------------------------------------------------------- | |
| def t_seed(d): | |
| hr("[12] tab:seed + sec:seed — seed-default vs seed-45") | |
| # (a) HR / PT main grid at 160 ms FLEURS + VP | |
| print(" (a) HR / PT main-grid FLEURS@160ms and VP@160ms seed deltas:") | |
| print(f" {'lang':<4s}{'init':<5s}{'hours':<6s}" | |
| f"{'FL_s1':>8s}{'FL_s2':>8s}{'ΔFL':>8s}" | |
| f"{'VP_s1':>8s}{'VP_s2':>8s}{'ΔVP':>8s}") | |
| fl_abs, vp_abs = [], [] | |
| rows = [] | |
| for lang in ("hr", "pt"): | |
| for init in ("ml", "enc"): | |
| for h in HOURS: | |
| a_fl = wer(d, lang, h, init, "160ms", "fleurs") | |
| b_fl = wer(d, lang, h, init+"_s45","160ms", "fleurs") | |
| a_vp = wer(d, lang, h, init, "160ms", "voxpopuli") | |
| b_vp = wer(d, lang, h, init+"_s45","160ms", "voxpopuli") | |
| if a_fl is None or b_fl is None: | |
| continue | |
| dfl = b_fl - a_fl | |
| dvp = (b_vp - a_vp) if (a_vp is not None and b_vp is not None) else None | |
| fl_abs.append(abs(dfl)) | |
| if dvp is not None: vp_abs.append(abs(dvp)) | |
| rows.append((lang, init, h, dfl, dvp)) | |
| print(f" {lang:<4s}{init:<5s}{h:<6s}" | |
| f"{a_fl:>8.2f}{b_fl:>8.2f}{dfl:>+8.2f}" | |
| f"{fmt(a_vp,w=8)}{fmt(b_vp,w=8)}{fmt(dvp,signed=True,w=8)}") | |
| if fl_abs: | |
| print(f"\n mean |ΔFL| = {sum(fl_abs)/len(fl_abs):.2f} pp" | |
| f" (n={len(fl_abs)}, max={max(fl_abs):.2f})") | |
| if vp_abs: | |
| print(f" mean |ΔVP| = {sum(vp_abs)/len(vp_abs):.2f} pp" | |
| f" (n={len(vp_abs)}, max={max(vp_abs):.2f})") | |
| # (b) 16-cell 100h re-run @ 560 ms (all 8 langs × 2 inits) | |
| print("\n (b) 100h × 8 langs × 2 inits @ 560 ms (FLEURS, VP):") | |
| fl, vp = [], [] | |
| cells_fl, cells_vp = [], [] | |
| for lang in LANGS: | |
| for init in ("ml", "enc"): | |
| a_fl = wer(d, lang, "100h", init, "560ms", "fleurs") | |
| b_fl = wer(d, lang, "100h", init+"_s45", "560ms", "fleurs") | |
| a_vp = wer(d, lang, "100h", init, "560ms", "voxpopuli") | |
| b_vp = wer(d, lang, "100h", init+"_s45", "560ms", "voxpopuli") | |
| if a_fl is not None and b_fl is not None: | |
| fl.append(abs(b_fl - a_fl)) | |
| cells_fl.append((lang, init, b_fl - a_fl)) | |
| if a_vp is not None and b_vp is not None: | |
| vp.append(abs(b_vp - a_vp)) | |
| cells_vp.append((lang, init, b_vp - a_vp)) | |
| if fl: | |
| s = sorted(fl) | |
| worst = max(cells_fl, key=lambda x: abs(x[2])) | |
| print(f" FLEURS: mean |Δ|={sum(fl)/len(fl):.2f} median={s[len(s)//2]:.2f}" | |
| f" max={max(fl):.2f} ({worst[0]}-{worst[1]}) n={len(fl)}") | |
| if vp: | |
| s = sorted(vp) | |
| worst = max(cells_vp, key=lambda x: abs(x[2])) | |
| print(f" VoxPopuli: mean |Δ|={sum(vp)/len(vp):.2f} median={s[len(s)//2]:.2f}" | |
| f" max={max(vp):.2f} ({worst[0]}-{worst[1]}) n={len(vp)}") | |
| # (c) HR-100h FLEURS swing collapse at 560 ms vs 160 ms | |
| print("\n (c) HR-100h FLEURS seed swing collapse 160 ms → 560 ms:") | |
| for init in ("ml", "enc"): | |
| for tier in ("160ms", "560ms"): | |
| a = wer(d, "hr", "100h", init, tier, "fleurs") | |
| b = wer(d, "hr", "100h", init+"_s45", tier, "fleurs") | |
| if a is not None and b is not None: | |
| print(f" hr-{init:<3s} @ {tier:<6s}: s1={a:.2f} s2={b:.2f} Δ={b-a:+.2f}") | |
| # (d) Largest seed-induced EN-ML gap excursion at 100h / 560 ms | |
| print("\n (d) Seed-induced EN-ML gap excursion at 100h / 560 ms FLEURS:") | |
| print(f" {'lang':<4s}{'Δ(s1)':>10s}{'Δ(s2)':>10s}{'shift':>10s}{'sign?':>8s}") | |
| biggest = (None, 0.0) | |
| for lang in LANGS: | |
| ml1 = wer(d, lang, "100h", "ml", "560ms", "fleurs") | |
| en1 = wer(d, lang, "100h", "enc", "560ms", "fleurs") | |
| ml2 = wer(d, lang, "100h", "ml_s45", "560ms", "fleurs") | |
| en2 = wer(d, lang, "100h", "enc_s45", "560ms", "fleurs") | |
| if any(x is None for x in (ml1, en1, ml2, en2)): | |
| continue | |
| d1 = en1 - ml1; d2 = en2 - ml2 | |
| sign_keep = "yes" if (d1 >= 0) == (d2 >= 0) else "NO" | |
| shift = d2 - d1 | |
| print(f" {lang:<4s}{d1:>+10.2f}{d2:>+10.2f}{shift:>+10.2f}{sign_keep:>8s}") | |
| if abs(shift) > abs(biggest[1]): | |
| biggest = (lang, shift) | |
| if biggest[0]: | |
| print(f" largest shift: {biggest[0]} ({biggest[1]:+.2f} pp)") | |
| # --------------------------------------------------------------------------- | |
| # [13] Streaming penalty per (tier, hours, init) on FLEURS | |
| # penalty = WER(tier) - WER(offline) | |
| # --------------------------------------------------------------------------- | |
| def t_streaming_penalty(d): | |
| hr("[13] Streaming penalty (FLEURS): WER(tier) - WER(offline)") | |
| print(f" {'init':<5s}{'tier':<10s}" + "".join(f"{h:>10s}" for h in HOURS)) | |
| for init in ("ml", "enc"): | |
| for tier in ("160ms", "560ms", "1120ms"): | |
| row = f" {init:<5s}{tier:<10s}" | |
| for h in HOURS: | |
| tier_wers = [wer(d, l, h, init, tier, "fleurs") for l in LANGS] | |
| off_wers = [wer(d, l, h, init, "offline", "fleurs") for l in LANGS] | |
| pairs = [(t - o) for t, o in zip(tier_wers, off_wers) | |
| if t is not None and o is not None] | |
| m = mean(pairs) | |
| row += fmt(m, signed=True, w=10) | |
| print(row) | |
| # --------------------------------------------------------------------------- | |
| # [14] tab:per_dataset — 160 ms WER per (lang, hours, init, dataset) | |
| # --------------------------------------------------------------------------- | |
| def t_per_dataset(d): | |
| hr("[14] tab:per_dataset — 160 ms WER per (lang, hours, init, dataset)") | |
| datasets = ("cv", "mls", "voxpopuli", "fleurs") | |
| print(f" {'lang':<5s}{'hours':<7s}" | |
| + "".join(f"{ds.upper() + ' ml':>10s}{ds.upper() + ' en':>10s}" | |
| for ds in datasets)) | |
| for lang in LANGS: | |
| for h in HOURS: | |
| row = f" {lang:<5s}{h:<7s}" | |
| for ds in datasets: | |
| ml = wer(d, lang, h, "ml", "160ms", ds) | |
| en = wer(d, lang, h, "enc", "160ms", ds) | |
| row += fmt(ml, w=10) + fmt(en, w=10) | |
| print(row) | |
| # --------------------------------------------------------------------------- | |
| # main | |
| # --------------------------------------------------------------------------- | |
| def main(argv): | |
| src = Path(argv[1]) if len(argv) > 1 else DEFAULT_JSON | |
| if not src.is_file(): | |
| print(f"error: results file not found: {src}\n" | |
| f" pass the path to wer_results.json as the first argument.", | |
| file=sys.stderr) | |
| return 2 | |
| d = json.loads(src.read_text()) | |
| print(f"Reading {src}") | |
| t_main160(d) | |
| t_seen_unseen(d) | |
| t_latency_effect(d) | |
| t_abs_wer(d) | |
| t_lst(d) | |
| t_from_pl(d) | |
| t_reinitjoint(d) | |
| t_quant(d) | |
| t_es_5000h(d) | |
| t_powerlaw(d) | |
| t_hybrid(d) | |
| t_seed(d) | |
| t_streaming_penalty(d) | |
| t_per_dataset(d) | |
| return 0 | |
| if __name__ == "__main__": | |
| sys.exit(main(sys.argv)) | |