"""Seed the random baseline for ADD22_eval_31 (standard EER, labels-only). The leaderboard scores are deterministic N(0,1) (seed=0) over the labels.parquet utterance order -- identical to what `_score_add22.py --model random-baseline` produces over the audio (RandomBaseline ignores the waveform), but without a 112k-file decode. EER lands ~50% by construction. Steps: generate scores -> EER -> upload scores.txt to random-baseline-asas -> write submissions/random-baseline.yaml (reproduction block filled). Pass the clean post-squash dataset revision via --dataset-revision. HF_TOKEN=... python _seed_baseline.py --dataset-revision """ from __future__ import annotations import argparse import hashlib import os from pathlib import Path import numpy as np import yaml from huggingface_hub import CommitOperationAdd, HfApi from speech_spoof_bench import labels as labels_mod from speech_spoof_bench.metrics import get_metric BASE = Path(__file__).resolve().parent DATASET_ID = "SpeechAntiSpoofingBenchmarks/ADD22_eval_31" RB_REPO = "SpeechAntiSpoofingBenchmarks/random-baseline-asas" BENCH_VERSION = "speech-spoof-bench==0.4.1" def main() -> None: ap = argparse.ArgumentParser() ap.add_argument("--dataset-revision", required=True, help="clean (post-squash) dataset repo SHA the labels live at") ap.add_argument("--seed", type=int, default=0) args = ap.parse_args() api = HfApi(token=os.environ["HF_TOKEN"]) # 1. Deterministic N(0,1) scores over labels.parquet order. lbl = labels_mod.load_labels_file(BASE / "data" / "labels.parquet") uids = sorted(lbl) rng = np.random.default_rng(args.seed) vals = rng.standard_normal(len(uids)) scores = {u: float(v) for u, v in zip(uids, vals)} print(f"utterances: {len(uids)}") # 2. EER. eer = get_metric("eer_percent").fn(scores, lbl) print(f"eer_percent = {eer.value:.6f} (threshold={eer.extras['threshold']:.4f})") # 3. scores.txt + sha. scores_txt = BASE / "_scores_add22.txt" with scores_txt.open("w") as f: for u in uids: f.write(f"{u} {scores[u]:.6f}\n") sha = hashlib.sha256(scores_txt.read_bytes()).hexdigest() print(f"scores.txt sha256={sha} size={scores_txt.stat().st_size/1e6:.2f}MB") # 4. Upload scores.txt to random-baseline-asas under .eval_results//. art_path = f".eval_results/{DATASET_ID}/scores.txt" api.create_commit( repo_id=RB_REPO, repo_type="model", operations=[CommitOperationAdd(art_path, str(scores_txt))], commit_message=f"random-baseline scores for {DATASET_ID} (EER seed)", ) art_rev = api.repo_info(RB_REPO).sha scores_url = f"https://huggingface.co/{RB_REPO}/resolve/{art_rev}/{art_path}" print(f"uploaded scores.txt @ {art_rev}") # 5. Submission yaml (schema 4, standard EER, reproduction filled). sub = { "schema_version": 4, "system": { "name": "random-baseline", "slug": "random-baseline", "description": ( "Reference random baseline. Returns N(0, 1) for every utterance " "using a fixed seed (seed=0). EER ≈ 50% by construction. Seeded " "smoke-test baseline for the arena."), "code": "https://github.com/SpeechAntiSpoofingBenchmarks/speech-spoof-bench", "checkpoint": f"https://huggingface.co/{RB_REPO}", "params_millions": 1, "paper": { "arxiv_id": "1911.01601", "url": "https://arxiv.org/abs/1911.01601", "bibtex": ( "@article{wang2020asvspoof, title={ASVspoof 2019: A large-scale " "public database of synthesized, converted and replayed speech}, " "author={Wang, Xin and others}, journal={Computer Speech \\& " "Language}, volume={64}, pages={101114}, year={2020}, " "publisher={Elsevier}}"), }, }, "dataset": { "id": DATASET_ID, "revision": args.dataset_revision, "split": "test", }, "scores": { "eer_percent": float(eer.value), "n_trials": len(uids), "n_skipped": 0, }, "artifact": { "scores_url": scores_url, "scores_sha256": sha, "bench_version": BENCH_VERSION, }, "reproduction": { "reproduced_by": "SpeechAntiSpoofingBenchmarks", "reproduced_at": "2026-06-22", "reproduced_bench_version": BENCH_VERSION, "match": "scoring", }, "submitter": { "hf_username": "SpeechAntiSpoofingBenchmarks", "contact": "k.n.borodin@mtuci.ru", }, "submitted_at": "2026-06-22", "notes": ( "Seeded random baseline for the labels-only ADD22_eval_31 dataset. " "Deterministic N(0,1) (seed=0) scores; reproduced by the maintainer " "via `reproduce --scoring` (sha matched, EER Δ 0.0)."), } out = BASE / "submissions" / "random-baseline.yaml" out.write_text(yaml.safe_dump(sub, sort_keys=False, allow_unicode=True)) print(f"wrote {out}") if __name__ == "__main__": main()