Speech recognition as sequence to sequence
Whisper turns audio into text with an encoder–decoder transformer. The encoder reads 30 seconds of sound as a log-mel spectrogram and turns it into 1,500 vectors, one for every 20 ms. The decoder writes text one token at a time and reads the audio through cross-attention. A few special tokens at the start of the decoder's input name the language and the task.
This page records Whisper base on a 2.04-second clip from LibriSpeech whose reference text is WHERE IS MY BROTHER NOW. The model has 6 encoder blocks and 6 decoder blocks of width 512, each with 8 heads of 64, and 72,593,920 parameters. Decoding greedily, it writes Where is my brother now?
From waveform to log-mel spectrogram
Whisper's input is always 30 s of audio at 16 kHz, so the clip's 32,640 samples are padded with zeros to 480,000. A short-time Fourier transform with a 400-sample (25 ms) Hann window, moved 160 samples (10 ms) at a time, gives 3,000 frames of 201 frequency bins. A bank of 80 filters spaced on the mel scale, which follows perceived pitch rather than frequency, sums the power spectrum into 80 bands. A logarithm, a floor 8 below the maximum and a fixed rescaling compress the range:
The Audio card draws the waveform and the spectrogram with time running down; its Log-mel button opens these steps. Speech fills 204 frames, and every frame from 206 on sits at the floor value. The page compresses those 27.8 s of padding into one hatched box.
Convolution stem and positions
Two 1-D convolutions of kernel 3, each followed by a GELU, turn the 80 mel bands into 512 channels. The second has stride 2, so 3,000 frames of 10 ms become 1,500 positions of 20 ms, each depending on 5 neighbouring mel frames. A fixed sinusoidal vector is then added at each position :
This table is not learned, and it is the encoder's only position signal: the attention scores have no position term.
Encoder self-attention over 30 seconds
The encoder is bidirectional. Each of the 1,500 positions attends to all 1,500 with scores and no mask. Only 102 positions hold speech; the other 1,398 hold padding, and the encoder attends to them as well. Each block then applies an MLP, 512 → 2048 → 512 with GELU, with a LayerNorm before each step and a residual connection around it.
A 1,500 × 1,500 matrix does not fit on screen, so Multi-head Self Attention shows it in 0.2 s bins: 11 bins of 10 positions over the first 2.2 s and one bin for the remaining 27.8 s. A binned row is the mean of its query rows and a binned column sums the attention over its keys, so every row still sums to 1.
The decoder and cross-attention
The decoder starts from four special tokens, written on the page SOT, EN, TRANSCRIBE and NO-TS: start of transcript, English, transcribe rather than translate, and no timestamps. Each token gets a learned position vector, and Masked Self Attention lets it read only itself and earlier tokens. Cross Attention then reads the audio. Its queries come from the decoder, and its keys and values from the encoder's final hidden state at all 1,500 positions, with no mask:
The thin trace beside the spectrogram shows where the selected token's cross-attention falls along every 20 ms position, and how much of it goes to the padding. After 6 decoder blocks the hidden state is scored against all 51,865 vocabulary entries by the token embedding matrix itself (tied weights). Probabilities shows the result at the selected token; after brother the most likely next token is now. Greedy decoding appends the most likely token each time until the end-of-text token.
Where Whisper came from
Attention-based encoder–decoders for speech go back to Listen, Attend and Spell (Chan et al., 2015), which used recurrent layers; the Speech-Transformer (Dong et al., 2018) replaced them with self-attention. Self-supervised encoders such as wav2vec 2.0 (Baevski et al., 2020) learned from unlabelled audio and were then fine-tuned with labelled data for each task. Whisper (Radford et al., 2022) instead trained an ordinary transformer encoder–decoder on 680,000 hours of transcribed audio collected from the web, with the task named by special tokens, and showed that it transcribes well without fine-tuning.
The Encoder–decoder tab draws T5 with the same components, and the Tokenization explainer's Whisper tab looks more closely at the log-mel frames and the text tokens.
Papers
- Robust Speech Recognition via Large-Scale Weak Supervision Whisper, the model this page records: the log-mel front end, the convolution stem, the encoder–decoder and the special-token task format.
- Attention Is All You Need The encoder–decoder transformer with cross-attention and sinusoidal positions that Whisper uses almost unchanged.
- Listen, Attend and Spell An early attention-based encoder–decoder that maps filter-bank features of speech straight to characters.
- Speech-Transformer: A No-Recurrence Sequence-to-Sequence Model for Speech Recognition Replaces the recurrent layers of attention-based speech recognition with self-attention.
- wav2vec 2.0: A Framework for Self-Supervised Learning of Speech Representations Self-supervised speech encoders fine-tuned for recognition, the approach Whisper's weakly supervised training is compared with.
- Librispeech: An ASR corpus based on public domain audio books The corpus of the clip on this page, dev-clean 1272-135031-0012.
- A Scale for the Measurement of the Psychological Magnitude Pitch The mel scale, which spaces Whisper's 80 filters by perceived pitch.