Chapter 15: Speech Recognition
This chapter teaches the system to hear. By its end, a WAV file uploaded to the gateway becomes a list of timestamped transcript segments, produced by a published Whisper checkpoint whose logits match Hugging Face’s, and those transcripts can be scored with error rates and confidence intervals that match what papers report.
Concepts from other sections (17)
This section uses these ideas. Each has a short definition and a link to the section that explains it in full. Tap a dotted term in the text to preview it.
- logits: unnormalized log-scores that softmax turns into probabilities; here the table stores . Read more: 6.1 Byte bigram: counts, logits, safetensors v0
- Confidence interval: a procedure that, over repeated samples, produces intervals covering the fixed true parameter at the stated rate. Read more: 13.11 Probability problem set, part c: limit theorems and confidence intervals in Mathematics
- Log-mel: Whisper’s features, of the mel spectrogram with a floor, an 8-unit clip, and the map . Read more: 18.6 Mel scale and filterbanks in Mathematics
- control prompt: the explicit
[sot, language, task]sequence, plusno_timestampswhen timestamps are off, that tells Whisper what to do. Read more: 15.4 Whisper decoding and long-form transcription - temperature fallback: retrying a window at hotter temperatures when output is repetitive or low-confidence. Read more: 15.4 Whisper decoding and long-form transcription
- word error rate (WER): pooled substitutions, deletions and insertions divided by the total reference word count. Read more: 15.5 Multimodal eval metrics: WER, CER, VQA, captions, zero-shot
- character error rate (CER): the same rate computed over the characters of the stripped strings, spaces included. Read more: 15.5 Multimodal eval metrics: WER, CER, VQA, captions, zero-shot
- STFT: the DFT of overlapping windowed frames, giving a spectrum per time step. Read more: 18.5 Sampling, Nyquist, windows, and the STFT in Mathematics
- Mel filterbank: a matrix of triangular filters on mel-spaced edges that pools an rfft power spectrum into bands. Read more: 18.6 Mel scale and filterbanks in Mathematics
- positional encoding: a vector depending only on position, added to the token embedding so attention can see order. Read more: 11.4 Positional encodings: sinusoidal, learned
- KV cache: per-layer storage of past keys and values, so each decode step processes only the new token. Read more: 21.2 The KV cache, incremental decoding, and generate
- beam search: keeping the best prefixes by summed log-probability, ranking all extensions together at each step. Read more: 10.4 Beam search, generic over a step function
- Byte-level: the base alphabet is the 256 bytes (through the byte map), so every text encodes and there is no unknown token. Read more: 7.2 Byte-level BPE
- RIFF chunk: a
<4-byte id> <u32 size> <payload>record, followed by a pad byte when the size is odd. Read more: 15.1 Audio frontend: WAV parsing and Whisper’s log-mel - Self-attention: a layer in which each position computes a weighted average of all positions’ values, weighted by query-key similarity. Read more: Chapter 2: Deep Learning
- cross-attention: attention whose queries come from the decoder and whose keys and values come from the encoded audio window, with no mask. Read more: 15.3 Whisper decoder and checkpoint weights
- tie rule: the fixed backtrace preference (diagonal, deletion, insertion) that makes the S, D, I split deterministic. Read more: 15.5 Multimodal eval metrics: WER, CER, VQA, captions, zero-shot
The arc follows the data. You start with raw bytes: a WAV parser that treats every size field as a claim to verify, and Whisper’s exact log-mel recipe, where one frame too many or a symmetric window quietly degrades every transcript. Then comes the model, in two halves. The encoder looks at a 30 second window once and produces 1500 vectors; the decoder compares a text prefix with those vectors and predicts the next token, with a loader that checks the checkpoint strictly. Logits are not yet a transcript, so the fourth section builds the transcription policy: control prompts, the timestamp grammar, greedy, beam and sampled search, temperature fallback, silence skipping, and seeking through recordings longer than one window. The chapter closes with the metrics that judge all of this, and the vision models of the previous chapter too: WER, CER, VQA accuracy, caption scores and zero-shot accuracy.
A thread runs through every section: match a published reference exactly, and refuse anything that would silently compute something else. Transcripts generated by the model are kept separate from teacher-forced model diagnostics throughout.
Learning objectives
- Parse WAV files defensively and compute Whisper’s log-mel features within of the reference.
- Build Whisper’s encoder and decoder so that a published checkpoint loads by name and reproduces Hugging Face’s logits.
- Explain and implement Whisper’s transcription policy, from the control prompt to long-form seeking.
- Score transcripts and vision outputs with WER, CER, VQA, caption and zero-shot metrics, each with a reproducible bootstrap interval.
Before you begin
Section titled “Before you begin”The signal processing comes from chapter 12 of Mathematics, Signals and images: resampling, the STFT and the mel filterbank. The convolution layers come from Vision foundations, attention and positional encodings from The Transformer (2017), and the KV cache from Inference. Beam search and sequence metrics come from Attention origins, and the byte-level BPE tokenizer from Tokenizers.
In this chapter
Section titled “In this chapter”- Audio frontend: WAV parsing and Whisper’s log-mel. Walk RIFF chunks safely, decode s16, s24 and f32 samples, and turn any clip into the exact mono, 16 kHz, 30 second log-mel picture Whisper was trained on.
- Whisper encoder: conv stem, sinusoids, pre-LN blocks. Build the encoder from familiar parts and learn the three small conventions that decide whether a checkpoint’s weights compute anything meaningful.
- Whisper decoder and checkpoint weights. Add causal self-attention with a cache and cross-attention over the audio window, and load Hugging Face checkpoints strictly, sharded files included.
- Whisper decoding and long-form transcription. Turn logits into timestamped segments with an explicit control prompt, the timestamp state machine, search, fallback and seeking, all behind a seam that lets recorded logits replace the model.
- Multimodal eval metrics: WER, CER, VQA, captions, zero-shot. Define and implement the metrics that judge speech and vision outputs, with a pinned alignment tie rule and item-level bootstrap intervals.