Skip to content

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.

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 10−410^{-4} 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.

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.

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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.