duplex-v0 / tools /heard_accuracy.py
Jr23xd23's picture
RightNow Duplex v0
f730521 verified
Raw History Blame Contribute Delete
1.78 kB
"""How many answers are right as HEARD, not as written.
The benchmark arms are scored on the reply's text (eval/eval_bba.py). Here Whisper's transcript of the
reply's audio (eval/eval_wer.py, clips.json) is searched for the answer in the same way and compared
with the official answer. Whisper makes errors of its own, most of all on a lone short word, so this
is a lower bound on what a person would hear.
python -m tools.heard_accuracy eval/results/wer_answers/clips.json eval/results/bba3/reference_again/judge=eval/results/wer_answers/reference_again ...
"""
import json
import sys
from pathlib import Path
from eval.eval_bba import parse_answer
groups = json.loads(Path(sys.argv[1]).read_text(encoding="utf-8"))
print("| Arm | Replies with audio | Right in the text | Right as heard | Text right, not heard | Reply audio, median (s) |")
print("|---|---|---|---|---|---|")
for pair in sys.argv[2:]:
arm, key = pair.split("=")
heard = {c["clip"].replace(".wav", ""): " ".join(c["hyp"]) for c in groups[key]}
rows = [json.loads(p.read_text(encoding="utf-8")) for p in sorted(Path(arm).glob("q_*.json"))]
rows = [r for r in rows if f"q_{r['id']}" in heard]
ok_text = [r["correct"] for r in rows]
ok_heard = []
for r in rows:
answer, official = parse_answer(heard[f"q_{r['id']}"], r["official_answer"])
ok_heard.append(answer is not None and answer == official)
import wave
secs = []
for r in rows:
with wave.open(str(Path(arm) / f"q_{r['id']}.wav")) as w:
secs.append(w.getnframes() / w.getframerate())
secs.sort()
print(f"| {Path(arm).parent.name} | {len(rows)} | {sum(ok_text)} | {sum(ok_heard)} | {sum(t and not h for t, h in zip(ok_text, ok_heard))} | {secs[len(secs) // 2]:.2f} |")