| |
| """Chiffre EXACTEMENT ce que coûte l'absence de virgules (et d'apostrophes) dans nos sorties. |
| Méthode : comparer nos hypothèses aux références TELLES QUELLES, puis aux références PRIVÉES |
| de virgules. L'écart = le coût réel du déficit de ponctuation. Décide si ça vaut un effort. |
| Aucun GPU, aucune soumission. |
| """ |
| import json, os, re |
| import jiwer |
|
|
| AUD = "/root/devhard_audio" |
|
|
|
|
| def comb(refs, hyps): |
| pr = [(r, h) for r, h in zip(refs, hyps) if r.strip()] |
| a = [x for x, _ in pr]; b = [y for _, y in pr] |
| w = jiwer.wer(a, b); c = jiwer.cer(a, b) |
| return w, c, 0.5 * w + 0.5 * c |
|
|
|
|
| def main(): |
| |
| hyp_file = "/root/devhard_allhyps.json" |
| if not os.path.exists(hyp_file): |
| print("pas de cache d'hypotheses"); return |
| D = json.load(open(hyp_file, encoding="utf-8")) |
| rows = [json.loads(l) for l in open("/root/devhard/devhard_linsna.jsonl", encoding="utf-8")] |
|
|
| |
| if isinstance(D, dict): |
| keys = list(D.keys()) |
| print("cles disponibles dans devhard_allhyps.json :", keys[:8]) |
| for lg in ("lin", "sna"): |
| sub = [r for r in rows if r["lang"] == lg] |
| refs = [r["text"] for r in sub] |
| ids = [r["id"] for r in sub] |
| |
| hyps = None |
| if isinstance(D, dict): |
| for k in D: |
| v = D[k] |
| if isinstance(v, dict) and all(i in v for i in ids[:5]): |
| hyps = [v.get(i, "") for i in ids]; print(" -> hypotheses via '%s'" % k); break |
| if isinstance(v, list) and len(v) == len(rows): |
| pass |
| if hyps is None: |
| print("[%s] pas d'hypotheses appariables -> on mesure seulement les REFS" % lg) |
| nc = sum(t.count(",") for t in refs) |
| na = sum(t.count("'") for t in refs) |
| print(" refs : %d virgules, %d apostrophes sur %d phrases" % (nc, na, len(refs))) |
| continue |
| base = comb(refs, hyps) |
| nocom = comb([t.replace(",", "") for t in refs], [h.replace(",", "") for h in hyps]) |
| print("\n[%s] %d clips" % (lg, len(refs))) |
| print(" tel quel : WER %.4f CER %.4f combine %.4f" % base) |
| print(" refs+hyps SANS virgules : WER %.4f CER %.4f combine %.4f" % nocom) |
| print(" => COUT du deficit de virgules = %+.4f sur le combine %s" % (base[2] - nocom[2], lg)) |
|
|
|
|
| if __name__ == "__main__": |
| main() |
|
|