W2V-BERT 2.0 + MHFA speaker verification (OpenSVBench)
A single speaker-embedding model: the W2V-BERT 2.0 encoder, cut to its first 22 layers and fully fine-tuned, with an MHFA
(multi-head factorised attentive pooling) back-end. It maps 16 kHz speech to a 256-dim embedding. Trials are scored by the
cosine of the two embeddings after subtracting the VoxCeleb2-dev mean (vox2_mean.npy). The scores are not normalised or
calibrated, and no other model is fused in.
Training code: branch ovsb of wespeaker_w2v2, recipe examples/ovsb/v1,
config conf/stage2_v9c.yaml.
Files
| File | Content |
|---|---|
model.safetensors | encoder (frontend.upstream.*, 22 conformer layers) + MHFA back-end; 534.5 M parameters, fp32; the training classifier is removed |
w2v-bert-2.0_L22/ | encoder config (the facebook/w2v-bert-2.0 config with 22 layers) and the feature-extractor config |
model_config.json | back-end sizes, input cap (60 s), mean file |
vox2_mean.npy | mean of the raw embeddings of all 1,092,009 VoxCeleb2-dev utterances, computed with this checkpoint |
modeling_mhfa.py | standalone inference code (PyTorch + transformers), the same computation as the training repository |
Usage
pip install torch transformers safetensors soundfile huggingface_hub
import sys, soundfile as sf, torch
from huggingface_hub import snapshot_download
d = snapshot_download("JYP2024/wespeaker-mhfa-W2VB-OVSB")
sys.path.insert(0, d)
from modeling_mhfa import SpeakerEmbedder
model = SpeakerEmbedder.from_pretrained(d, device="cuda") # or "cpu"
wav1, sr = sf.read("enroll.wav", dtype="float32"); assert sr == 16000
wav2, sr = sf.read("test.wav", dtype="float32"); assert sr == 16000
e = model.embed([torch.from_numpy(wav1), torch.from_numpy(wav2)]) # raw embeddings (2, 256)
print(float(model.score(e[0], e[1]))) # cosine after the vox2 mean
Evaluation protocol used for every number below:
- Input is mono 16 kHz audio, scaled to [-1, 1].
- Each utterance is embedded whole, up to 60 s, in one forward pass. There is no chunking and no test-time augmentation.
- Weights are fp32. Matrix multiplications use TF32 on A100.
- Scores are the cosine after mean subtraction and length normalisation.
model(x, lens) embeds a zero-padded batch with masked attention, which is faster. It gives the same embedding up to
floating-point differences.
Results
The OpenSVBench core sets were scored with the protocol above. The macro average is the OpenSVBench kit's average over scenario groups. minDCF is reported at P_target = 0.05.
| EER (%) | minDCF | |
|---|---|---|
| OpenSVBench macro (kit) | 5.354 | 0.2281 |
| macro without cnceleb_genre / cnceleb_short (see note) | 4.904 | 0.2126 |
| VoxCeleb1-O (cleaned) | 0.314 | 0.0295 |
| VoxCeleb1-E (cleaned) | 0.477 | 0.0271 |
| VoxCeleb1-H (cleaned) | 0.948 | 0.0535 |
| Set | EER (%) | minDCF |
|---|---|---|
| tidyvoice | 1.947 | 0.1488 |
| hi_mia | 3.257 | 0.1990 |
| gsc_short | 2.502 | 0.1487 |
| globe | 24.129 | 0.4941 |
| cnceleb | 4.756 | 0.2167 |
| cnceleb_genre † | 8.634 | 0.3463 |
| cnceleb_short † | 10.039 | 0.3897 |
| voxceleb_o | 0.314 | 0.0295 |
| voxceleb_e | 0.477 | 0.0271 |
| voxceleb_h | 0.949 | 0.0534 |
| voxceleb_short | 9.731 | 0.3811 |
| speaker3d_device | 3.720 | 0.2452 |
| speaker3d_distance | 5.023 | 0.3072 |
| speaker3d_dialect | 7.375 | 0.4489 |
| ffsvc2022_cross_channel | 3.700 | 0.2420 |
| ffsvc2022_cross_domain | 3.728 | 0.2417 |
| whisper40_whisper | 3.875 | 0.1993 |
| lombardgrid_lombard | 0.037 | 0.0022 |
| voices_noise_reverb | 2.400 | 0.0609 |
| chime6_domestic_farfield | 7.688 | 0.2986 |
| chime6_overlap | 13.139 | 0.5940 |
| esd | 1.866 | 0.1470 |
| alimeeting_near_far | 2.450 | 0.1297 |
| alimeeting_overlap | 3.700 | 0.2131 |
| voxknesset | 3.140 | 0.1045 |
| voxpopuli_cross_time | 1.531 | 0.0313 |
† Training contains test speakers of these two sets. The training data includes CN-Celeb1 dev, and the CN-Celeb1 dev speakers also appear in the trials of cnceleb_genre and cnceleb_short. Their numbers are therefore not held-out results. The second macro row leaves both sets out.
Training
- Stage 1. The MHFA back-end is trained on top of the frozen encoder.
- Stage 2 (this checkpoint).
- Full fine-tuning for 14 epochs of 1.4 M samples each.
- Loss: AAM-softmax with inter-top-k and 3 sub-centres (152,367 speakers), plus a consistency term and a pairwise ranking term.
- Sampler: episodic P × K, with a fixed sampling share for each corpus.
- Crops: variable length, from 0.5 to 6 s.
- Augmentation: noise, reverberation, codec / band-limit / EQ channel simulation, and time masking.
- Training data. About 7.8 M utterances, 19.2 k hours, 152,367 speakers:
| Corpus | Speakers | Hours |
|---|---|---|
| VoxCeleb2 dev | 5,994 | 2,372 |
| VoxBlink2 | 104,297 | 11,987 |
| CN-Celeb2 | 1,555 | 830 |
| CN-Celeb1 dev | 787 | 230 |
| 3D-Speaker | 9,448 | 921 |
| KeSpeech | 24,768 | 1,390 |
| MAGICDATA Mandarin read speech | 1,076 | 755 |
| MagicData-RAMC | 663 | 133 |
| AISHELL-1 | 400 | 179 |
| AISHELL-3 | 218 | 86 |
| TidyVoiceX (train) | 3,161 | 313 |
The noise and reverberation sources are MUSAN and the RIR corpus (simulated and real RIRs).
Limitations
- The model is not calibrated. Raw cosine thresholds depend on the condition, so pick a threshold on data from the target domain.
- Inputs longer than 60 s are truncated.
- Do not use it for identification or surveillance of people without their consent.
Citation
@inproceedings{peng2022mhfa,
title = {An attention-based backend allowing efficient fine-tuning of transformer models for speaker verification},
author = {Peng, Junyi and Plchot, Old{\v{r}}ich and Stafylakis, Themos and Mo{\v{s}}ner, Ladislav and Burget, Luk{\'a}{\v{s}} and {\v{C}}ernock{\'y}, Jan},
booktitle = {IEEE Spoken Language Technology Workshop (SLT)},
year = {2023}
}