Run this model with HF Jobs

Run Zenbu/embeddinggemma-2-audio-lid-probe on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.

Paste one of these prompts into your coding agent:

Fine-tune on my dataset

Use HF Jobs to fine-tune https://huggingface.co/Zenbu/embeddinggemma-2-audio-lid-probe. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.

Run batch inference

Use HF Jobs to run batch inference with https://huggingface.co/Zenbu/embeddinggemma-2-audio-lid-probe on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.

EmbeddingGemma 2 Spoken-Language Classifier Probe (v3)

A 230 KB linear spoken-language classifier probe (61,460 float32 parameters) on top of Google's frozen google/embeddinggemma-2 audio tower, with music and non_speech fallback classes.

Use it to identify spoken language, abstain or fall back when an audio clip is music or non-speech, or guard English-only retrieval pipelines. It runs on audio_tower alone (so you skip loading the 24-layer language backbone), or captures window posteriors mid-pass while generating multimodal embeddings. Put simply, it's an almost computationally "free" addon to EmbeddingGemma 2 that lets it classify the spoken language in an audio file, with a few other niche applications.

Why does this exist?

EmbeddingGemma 2 aligns speech and text across languages in one 768-dimensional semantic space, so similarity search on those output vectors does not tell you which language was spoken.

Upstream of the 24-layer language backbone, the audio_tower frames keep the language signal. Reading them with a 230 KB linear layer lets an EmbeddingGemma 2 setup recover spoken language (with music and non_speech fallbacks) mid-pass while indexing, or run standalone on audio_tower without loading the 24-layer backbone or a separate language-ID model.

Classes

There are 20 outputs in fixed order:

  • 17 spoken languages: en, pt, es, fr, de, it, nl, pl, ru, uk, tr, ar, hi, zh, ja, ko, vi
  • other_speech: open-set speech bucket trained on 49 FLEURS and 42 VoxLingua107 languages (Hungarian, Romanian, and Danish were left completely out of training and calibration to test unseen generalization)
  • music: generic music across vocal and instrumental tracks
  • non_speech: environmental audio, sound effects, beeps, and synthetic noise

Clips up to 150 tower frames (6.0 s at 25 Hz) are pooled in one window. Longer clips use overlapping 5.0 s (125-frame) windows with a 2.5 s (62-frame) hop. For recordings longer than 30 s, probe_inference.py includes a trim_silence_and_chunk helper that drops gaps longer than 1 s and processes <= 30 s chunks before aggregating windows.

Scope and known failure modes

What holds up in testing:

  • Single-language speech at least 2 s long across the 17 target languages, including noisy recordings, 8 kHz phone channels, 12 kbps Opus VoIP audio, and global English accents (88.3% primary accuracy across 15 accents on EDACC, with 100.0% precision when language_confident is true).
  • Catching languages outside the 17-language list as other_speech (12/12 on unseen Hungarian, Romanian, and Danish).
  • Generic music flagging on both accompaniment stems (48/48 on MUSDB18) and vocal mixes (46/48 on MUSDB18).
  • Abstaining when uncertain: language_confident requires a named language above threshold (0.65), music_ratio <= speech_ratio, and at least 2.0 s of speech. Across all 1,315 conversational English/Mandarin turns in CAiRE/ASCEND, confident predictions were right 100.0% of the time (558/558).

What does not work reliably:

  • Sub-1.5 s clips and back-channels (the probe was not trained below 1.5 s; language_confident always returns false below 2.0 s of speech).
  • Exact tag sets on fast spontaneous code-switching under 3 s.
  • Separating singing from instrumental backing: MUSDB18 accompaniment stems fire music just like vocal mixes do, so has_music means music is present, not that someone is singing.

Inference details (pooling and mask polarity)

Two implementation details cause silent bugs if missed:

  1. Pooling uses biased standard deviation (ddof=0 / unbiased=False) plus 1e-6 before the square root over valid unpadded 25 Hz audio_tower frames (T, 1536):

    mean = frames.mean(axis=0)
    std = np.sqrt(frames.var(axis=0, ddof=0) + 1e-6)
    feat_3072 = np.concatenate([mean, std], axis=0)
    

    Using ddof=1 or omitting 1e-6 breaks short or near-constant clips.

  2. PyTorch and Apple MLX invert mask meaning:

    • PyTorch (transformers audio_tower(..., attention_mask=...)): True means a valid frame.
    • MLX (mlx-vlm audio_tower(mel, invalid_mask)): True means a padding/invalid frame (pass ~input_features_mask).

On matched inputs, PyTorch FP32 (Tesla T4) and Apple Silicon MLX 8-bit (mlx-community/embeddinggemma-2-8bit) pooled features agree with cosine 1.000000 and 0.99999994.

Usage

Standalone script (probe_inference.py + model.safetensors)

Requires numpy, safetensors, ffmpeg, plus either mlx / mlx-vlm (Apple Silicon) or torch / transformers.

