KrokoMusci-OpenASR / normalizer /voice_code_data.py
Banafo's picture
Bench packed Musci prefill and cache retention on expanded public Open ASR suite
9ef47e0 verified
Raw History Blame Contribute Delete
1.93 kB
"""Load the pinned VoiceCodeBench recordings using the Open ASR protocol."""
from pathlib import Path, PurePosixPath
DATASET_ID = "besimple-ai/voice-code-bench"
DATASET_REVISION = "bef2824f83ef1c796f3e79731a3b0741708730df"
RECORDINGS = 300
MANIFEST_KEYS = ("audio_id", "voice_code_bench_revision")
MAX_RECORDING_SECONDS = 130
MAX_CHUNK_SECONDS = 30
def load_data(args):
from datasets import Audio, load_dataset
from huggingface_hub import snapshot_download
if (args.dataset != "default" or args.split != "test" or args.streaming
or args.dataset_revision != DATASET_REVISION or args.max_eval_samples != -1):
raise ValueError("Expected the complete pinned VoiceCodeBench default test split")
# Upstream protocol: open_asr_leaderboard@4b87692/normalizer/voice_code_bench.py.
root = Path(snapshot_download(
DATASET_ID, repo_type="dataset", revision=DATASET_REVISION,
allow_patterns=["data/metadata.jsonl", "data/audio/*.wav"],
)) / "data"
dataset = load_dataset("json", data_files={"test": str(root / "metadata.jsonl")}, split="test")
ids = dataset["audio_id"]
if len(ids) != RECORDINGS or len(set(ids)) != RECORDINGS or any(not value for value in ids):
raise ValueError("VoiceCodeBench metadata does not contain 300 unique audio IDs")
def attach_audio(sample):
relative = PurePosixPath(sample["file_name"])
if relative.parent != PurePosixPath("audio") or relative.suffix != ".wav":
raise ValueError("Unexpected VoiceCodeBench audio path")
audio = root / relative
if not audio.is_file():
raise FileNotFoundError(audio)
return {"audio": str(audio), "id": sample["audio_id"], "text": sample["transcripts"]["acoustic"],
"voice_code_bench_revision": DATASET_REVISION}
return dataset.map(attach_audio, load_from_cache_file=False).cast_column("audio", Audio())