Vibe Engines is free, interactive AI engineering & system design — runs in your browser. Pick a learning path →
Listen
unlabeled.
Transcribing speech is expensive — someone has to sit and type out every word — which is why good speech recognition existed for a handful of rich languages and almost nowhere else. wav2vec 2.0 flips the economics. It learns the structure of speech from oceans of raw, untranscribed audio by playing a guessing game with itself: hide part of the sound, then pick out the right hidden piece from a lineup of impostors. After that, ten minutes of transcripts is enough to build a working recognizer. Here's the masking, the quantized targets, and the contrastive InfoNCE loss that makes it click.
What changes for audio: the transcripts stop being required
The ladder changes modality here, and the constraint in speech is the same one language and vision had: labels. Training a recogniser needs transcribed audio, transcription is skilled manual work, and for most of the world's languages there is very little of it. Audio itself is abundant.
The change is to learn from raw audio with no transcripts at all, by masking part of the signal's latent representation and requiring the model to identify what was hidden. The obstacle is that audio is continuous, so there is no correct token to predict and a regression on the waveform rewards modelling noise. The fix is to quantise the targets — learn a codebook of discrete speech units, the same device as discrete latents on the generative ladder — and then pose the task as contrastive: pick the true quantised unit for the masked position out of a set of distractors. A discrete, checkable question replaces an ill-posed continuous one.
Stated in units, the result is the one that mattered: pre-train on unlabelled audio, then fine-tune on a very small amount of transcribed speech — on the order of tens of minutes — and get usable recognition. Labelled data stops being the gate, which is what made speech recognition practical for languages that will never have thousands of transcribed hours.
The transcript problem
Supervised speech recognition needs transcribed audio — thousands of hours of it — and someone has to produce those transcripts by hand. That's why strong recognizers existed for English and a few other well-resourced languages and were poor or nonexistent for most of the world's ~7,000 languages. Meanwhile, unlabeled audio is everywhere and nearly free. The obvious question: can a model learn most of what it needs from raw audio alone, so only a tiny bit of labeled data is required at the end?
NLP had already answered "yes" with BERT-style masked pretraining. wav2vec 2.0 (Baevski, Zhou, Mohamed & Auli, 2020) brought that answer to speech. It pretrains on large amounts of unlabeled audio by masking chunks of the signal and learning to recover them through a contrastive task, then fine-tunes on a small labeled set. The headline result was startling: competitive recognition from as little as ten minutes of transcribed speech, and strong systems from an hour — roughly a hundredfold cut in the labeled data required, by the paper’s own comparison.
A CNN encodes raw audio into latent frames; a span is masked; a Transformer must identify each masked frame's true quantized latent among K distractors via a contrastive InfoNCE loss (cosine similarity / temperature) — learning speech structure from unlabeled audio, then fine-tuning on minutes of labels.
Encode, mask, contextualize
wav2vec 2.0 has three moving parts working on the raw waveform — no spectrograms, no hand-designed features:
The Transformer context network is what gives each masked position access to the surrounding audio, so it can infer what belongs in the gap from context — exactly the masked-prediction idea, but on continuous audio. The twist that makes speech work well is the quantizer: rather than asking the model to reproduce the raw continuous latent (which invites cheating on low-level acoustic texture), the target is a discrete quantized latent from a learned codebook. This nudges the model toward discovering a compact, phone-like inventory of speech units.
Pick the true target
The pretraining objective is contrastive, like a lineup. For each masked step, the model's context vector c is shown a set of candidate quantized latents: the one true target q for that step, plus K distractors sampled from the quantized latents of other masked positions in the same utterance. The model must pick out the true one.
"Picking" means scoring: it computes the cosine similarity between c and each candidate, divides by a temperature κ, and turns those scores into probabilities with a softmax. Training maximizes the probability assigned to the true target — equivalently, minimizes its negative log, the InfoNCE loss. To succeed, the context vector for a masked frame must become more aligned with its own quantized content than with any distractor, which forces the representation to encode what's actually being said at that moment. It's the same contrastive principle behind CLIP (match the right pair against many wrong ones), applied within a single audio stream.
InfoNCE, precisely
For a masked step with context c, true target q, and candidate set Q (the true target plus K distractors), the contrastive loss is:
sim(a, b) is cosine similarity; κ is a temperature. The numerator rewards similarity to the TRUE target; the denominator sums over the true target and all K distractors. This is a softmax classification over candidates, and the loss is the negative log-probability of the correct one.
Two everyday properties fall out. When the context is far more similar to its true target than to the distractors, the softmax puts nearly all mass on the truth and the loss approaches 0; when the true target is indistinguishable from the distractors, the loss approaches log(K+1) (chance). And solving the task simply means the true quantized target is the most similar candidate. The runnable version below implements cosine similarity, the InfoNCE loss over candidates, and this "did the true target win?" check.
How wav2vec 2.0 pre-trains and fine-tunes
wav2vec 2.0 pre-trains one network on unlabeled audio, then fine-tunes it on whatever transcribed audio exists. The numbers below are the paper's two configurations, BASE (about 95 million parameters) and LARGE (about 317 million).
- Encode the waveform. Raw 16 kHz audio passes through seven convolutional blocks with 512 channels each. The output is one latent vector z every 20 ms, each covering 25 ms (400 samples) of audio.
- Quantize the targets. From the unmasked latents, a quantizer with G = 2 codebooks of V = 320 entries picks one entry per codebook through a Gumbel-softmax; the two picks are concatenated and linearly transformed into the target q. That allows 320 × 320 = 102,400 distinct targets. The Gumbel temperature is annealed from 2 down to 0.5 for BASE and 0.1 for LARGE.
- Mask spans. Each time step is chosen as a span start with probability 0.065, and the 10 steps from each start are masked. Spans overlap, so about 49% of steps end up masked, in spans averaging 14.7 steps (about 300 ms). Masked latents are replaced by one shared learned vector before they reach the Transformer; the quantizer still sees the originals.
- Contextualize. A Transformer reads the masked sequence: 12 blocks of width 768 with 8 heads for BASE, 24 blocks of width 1,024 with 16 heads for LARGE. Position information comes from a convolution (kernel 128, 16 groups) whose output is added to the input, not from fixed position embeddings.
- Score. At each masked step, the context vector c is compared by cosine similarity with its own target q and with K = 100 distractors drawn from other masked steps of the same utterance, at temperature κ = 0.1. A diversity penalty with weight 0.1 keeps the codebooks in use.
- Pre-train. The unlabeled data is either LibriSpeech's 960 hours or LibriVox's 53,200 hours (LV-60k). BASE trained for 400K updates on 64 V100 GPUs in 1.6 days; LARGE trained on 128 V100 GPUs for 250K updates on LibriSpeech (2.3 days) or 600K updates on LibriVox (5.2 days).
- Fine-tune. A randomly initialized linear layer maps each context vector to characters, and the model is trained with CTC loss. The convolutional encoder stays frozen; for the first 10,000 updates only the new layer trains, then the Transformer joins. Labeled subsets range from 10 minutes to the full 960 hours.
- Decode. Transcripts come from beam search with a 4-gram or Transformer language model trained on the LibriSpeech text corpus.
Why continuous inputs but discrete targets
The Transformer reads continuous latents, which keep everything the encoder found, while it is scored against quantized ones. A continuous target would let the model win the lineup by matching speaker and background details of the utterance rather than what was said; a quantized input would throw information away before the context network could use it. The paper tests all four combinations, and the result is in the evidence below.
The full wav2vec 2.0 objective, with the diversity loss
Lm— the contrastive loss already shown on this page: the true target against K = 100 distractors at κ = 0.1G = 2, V = 320— two codebooks of 320 entries eachlg,v— the score the quantizer gives entry v of codebook g for one frame;n— Gumbel noiseτ— the Gumbel temperature; the forward pass takes the hard argmax, and the backward pass uses these soft probabilities (straight-through)p̄g— codebook g's softmax without noise, averaged over every frame in the batch;H— its entropy
At the extremes: if every frame picks the same entry, each H(p̄g) = 0 and Ld = 0, its worst value. If all 320 entries are used equally, H = ln 320 and Ld = −ln(320)/320 ≈ −0.018, its best. Because p̄ is averaged over the batch, the penalty does not push any single frame toward indecision; it rewards spreading choices across frames. As τ → 0 the probabilities become one-hot; a large τ makes them nearly uniform, smooth to train but vague as targets, which is why τ starts at 2 and is annealed down.
Word error rates from ten minutes to 960 hours
Models were pre-trained on 960 hours (LibriSpeech) or 53,200 hours (LibriVox) of audio without transcripts, fine-tuned on labeled subsets from 10 minutes to 960 hours, and compared with earlier self-training and semi-supervised systems by word error rate (WER) on LibriSpeech's clean and other test sets.
| Labeled audio | Setup | WER test-clean / test-other |
|---|---|---|
| 10 minutes | LARGE, LV-60k, Transformer LM | 4.8 / 8.2 |
| 10 minutes | LARGE, LV-60k, no LM | 40.2 / 38.7 |
| 1 hour | best configuration | beats the previous best 100-hour result with 100× less labeled data |
| 960 hours | LARGE, LV-60k, Transformer LM | 1.8 / 3.3 |
The ablation that justifies the design changes what is quantized. BASE, pre-trained on LibriSpeech and fine-tuned on 10 hours, averaged over three seeds on the dev sets:
| Transformer input | Contrastive target | Average WER |
|---|---|---|
| continuous | quantized (the paper's choice) | 7.97 |
| continuous | continuous | 8.58 |
| quantized | continuous | 11.18 |
| quantized | quantized | 12.18 |
Quantizing the input does the most damage, and the paper uses it to explain the weaker results of earlier work such as vq-wav2vec, which quantized the features its Transformer read. Continuous targets are the smaller loss: they let the model lean on speaker and background artifacts that make the task easier without helping recognition. The second row of the first table is the honest caveat on the headline: at 10 minutes, most of the word-level accuracy comes from the language model used in decoding.
What the authors admit, and what happened next
It is a representation learner, not a recogniser: there is always a fine-tune, so deploying it means a labelled dataset per language and per domain, however small. The contrastive setup is also sensitive in the ways contrastive setups are — the masking span, the number and source of distractors, and the codebook's health all matter, and codebook collapse is the same hazard it is on the generative ladder.
Robustness is the deeper limitation and it is inherited from the data rather than the method: a model pre-trained on clean read speech transfers poorly to noisy, accented, spontaneous audio, because nothing in the objective asks it to.
How it held up: self-supervised pre-training became standard in speech, and the low-resource result is a genuine and lasting contribution — there are working recognisers for languages that would otherwise have none. But the paradigm was directly challenged by the next rung, which is why the two sit adjacent here. This rung's bet is that clean supervision is scarce so you should learn representations and fine-tune; the next one's is that weak supervision is abundant, and that using enough of it removes the fine-tune entirely. Both are right about something, and they are not compatible strategies.
The contrastive loss, from scratch
wav2vec 2.0's pretraining is a contrastive task scored by cosine similarity. Here it is with no audio and no framework: cosine similarity (1 for aligned, 0 for orthogonal, −1 for opposite), the InfoNCE loss that turns candidate similarities into a softmax and takes the negative log of the true target's probability, and the check for whether the true quantized target is the most similar candidate. Change the context, the true target, and the distractors and watch the loss respond.
Write the body of infonce_loss. Everything else in the file is
already written; this is the function the paper is about. Press ▶ Run to check it against
the 5 assertions below — they start red.
- Cosine similarity of a vector with itself is 1 (perfectly aligned)
- Orthogonal vectors have cosine similarity 0
- Opposite vectors have cosine similarity -1
- The InfoNCE loss (true sim 1, distractors 0 and -1, kappa 1) is -log of the softmax prob
- The contrastive task is solved when the true quantized target is the most similar candidate
Self-supervision for audio
wav2vec 2.0 established self-supervised pretraining as the default first stage for speech models, mirroring what masked pretraining did for text. Its ideas propagated fast: HuBERT swapped the contrastive objective for predicting cluster assignments (a more BERT-like target), data2vec unified the recipe across speech, vision, and text with a single self-distillation objective, and multilingual variants like XLS-R scaled the approach to dozens of languages at once — directly attacking the low-resource gap that motivated the work.
Zoom out and it's a tidy convergence point for representation learning. The mask-and-predict idea from BERT, the contrastive idea from earlier contrastive predictive coding (wav2vec 2.0 predates CLIP), and discrete learned codebooks all meet here in the audio domain — and the pretrained representations became a strong starting point that even large supervised systems like Whisper can be compared against or built alongside. wav2vec 2.0 is the paper that made "learn from the audio you already have, label almost none of it" the standard way to teach machines to listen.
The quantizer uses product quantization: instead of one big codebook, it splits each latent into groups and quantizes each group with its own small codebook, then concatenates. This yields a huge number of possible discrete targets from a few compact codebooks (e.g. 2 groups of 320 entries → 320² ≈ 100K combinations), giving expressive discrete units without an unwieldy single codebook — and the Gumbel-softmax keeps the discrete choice differentiable so it trains end-to-end.
Questions people ask about wav2vec 2.0
What is the wav2vec 2.0 diversity loss?
It is a penalty that stops the quantizer from collapsing onto a few codebook entries. wav2vec 2.0's targets come from two codebooks of 320 entries each, chosen with a Gumbel-softmax. The diversity loss averages each codebook's softmax over all frames in a batch and rewards high entropy of that average, so the batch as a whole spreads its choices across entries while any single frame can still pick one entry confidently. Formally it is the negative entropy summed over the two codebooks and divided by G times V, added to the contrastive loss with weight 0.1. Without it, many entries go unused, and a collapsed codebook gives targets that say little about what was spoken.
How is wav2vec 2.0 different from HuBERT?
Both mask spans of speech features and train a Transformer to recover what was hidden, but they define the target differently. wav2vec 2.0 learns its targets during training with a Gumbel-softmax quantizer and asks the model to pick the true quantized latent out of 100 distractors with a contrastive loss, plus a diversity penalty to keep the codebook in use. HuBERT, from Facebook AI in 2021, makes its targets offline: it clusters MFCC features with k-means, trains the model to predict each masked frame's cluster with ordinary cross-entropy, then re-clusters the model's own features and trains again. HuBERT needs no negatives and no codebook penalty, and its authors report matching or beating wav2vec 2.0 on the same LibriSpeech and Libri-light fine-tuning splits.
How does wav2vec 2.0 mask the audio?
Masking happens on the latent frames, one every 20 milliseconds, not on the waveform. Each frame is picked as the start of a span with probability 0.065, and the 10 frames from every start are masked. Because spans overlap, about 49% of all frames end up masked, in spans averaging 14.7 frames, roughly 300 milliseconds. Each masked frame is replaced by one learned vector shared by all masked positions before it enters the Transformer. The quantizer, which makes the targets, still sees the unmasked latents, so every masked position has a real target to be identified among 100 distractors drawn from other masked positions in the same utterance.
How much labeled data does wav2vec 2.0 need?
Very little, as long as a language model helps with decoding. Pre-trained on 53,200 hours of unlabeled LibriVox audio and fine-tuned on just 10 minutes of transcribed speech, the large model reached 4.8% and 8.2% word error rate on LibriSpeech's clean and other test sets with a Transformer language model. With one hour of labels it beat the previous best result trained on 100 hours, using 100 times less labeled data, and with all 960 hours it reached 1.8% and 3.3%. The language model matters most at the low end: decoded without one, the same 10-minute model's error rates were around 40%.
Why does wav2vec 2.0 quantize the targets but not the Transformer's input?
Because the paper tested all four combinations and this one won. With the base model fine-tuned on 10 hours, continuous inputs with quantized targets gave an average word error rate of 7.97; continuous for both gave 8.58; quantized inputs with continuous targets gave 11.18; and quantized for both gave 12.18. Quantizing the input throws information away before the context network can use it, and the authors say this explains the weaker results of earlier work such as vq-wav2vec, which quantized the features its Transformer read. Continuous targets are the smaller problem: they let the model match speaker and background details instead of what was said.
How is wav2vec 2.0 fine-tuned for speech recognition?
A randomly initialized linear layer is added on top of the Transformer to map each 20-millisecond context vector to a character, and the model is trained on transcribed audio with connectionist temporal classification (CTC), which handles the alignment between frames and letters. The convolutional feature encoder stays frozen. For the first 10,000 updates only the new output layer is trained, so its random weights cannot damage the pre-trained Transformer, which then joins in. Time steps and feature channels are still masked during fine-tuning, as a form of regularization. At test time, beam search with a 4-gram or Transformer language model turns the character probabilities into words.
5 questions to test what you just read
Work each one out before you open it — a number, a prediction or a reason, not a definition. Producing the answer is what makes it stick. Your progress is kept on this device.
A training crop is 15.6 seconds long. How many latent frames does the encoder produce, and roughly how many are masked?
Show answer
One frame every 20 ms gives about 15.6 × 50 ≈ 780 frames. About 49% are masked, roughly 380, and each masked frame is its own 101-way contrastive problem: its true target against 100 decoys.
Spans start with probability 0.065 and cover 10 frames. Why are about 49% of frames masked rather than 65%?
Show answer
Spans overlap. A frame stays unmasked only if none of the 10 positions that could cover it was chosen as a start: (1 − 0.065)^10 ≈ 0.51. So about 1 − 0.51 ≈ 49% are masked; 6.5% × 10 = 65% would require that no two spans ever overlap.
Before any training, a context vector is unrelated to its target. What contrastive loss should you expect with K = 100 distractors?
Show answer
All 101 candidates score about the same, so the softmax gives the true target about 1/101 and the loss is ln 101 ≈ 4.62 nats. Getting below that requires ct to encode what was actually said at the masked step.
Compute the diversity loss at full codebook collapse and at perfectly even use, with G = 2 and V = 320. Which does training prefer?
Show answer
Collapse: each entropy is 0, so Ld = 0. Even use: each entropy is ln 320 ≈ 5.77, so Ld = −(2 × 5.77)/(2 × 320) ≈ −0.018. Training minimizes the total loss, so it prefers even use of the codebooks.
Predict the ablation: quantize the Transformer's input as well as its targets. Better or worse than the paper's choice, and why?
Show answer
Worse: average WER rises from 7.97 to 12.18, the worst of the four variants. Quantizing the input discards detail before the context network can use it. The paper uses this result to explain why earlier work such as vq-wav2vec, which fed its Transformer quantized units, did worse.
One model, many senses
Joining text to images, audio, video and finally to a robot arm. Starts with the contrastive objective the whole field standardised on.
- 1CLIP2021
- 2Flamingo2022
- 3LLaVA2023
- 4wav2vec 2.02020
- 5Whisper2022
- 6V-JEPA2024
- 7RT-22023
- 8Genie2024
Explore the topic
See this alongside everything else on the same subject — handbooks, system designs, challenges and tools, in one place.
More Paper Breakdowns
- Attention Is All You NeedThe paper that introduced the Transformer — the architecture underneath GPT, BERT, Claude, and Gemini. Self-attention, Query/Key/Value, multi-head attention, positional encoding, and the real BLEU results, explained in depth with analogies and animated visuals, not just equations.Read →
- Word2VecHow words became math. Dense word vectors learned from the company a word keeps, so king − man + woman lands near queen. Skip-gram, CBOW, the distributional hypothesis, and the origin of every embedding model powering search and RAG.Read →
- ResNetThe skip connection that made deep learning deep. Why stacking layers made networks worse, and how residual learning let them reach 150+ layers and win ImageNet — the identity shortcut every Transformer still uses inside every block.Read →
- Vision Transformer (ViT)When an image became 16×16 words. Cut a picture into patches, treat each patch as a token, and feed them to a plain Transformer — no convolutions. Patch embeddings, the class token, and why data scale lets attention beat the CNNs that ruled computer vision for a decade.Read →
- Latent DiffusionThe paper behind Stable Diffusion. Compress an image into a small latent space with a VAE, run the diffusion denoising there instead of on pixels for a tens-of-times efficiency win, and steer it with text via cross-attention. The architecture that put text-to-image generation on consumer GPUs.Read →
- DDPMThe original denoising diffusion math — the paper that made diffusion work. A fixed forward process adds Gaussian noise over many steps; a U-Net learns the reverse. The masterstroke: train the network to simply predict the added noise with a plain MSE loss. The foundation under every modern image generator.Read →