"""100 Big Bench Audio questions through the endpoint, with and without the controller. without endpointing "manual": the question is committed the instant its audio ends, so nothing but the model decides the answer. with endpointing "controller": the controller alone decides when to answer. If it starts early, the model answers a cut-off question and that shows up here. Scoring is ours, not Artificial Analysis's judge model: the reply text after the last "" is searched for the last valid/invalid, yes/no or number, and compared with the official answer. Scores are comparable between the two modes of this run, not with the public leaderboard. Raw replies (text and audio) are saved so they can be re-scored. python -m eval.eval_bba --data eval/data/bba --out eval/results/bba --modes manual,controller """ import argparse import asyncio import json import re from collections import defaultdict from pathlib import Path import aiohttp import numpy as np from duplex.spec import OUT_SR, write_json, write_wav from eval.ws_client import load_16k, open_session, percentiles, run_turn SYSTEM = ('Listen to the question and answer it. Reply with only "valid" or "invalid", "yes" or "no", ' "or a number. Do not add anything else.") # Third run: Whisper recognised only 71 of 94 one-word spoken answers (the model gives a lone word very little # audio, down to 0.16 s). "sentence" asks for the answer inside one short sentence instead. SYSTEMS = {"word": SYSTEM, "sentence": ('Listen to the question and answer it in one short spoken sentence that states the answer: "valid" or "invalid", ' '"yes" or "no", or the number. Do not add anything else.')} UNITS = "zero one two three four five six seven eight nine ten eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen".split() TENS = "twenty thirty forty fifty sixty seventy eighty ninety".split() # digits, "twenty", "twenty one" / "twenty-one", or a single word from zero to nineteen NUMBER = rf"\d+|(?:{'|'.join(TENS)})(?:[\s-](?:{'|'.join(UNITS[1:10])}))?|(?:{'|'.join(UNITS)})" def to_number(s): words = re.split(r"[\s-]+", s.strip().lower()) if len(words) == 1 and words[0].isdigit(): return int(words[0]) if len(words) == 1 and words[0] in UNITS: return UNITS.index(words[0]) if words[0] in TENS and (len(words) == 1 or (len(words) == 2 and words[1] in UNITS[1:10])): return 10 * (TENS.index(words[0]) + 2) + (UNITS.index(words[1]) if len(words) == 2 else 0) return None def parse_answer(text, official): """The last answer of the right kind in the spoken part of the reply, or None.""" say = re.sub(r"<[^>]+>", " ", text.split("")[-1]).lower() official = official.strip().lower() if official in ("valid", "invalid"): found = re.findall(r"\b(invalid|valid)\b", say) elif official in ("yes", "no"): found = re.findall(r"\b(yes|no)\b", say) else: found = [str(n) for n in (to_number(m) for m in re.findall(rf"\b({NUMBER})\b", say)) if n is not None] official = str(to_number(official)) if to_number(official) is not None else official return (found[-1] if found else None), official async def ask(http, args, q, mode, sem, out): async with sem: pcm = load_16k(Path(args.data) / f"q_{q['id']}.wav") ws = await open_session(http, args.url, SYSTEMS[args.system], mode) try: r = await run_turn(ws, pcm, commit=(mode == "manual"), until="done_after_audio", max_wait_s=args.max_wait_s) finally: await ws.close() answer, official = parse_answer(r["text"], q["official_answer"]) row = { "id": q["id"], "category": q["category"], "official_answer": official, "answer": answer, "correct": answer is not None and answer == official, "replied": r["done"] is not None and r["done"]["reason"] == "done", "started_early": r["started_early"], "replies_cut_off": sum(1 for d in r["replies"] if d["reason"] != "done"), "latency_ms": r["latency_ms"], "question_s": len(pcm) / 16000, "text": r["text"], "error": r["error"], "events": [e for e in r["events"] if e["type"] != "transcript.delta"], } write_json(out / f"q_{q['id']}.json", row) if r["audio"]: write_wav(out / f"q_{q['id']}.wav", np.frombuffer(r["audio"], dtype=" 1 else ''}.json", summary) if __name__ == "__main__": asyncio.run(main())