Paper Breakdowns  /  wav2vec 2.0
Paper 101~11 min read2020worked math + runnable code
Paper Breakdown

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.

Video breakdown
The animated walkthrough is in production.
Read the full breakdown below in the meantime ↓
01

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 — an order-of-magnitude cut in the labeled data required.

The one-sentence version

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.

02

Encode, mask, contextualize

wav2vec 2.0 has three moving parts working on the raw waveform — no spectrograms, no hand-designed features:

The pretraining pipeline
CNN encoderA convolutional stack turns the raw waveform into ~50 latent frames per second, z.
maskA span of latent frames is masked (replaced with a shared learned vector).
TransformerA context network reads the whole (masked) sequence, producing context vectors c.
quantizerA learned codebook maps each latent z to a discrete quantized target q.
taskFor each masked step, make context c match its own true q, not the distractors.

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.

03

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.

04

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:

L  =  −log  exp( sim(c, q) / κ )  /  Σq̃ ∈ Q exp( sim(c, q̃) / κ )

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.

RUN IT YOURSELF

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.

CPython · WebAssembly
05

What it showed

wav2vec 2.0 collapsed the labeled-data requirement for speech recognition:

ContributionSignificance
ASR from ~10 minutes of labelsAfter unlabeled pretraining, competitive recognition with a tiny transcribed set — orders of magnitude less than before.
State-of-the-art with full labelsFine-tuned on the full labeled set, it also set new records on standard benchmarks (LibriSpeech).
Learned discrete speech unitsThe quantizer discovered a compact, phone-like inventory directly from raw audio, no phonetic labels.
Low-resource unlockMade strong ASR feasible for languages with little transcribed data — the basis of multilingual XLS-R.

There are engineering subtleties that matter in practice. The Gumbel-softmax quantizer needs a diversity penalty so the codebook doesn't collapse to a few entries; the contrastive task is sensitive to how many distractors you use and the temperature; and fine-tuning uses a CTC loss on top. But the headline stands: most of the learning can happen without labels, and that reshaped how speech models are built.

06

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 models like 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.

Worth knowing

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.

Frequently asked

Quick answers

What is wav2vec 2.0?

A self-supervised speech model that learns from raw, untranscribed audio by masking latent frames and solving a contrastive task, then fine-tunes for recognition with very little labeled data.

How does pretraining work?

For each masked frame, the Transformer's context vector must identify the true quantized target among K distractors, scored by cosine similarity/temperature and trained with the InfoNCE loss.

Why quantize the targets?

Discrete targets (from a learned codebook via Gumbel-softmax) push the model toward compact, phone-like speech units instead of memorizing low-level waveform texture.

Why does it matter?

It made ASR possible from ~10 minutes of transcripts, unlocking low-resource languages, and set self-supervised contrastive pretraining as the standard for speech (HuBERT, XLS-R).

wav2vec 2.0: A Framework for Self-Supervised Learning of Speech Representations · Alexei Baevski, Henry Zhou, Abdelrahman Mohamed, Michael Auli · Facebook AI · 2020 · read the original paper on arXiv → · Vibe Engines · 2026
Finished this one? 0 / 101 Paper Breakdowns done

Explore the topic

See this alongside everything else on the same subject — handbooks, system designs, challenges and tools, in one place.

More Paper Breakdowns