Skip to content

Learning from unlabeled speech: wav2vec, wav2vec 2.0, XLS-R and w2v-BERT

Transcribed speech is scarce; untranscribed speech is everywhere. Contrastive pretraining learns a speech encoder by picking the true target out of distractors, then a little labeled audio fine-tunes it.

Advanced ~16 min9 steps

What runs in CodeSplash

You will be able to

  • Explain contrastive prediction of future or masked speech features
  • Describe wav2vec 2.0's masking, quantized targets and diversity term
  • Explain why multilingual pretraining reweights languages, and how
  • Say what w2v-BERT adds, and report pretraining and fine-tuning separately

Read first

01

Labels are the bottleneck

Read

A good recognizer needs thousands of hours of transcribed speech, and most of the world's languages don't have that. Untranscribed audio is plentiful. Self-supervised speech representationsSelf-supervised speech representationsPretraining a speech encoder on unlabeled audio by contrast or masked prediction, then fine-tuning it on a little labeled speech. use it: pretrain an encoder on a task the audio sets for itself, then fine-tune on a few hours with transcripts.

The tasks in this lesson are contrastive: the model sees a context and must pick the true target out of distractors, as in contrastive predictive codingContrastive predictive codingLearns by predicting a future representation from a context and picking the true future out of negatives with InfoNCE.. The next lesson covers the other family, masked prediction of discrete targets.

02

wav2vec: predict the near future

Read

The original wav2vec runs convolutions over the raw waveform to get latent frames ztz_t, and more convolutions to summarize the past into a context ctc_t. From ctc_t it must tell the true future frame zt+kz_{t+k} from frames sampled elsewhere, with a logistic loss for each candidate:

−log⁡σ(zt+k⊤Wkct)−∑z~log⁡σ(−z~⊤Wkct).-\log \sigma(z_{t+k}^{\top} W_k c_t) - \sum_{\tilde z} \log \sigma(-\tilde z^{\top} W_k c_t).

With one true future and two distractors, the reference's example gets a loss of 1.616. The learned features then fed a separate supervised recognizer.

Reference · AUD006 · Explained herewav2vec (original)An early self-supervised raw-audio representation learner. Convolutional context representations predict future latent acoustic features against negative samples.
03

wav2vec 2.0: mask, then pick the code

Read

wav2vec 2.0 changed three things. It masks spans of latent frames instead of predicting the future, so a Transformer context network uses both sides. Its targets are quantized: a learned codebook, as in a VQ-VAEVQ-VAEAn autoencoder whose code snaps to the nearest of a fixed set of learned vectors, giving discrete codes instead of Gaussian ones., snaps each unmasked latent to a code. And its loss is InfoNCEInfoNCE lossA loss that asks each row to pick out its own corrupted view among the views of every row in the batch.: at each masked frame, pick the true code among distractors from the same utterance.

A diversity term keeps all codes in use; without it the quantizer can collapse onto a few. In the reference's example, the contrastive part plus a small weight on the diversity term gives 0.341.

Reference · AUD007 · Explained herewav2vec 2.0A self-supervised speech learner that masks latent spans, contextualizes them with a Transformer, and predicts quantized targets.

The contrastive loss on a toy you can train here.

DExplorable · InfoNCE: temperature, negatives, collapse

How does contrastive learning learn useful embeddings without labels, and what keeps it from collapsing?

After training with this objective, where do the embeddings end up?

How sure?
0.20

Batch size

Each item's negatives are the rest of the batch.

Objective

Without labels, a batch can't tell them apart. Off: they're masked out.

0.30
300
0.80

Multiplied by min(τ, 0.15)², so low temperatures take smaller steps.

Simulating…

Commit your prediction above to see the result

Make your prediction first; the figure appears when you commit.

Make your prediction to see the result.

04

Fine-tuning, reported separately

Read

After pretraining, wav2vec 2.0 gets a CTC head and is fine-tuned on transcribed speech: famously, very few hours of labels go a long way. When you read a result, keep the stages apart: which unlabeled audio for pretraining, how many labeled hours for fine-tuning, and which language model at decoding. A recognizer called "self-supervised" still learned to spell from transcripts.

Check the pretraining audio too. If it contains the test recordings or their speakers, the test is no longer clean, even though no labels were used.

