wav2vec 2.0 consists of the following three components. The left side of the figure at the top of the article shows the overall pretraining flow; the right side shows the training task at a masked time step and the inside of the quantization module.
| Component | Input â output | Contents |
|---|
| Feature encoder f | Waveform X â latent representations z1â,âŠ,zTâ | Seven blocks of 1D convolution (each block: convolution â layer normalization â GELU) |
| Context network g | Z â context representations c1â,âŠ,cTâ | Transformer. Positional information is injected by a convolution instead of fixed positional encodings |
| Quantization module | ztâ â quantized representation qtâ | Selects one entry from each of two codebooks, concatenates them, and applies a linear transformation |
The feature encoder takes a 16 kHz waveform normalized to zero mean and unit variance. All seven convolutions have 512 channels, with strides (5, 2, 2, 2, 2, 2, 2) and kernel widths (10, 3, 3, 3, 3, 2, 2). The strides multiply to 320, so one vector is produced roughly every 20 ms (49 Hz), and each vector covers 400 samples (25 ms) of audio.
The context network is a stack of Transformer layers. The output of a convolution with kernel width 128 and 16 groups, passed through a GELU, is added to the input, followed by layer normalization. This convolution provides cues about relative position. The two model sizes in the paper are as follows.
| Model | Transformer layers | Model dimension | Feed-forward inner dimension | Heads | Parameters |
|---|
| BASE | 12 | 768 | 3,072 | 8 | 95M |
| LARGE | 24 | 1,024 | 4,096 | 16 | 317M |
The quantization module replaces the continuous ztâ with a combination of a finite number of "speech units". There are G=2 codebooks, each with V=320 entries. One entry is chosen from each codebook and concatenated, giving up to 3202=102,400 combinations. Which entry to choose is decided by applying a Gumbel softmax to logits lg,vâ computed from ztâ.
pg,vâ=âk=1Vâexp((lg,kâ+nkâ)/Ï)exp((lg,vâ+nvâ)/Ï)â
n=âlog(âlogu) (where u is uniform on 0â1) is Gumbel noise, and Ï is the temperature. The forward pass picks the single entry with the highest probability, while the backward pass uses the gradient of the softmax output (the straight-through estimator). This makes the whole model trainable by gradients even though it contains a discrete "selection" step.