python probe_inference.py voice_memo.m4a sample.wav --backend mlx
python probe_inference.py voice_memo.m4a sample.wav --backend pytorch
from probe_inference import AudioProbeHead, classify_pytorch

head = AudioProbeHead.load("model.safetensors")
results = classify_pytorch([wav_16k_mono_float32], head)
print(results[0]["label"], results[0]["language_confident"], results[0]["detected_languages"])

Direct linear head (safetensors)

W_eff and b_eff already fold in the training feature StandardScaler and calibrated temperature (T = 0.95763), so inference is one matmul:

from safetensors import safe_open
import numpy as np

with safe_open("model.safetensors", framework="numpy") as f:
    W_eff = f.get_tensor("W_eff")               # (20, 3072) float32
    b_eff = f.get_tensor("b_eff")               # (20,) float32
    thresholds = f.get_tensor("class_thresholds")  # uniform 0.65

logits = feat_3072 @ W_eff.T + b_eff
logits -= logits.max(axis=-1, keepdims=True)
probs = np.exp(logits) / np.exp(logits).sum(axis=-1, keepdims=True)

Evaluation summary

Held-out multi-domain split (n = 2,869, group-disjoint)

Metric Result Notes
Overall accuracy / Macro-F1 96.72% / 0.9758 95% CI [0.9703, 0.9807], ECE = 0.0075
5.0 s slice (n = 2,488) 94.98% Macro-F1 0.9552
en PR-AUC / F1 (n = 203) 0.9841 / 0.9756 Across FLEURS, MINDS-14, VoxLingua107, CommonAccent, VoxPopuli
By source 89.5% to 100% VoxPopuli en_accented 100%, FLEURS 98.7%, MINDS-14 98.0%, FMA 97.5%, VoxLingua107 96.7%, CommonAccent 96.7%, FSD50K 89.5%

Out-of-distribution (OOD) and external suites (MLX 8-bit)

Suite Result Notes
Monolingual FLEURS (17 x 4) 68/68 (100.0%) 0/64 strict-English false passes
Unseen languages (hu, ro, da x 4) 12/12 (100.0%) Exact other_speech on all 12 clips
EDACC 15 English accents (60 clips, OOD) 88.3% acc (93.3% recall) language_confident: 71.7% cov (>= 2 s), 100.0% (33/33) prec
Earnings-22 corporate calls (40 clips, OOD) 100.0% (40/40) 100% confident coverage and precision
Multilingual LibriSpeech (pt/es/fr/de, 60) 93.3% acc (96.7% recall) pt 15/15, fr 15/15, es 13/15, de 13/15
URGENT-2024 noisy speech (60, < 5 to >= 15 dB) 96.7% acc 100% above 5 dB; 100.0% (57/57) confident precision
AMI far-field meetings (40 clips, OOD) 92.5% acc (37/40) 97.3% confident precision
12 kbps Opus / +3 dB Reverb+Noise (24 OOD clips) 100.0% (24/24) / 87.5% (21/24) 100.0% confident precision on both
TED-LIUM long-form (5 talks, up to 25.1 m) 100% chunk consistency 159/159 <= 30 s silence-trimmed chunks predicted en
CAiRE/ASCEND EN/ZH turns (1,315 clips) 100.0% conf prec (558/558) en >= 2 s: 91% cov; zh >= 2 s: 95% cov
MUSDB18 stems (48 accompaniment / 48 vocal mix) 48/48 (100%) / 46/48 music 0 speech tags on accompaniment

Detailed breakdowns live in evals/PROBE_V3_RELEASE_EVAL.md, evals/PROBE_V3_OOD_EVAL.md, and audio_lid_report_v3.json.

Training data and licenses

All 17,657 clips come from commercially permissive sources (GTZAN, non-commercial ESC-50, and Sampling+ files were excluded). Training used 5-fold StratifiedGroupKFold across 13,882 dev groups with spoken-class balanced sample weights (selected_C = 0.01, T = 0.95763):

Source Clips License
google/fleurs (rev 70bb2e84) 7,289 CC BY 4.0
TalTechNLP/voxlingua107_wds (max 1/video) 5,468 CC BY 4.0
PolyAI/minds14 1,020 CC BY 4.0
DTU54DL/common-accent (sentence-deduped) 360 CC0 1.0 / MIT
facebook/voxpopuli (en_accented, speaker-disjoint) 240 CC0 1.0
philgzl/fsd50k (CC0/CC-BY subset) 2,450 CC0 1.0 / CC BY 3.0 / CC BY 4.0
benjamin-paine/free-music-archive-commercial-16khz-full 650 CC BY 1.0-4.0 / CC0 1.0 / Public Domain Mark 1.0
Synthetic tones, beeps, and filtered noise 180 Public Domain (generated)
Downloads last month
46
Safetensors
Model size
61.5k params
Tensor type
F32
·
MLX
Hardware compatibility
Log In to add your hardware

Quantized

Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for Zenbu/embeddinggemma-2-audio-lid-probe

Finetuned
(210)
this model

Datasets used to train Zenbu/embeddinggemma-2-audio-lid-probe