05

XLS-R: many languages, reweighted

Read

XLS-R trains the wav2vec 2.0 objective on audio from over a hundred languages at once. Hours per language are wildly unequal, so sampling clips in proportion to hours would mostly teach the biggest languages. Language samplingLanguage sampling (multilingual training)Choosing training text by language with probability proportional to data size^α (α < 1), so rare languages are seen more often. raises each language's hours to a power α\alpha below 1 before normalizing.

With hours of 100, 10 and 1 and α=0.5\alpha = 0.5, the reference's example gives shares of 0.706, 0.223 and 0.071. The one-hour language goes from under 1% of the clips to several percent: seen more often, at the cost of repeating its few hours.

Reference · AUD015 · Explained hereXLS-RA large cross-lingual self-supervised speech representation family based on wav2vec 2.0. Its meaningful distinction is multilingual representation learning at scale, with downstream adaptation to recognition and…
06

w2v-BERT: contrast plus masked tokens

Read

w2v-BERT stacks two objectives. A contrastive module, like wav2vec 2.0's, learns to turn speech into discrete codes. A second module then predicts the codes at masked positions with cross-entropy, as BERT predicts masked words, which pushes it to model longer context.

The reference's example adds half the contrastive loss to a masked cross-entropy and gets 0.626. How the modules share weights, and where gradients stop, belongs to the exact published configuration.

Reference · AUD017 · Explained herew2v-BERTA self-supervised speech model that combines contrastive learning with masked prediction over discrete speech representations.
07

Where it stands in CodeSplash

Read
EntryIn CodeSplash
wav2vec (AUD006)Explained here; superseded by wav2vec 2.0
wav2vec 2.0 (AUD007)Explained here. CodeSplash loads audio but has no wav2vec 2.0 encoder
XLS-R (AUD015)Explained here
w2v-BERT (AUD017)Explained here

CodeSplash's audio embeddings come from the Audio Spectrogram Transformer instead. The four reference programs are component checks, verified in Python and R.

08

Check: contrastive pretraining

Checkpoint

Check yourself

What does the original wav2vec learn to do during pretraining?

Show the answer

Answer: b

It is contrastive prediction of the near future. The features then feed a separate recognizer.

Check yourself

How does wav2vec 2.0's task differ from the original wav2vec's?

Show the answer

Answer: a

Masking plus a Transformer lets the context use past and future; the targets come from a learned quantizer.

Check yourself

Why does wav2vec 2.0 add a diversity term to its loss?

Show the answer

Answer: c

If only a few codes are used, the contrastive task becomes trivial and the targets carry little information.

Check yourself

A report says "our self-supervised wav2vec 2.0 recognizer reaches a low error rate." What should it also state?

Show the answer

Answer: b

Pretraining is self-supervised; fine-tuning with CTC uses transcripts. Both stages, and any language model, shape the result.

Check yourself

XLS-R samples languages with shares proportional to hoursα\text{hours}^{\alpha}, α<1\alpha < 1. What does lowering α\alpha do?

Show the answer

Answer: b

At α=1\alpha = 1 shares follow the hours; at α=0\alpha = 0 every language is equal. Lower values repeat the small languages' audio more.

Check yourself

What is XLS-R?

Show the answer

Answer: a

The model family is one method; its different sizes aren't separate methods.

Check yourself

Which two objectives does w2v-BERT combine?

Show the answer

Answer: b

The contrastive part makes good tokens; the masked, BERT-like part learns longer context over them.

Check yourself

A pretrained speech encoder was trained on a large web crawl of audio. Why can that matter for your test set even though no labels were involved?

Show the answer

Answer: b

Leakage is about what the model has seen, labeled or not. Check overlap between pretraining audio and your test.

09

Recap

Recap
  • Contrastive pretraining picks the true target among distractors; wav2vec predicts the future, wav2vec 2.0 masked codes.
  • A diversity term keeps wav2vec 2.0's codebook in use; fine-tuning with CTC adds transcripts.
  • XLS-R reweights languages with an exponent below 1; w2v-BERT adds masked prediction of codes.
  • Report pretraining audio, labeled hours and decoding separately; all four are explained here.

Concepts in this lesson