Download recipe/bench/aggregate.py from KaleComputer/kale-tts-1-tiny: direct link, hf CLI and curl.
- Browser
- Download file 7.02 kB
-
https://huggingface.co/KaleComputer/kale-tts-1-tiny/resolve/main/recipe/bench/aggregate.py
- Command line
-
hf download hf://KaleComputer/kale-tts-1-tiny/recipe/bench/aggregate.py
-
curl -L -o aggregate.py https://huggingface.co/KaleComputer/kale-tts-1-tiny/resolve/main/recipe/bench/aggregate.py
7.02 kB
| # SPDX-License-Identifier: Apache-2.0 | |
| # Copyright 2026 Kale | |
| """aggregate.py: per-line and overall numbers from the bench's raw clip measures (features(), see bench.py). Plain python3. | |
| Every voice is scored against ITS OWN Maya-1 takes of the same 192 lines (refs/features.jsonl in this folder's working copy). | |
| Maya's level: each of her reference takes against her OTHER takes of the same line. A model's render is measured the same way: | |
| against every all-but-one set of Maya's takes of the line, averaged (against_loo). Maya's tail figures are taken over her single takes. | |
| utmos / tail UTMOS mean; tail = "weakest tenth" = mean UTMOS of the worst 10 % of lines | |
| match voice match: mean ECAPA-TDNN cosine to Maya's takes of the line | |
| werr Whisper read-back word errors, % of words | |
| pitch / pitch_out pitch error per word (st outside the range of Maya's takes) / share of words > 0.5 st outside | |
| step pitch step error at commas and sentence ends (st outside the range of Maya's steps); secondary melody read, | |
| a flat averaged contour can score better than Maya herself (use melody_gap.py as the melody number) | |
| creak share of sentence ends with >= 100 ms of low-band sound without findable pitch | |
| pace_within3 share of lines whose words/min is within 3 % of Maya's median take of the line | |
| Trimmed copy of our night-bench aggregate.py: the leaderboard, headline figure, baseline-model rows and bootstrap verdicts are | |
| removed; the maths of load_refs / against / against_loo / summary / maya_level is unchanged. `mean` skips None values. | |
| """ | |
| import json, statistics as st, sys, time | |
| from pathlib import Path | |
| B = Path(__file__).resolve().parent | |
| FLOOR = dict(utmos=0.02, match=0.002, pitch=0.02, werr=0.1) | |
| med = lambda xs: st.median(xs) if xs else None | |
| mean = lambda xs: (lambda ys: sum(ys) / len(ys) if ys else None)([x for x in xs if x is not None]) # a line with no pitch measure (None) must not break the mean | |
| dot = lambda a, b: sum(x * y for x, y in zip(a, b)) | |
| def load_refs(): | |
| refs = {} | |
| for l in (B / "refs/features.jsonl").read_text().splitlines(): | |
| r = json.loads(l) | |
| if r.get("ok"): | |
| refs.setdefault(r["line"], []).append(r) | |
| return refs | |
| def against(c, others): | |
| """one clip against Maya's takes `others` of the same line -> per-line numbers.""" | |
| o = dict(utmos=c["utmos"], match=mean([dot(c["emb"], r["emb"]) for r in others]), errors=c["errors"], words=c["words"]) | |
| perr, pout, pn = [], 0, 0 | |
| for i, x in enumerate(c["word_st"]): | |
| vs = [r["word_st"][i] for r in others if i < len(r["word_st"]) and r["word_st"][i] is not None] | |
| if x is None or len(vs) < 2: | |
| continue | |
| e = max(0.0, min(vs) - x, x - max(vs)) | |
| perr.append(e); pn += 1; pout += e > 0.5 | |
| o.update(pitch=mean(perr), pitch_words=pn, pitch_out=pout) | |
| serr, sdet = [], [] | |
| for s in c["steps"]: | |
| vs = [t["st"] for r in others for t in r["steps"] if t["i"] == s["i"] and t["st"] is not None] | |
| if s["st"] is None or len(vs) < 2: | |
| continue | |
| e = max(0.0, min(vs) - s["st"], s["st"] - max(vs)) | |
| serr.append(e); sdet.append(dict(i=s["i"], kind=s["kind"], st=s["st"], maya=[round(min(vs), 2), round(max(vs), 2)], err=round(e, 2))) | |
| o.update(step=mean(serr), steps=len(serr), step_detail=sdet) | |
| o["ends"] = len(c["ends"]); o["creak"] = sum(e["rough_ms"] >= 100 for e in c["ends"]) | |
| m = med([r["wpm"] for r in others]) | |
| o["pace_ratio"] = c["wpm"] / m if m else None | |
| o["over"] = c["over_full_scale"]; o["lead_ms"] = c["lead_ms"]; o["first_sample"] = c["first_sample"] | |
| return o | |
| def against_loo(c, rs): | |
| """a candidate line against Maya's takes, measured the way Maya's own level is: against every set of all-but-one of her | |
| takes of that line, averaged (so a candidate is never compared with a wider range than Maya's own takes are).""" | |
| ps = [against(c, [x for x in rs if x is not r]) for r in rs] | |
| o = dict(ps[0]) | |
| for k in ("match", "pitch", "step", "pace_ratio"): | |
| v = [p[k] for p in ps if p[k] is not None] | |
| o[k] = mean(v) if v else None | |
| o["pitch_out"] = sum(p["pitch_out"] for p in ps) / len(ps) | |
| full = against(c, rs) # for the worst-case lists: every step against all of Maya's takes | |
| o["step_detail"] = full["step_detail"] | |
| return o | |
| def summary(per): | |
| """per: list of per-line dicts -> overall numbers.""" | |
| w = sum(p["words"] for p in per) | |
| pw = [(p["pitch"], p["pitch_words"]) for p in per if p["pitch"] is not None] | |
| sw = [(p["step"], p["steps"]) for p in per if p["step"] is not None] | |
| pr = [p["pace_ratio"] for p in per if p["pace_ratio"]] | |
| us = sorted(p["utmos"] for p in per) | |
| return dict(lines=len(per), utmos=mean([p["utmos"] for p in per]), utmos_low=min(p["utmos"] for p in per), | |
| tail=mean(us[:max(1, round(len(us) * 0.1))]), under4=100 * sum(u < 4.0 for u in us) / len(us), match=mean([p["match"] for p in per]), | |
| werr=100 * sum(p["errors"] for p in per) / max(1, w), lines_with_errors=sum(p["errors"] > 0 for p in per), | |
| pitch=sum(a * b for a, b in pw) / max(1, sum(b for _, b in pw)), pitch_out=100 * sum(p["pitch_out"] for p in per) / max(1, sum(p["pitch_words"] for p in per)), | |
| step=sum(a * b for a, b in sw) / max(1, sum(b for _, b in sw)), creak=100 * sum(p["creak"] for p in per) / max(1, sum(p["ends"] for p in per)), | |
| pace_within3=100 * sum(abs(x - 1) <= 0.03 for x in pr) / max(1, len(pr)), pace_median=med(pr), | |
| over=sum(p["over"] for p in per), clean_starts=100 * sum(p["lead_ms"] >= 5 and p["first_sample"] < 0.01 for p in per) / len(per)) | |
| def maya_level(refs): | |
| per = [] | |
| for line, rs in refs.items(): | |
| if len(rs) < 3: | |
| continue | |
| ps = [against(r, [x for x in rs if x is not r]) for r in rs] | |
| avg = lambda k: mean([p[k] for p in ps if p[k] is not None]) | |
| per.append(dict(utmos=avg("utmos"), match=avg("match"), errors=sum(p["errors"] for p in ps) / len(ps), words=ps[0]["words"], pitch=avg("pitch"), | |
| pitch_words=ps[0]["pitch_words"], pitch_out=sum(p["pitch_out"] for p in ps) / len(ps), step=avg("step"), steps=max(p["steps"] for p in ps), | |
| ends=ps[0]["ends"], creak=sum(p["creak"] for p in ps) / len(ps), pace_ratio=1.0, over=sum(p["over"] for p in ps), lead_ms=min(p["lead_ms"] for p in ps), | |
| first_sample=max(p["first_sample"] for p in ps), _pr=[p["pace_ratio"] for p in ps if p["pace_ratio"]])) | |
| s = summary(per) | |
| allpr = [x for p in per for x in p["_pr"]] | |
| s["pace_within3"] = 100 * sum(abs(x - 1) <= 0.03 for x in allpr) / max(1, len(allpr)) | |
| us = sorted(r["utmos"] for rs in refs.values() if len(rs) >= 3 for r in rs) # her single takes, as a candidate's single renders | |
| s["tail"] = mean(us[:max(1, round(len(us) * 0.1))]); s["under4"] = 100 * sum(u < 4.0 for u in us) / len(us) | |
| return s | |