Speech Recognition
Spectrograms, CTC and sequence-to-sequence models.
CTC sums over an exponential number of alignments in time, and its gradient has a one-line form: the network's output minus the posterior probability of each symbol at each frame. This lesson derives both, then the transducer lattice that removes CTC's independence assumption, and asks what large-scale weak and self-supervision did and did not solve.
What you’ll learn
- Define CTC precisely, derive its forward recursion over the blank-extended label sequence, and state when a transcript is feasible.
- Prove that the CTC gradient with respect to the logits is the softmax output minus the forward–backward occupancy, and explain CTC's spiky posteriors.
- Derive the transducer's lattice recursion, count its alignments, and compare transducers with CTC and attention decoders.
- Explain how self-supervised and weakly supervised scaling changed robustness, and how to compare recognizers with WER responsibly.
CTC, precisely
Let be the total probability of path prefixes that are consistent with and sit at position of at frame . A valid path starts with a blank or with the first label:
At frame , a path at position came from (repeating the symbol), from (advancing) or from (skipping the blank between two labels). The skip is forbidden when is a blank, which can only be entered from the label before it, or when , since without the blank the two copies would merge:
A valid path ends on the last label or on the final blank:
Correctness follows by induction on : the three predecessor cases partition the valid prefixes ending at . The cost is (at most three terms per state and frame), computed in log space or with per-frame rescaling, as for HMMs. It is the HMM forward algorithm on a left-to-right chain whose emission probabilities change with (HMM Algorithms).
Feasibility. Each adjacent pair of identical labels needs a blank between them, so a path exists only if , where counts the adjacent repeats in ; otherwise and the loss is infinite. Encoders that downsample time, to 25 or even 12.5 frames per second, must respect this for every training transcript, one reason they predict subword units rather than characters.
What is the smallest number of frames for which CTC can output the 10-letter label ?
- 10
- 13
- 21
- 11
Show the answer
B. 13
The repeats , and each need a separating blank, so , for example . Blanks are needed only between identical neighbors.
The gradient, and why CTC spikes
Define backward variables as the total probability of the path suffixes that complete the labeling from position at frame , excluding frame 's own factor; they obey the mirror-image recursion. Every valid path occupies exactly one position at each frame, so for every . (In Graves et al.'s convention also includes , and the identity carries a division by .)
is the total probability of the valid paths at position at frame . Each contains the factor exactly once, and several positions can carry the same symbol (all blanks; repeated labels), so:
Chain through the softmax, , and use :
Negate. Compare cross-entropy against a fixed forced alignment, as in hybrid systems, whose gradient is : CTC replaces the hard alignment by its posterior, as EM does for HMMs.
Spikes. Trained CTC models output blank on most frames and each label as a sharp spike about one frame wide (observed by Graves et al., 2006; analyzed by Zeyer, Schlüter & Ney, 2021). The gradient explains the drift: the occupancy favors paths that are already probable, and since the blank can fill any frame between labels, mass flows toward "blank everywhere except one frame per label". Spike positions need not match the acoustic boundaries of the sounds, which matters when CTC is used for timing or forced alignment.
Decoding. The most probable labeling, , sums over many paths per candidate, so decoders run a prefix beam search that keeps, for each prefix, the probability of the paths ending in a blank and of those ending in its last label, adding a language-model score ("shallow fusion"). Best-path decoding, the argmax at each frame, is a fast approximation.
Transducers and attention
The transducer (RNN-T; Graves, 2012) keeps CTC's monotonic alignment but lets each output depend on the previous ones. An encoder produces for ; a prediction network, a small autoregressive model over labels, produces from for ; and a joint network gives a distribution over at every lattice point, . Emitting the next label moves ; emitting a blank moves to the next frame, .
Write and . Let be the probability of having emitted by the time frame is being read, with . A path reaches either by a blank from or by a label from :
Every alignment ends with a blank at the last lattice point:
An alignment is a string of blanks and labels whose last symbol is a blank, so the recursion sums over exponentially many alignments in steps:
How many distinct alignments does a transducer sum over for frames and labels?
Show the answer
10
Place the 2 labels among the first emission slots, the sixth being the final blank: . Enumerating monotonic lattice paths from to gives the same count.
The recursion is cheap, but the joint network must be evaluated at all lattice points, producing a tensor of logits, the main memory cost of transducer training; pruned and fused implementations attack it. Because emission never waits for audio beyond the current frame (plus whatever look-ahead the encoder allows), transducers with Conformer encoders (Gulati et al., 2020) are a standard choice for streaming, on-device recognition as of the mid-2020s.
Attention encoder–decoders (Listen, Attend and Spell; Chan et al., 2016) drop the monotonicity constraint and model with attention over the whole encoded utterance. That flexibility makes them accurate, but they cannot emit before the input ends, and on long or noisy inputs attention can repeat, skip, or continue past the end of the speech. Joint CTC–attention training and decoding (Kim, Hori & Watanabe, 2017) uses CTC's monotonic alignment to keep the attention on track. Whisper is an attention encoder–decoder applied to 30-second windows.
Scale, supervision and measurement
Transcribed speech is expensive, so the field found supervision elsewhere. Self-supervised models learn from unlabeled audio: wav2vec 2.0 (Baevski et al., 2020) masks spans of latent speech features and identifies the true quantized feature among distractors with a contrastive loss (contrastive learning), and HuBERT (Hsu et al., 2021) predicts -means cluster labels of the masked frames. Fine-tuned with CTC, such models gave usable recognizers from very little transcribed speech.
Weak supervision takes noisy labels at scale instead. Whisper (Radford et al., 2023) trained on 680,000 hours of internet audio with its transcripts, filtering out transcripts that looked machine-generated. Its central finding concerns distribution shift: models trained on LibriSpeech reach low WER there but degrade much more on other datasets than zero-shot Whisper, which never saw LibriSpeech's training set. Robustness tracked the breadth of the training distribution more than the fit to any one benchmark.
Comparing systems. Corpus WER is a ratio of totals, , not an average of per-utterance rates. If word errors were independent with rate , the standard error over reference words would be : for and , about percentage points. But errors cluster within utterances and speakers, so the real uncertainty is larger, and differences should be tested with paired tests over utterances or speakers, such as the matched-pairs test of NIST evaluations (Gillick & Cox, 1989) or a bootstrap over utterances (Bisani & Ney, 2004).
WER also weighs every word alike. A transcript with 3% WER that gets every name and number wrong may be useless, so applications add entity or semantic error measures. And averages hide subgroups: accuracy varies across dialects, accents, ages and speech impairments (algorithmic bias), so per-group WER belongs in any serious evaluation.
Key takeaways
- CTC sums over alignments with a forward recursion over the positions of the blank-extended label, skipping blanks only between distinct labels; it costs and needs frames.
- The CTC gradient with respect to the logits is , output minus forward–backward occupancy, an EM-like target that drives the characteristic blank-dominated, spiky posteriors.
- Transducers add a prediction network and sum over monotonic alignments in steps, at the memory cost of a joint tensor; attention decoders drop monotonicity and need the whole input, and joint CTC–attention combines the two.
- Self-supervised pretraining (wav2vec 2.0, HuBERT) and weak supervision at scale (Whisper's 680,000 hours) made recognizers far more robust under distribution shift.
- Corpus WER is a ratio of totals; compare systems with paired tests over utterances or speakers, and report subgroup results, since errors cluster and fall unevenly.
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
In the CTC forward recursion, when is the transition from position to position of forbidden?
- Never: skips are always allowed
- When is a blank, or when
- Only at the last frame
- Whenever is a label
Show the answer
B. When is a blank, or when
A blank position is entered only from the label before it (or from itself), and skipping the blank between two identical labels would merge them into one. Between distinct labels the blank is optional, so the skip is allowed.
What is , the gradient of the CTC loss with respect to frame 's logit for symbol ?
- , where is the posterior probability that the path emits at frame
Show the answer
C. , where is the posterior probability that the path emits at frame
, and the softmax Jacobian turns this into for ; the loss is its negative. Outputs above their occupancy are pushed down, those below pushed up.
Why do transducers suit streaming recognition while attention encoder–decoders do not, natively?
- Transducers emit labels as frames arrive, along a monotonic alignment; attention decoders attend over the whole encoded utterance before emitting
- Transducers have no prediction network, so they run faster
- Attention decoders cannot model dependencies between output labels
- Transducers do not need a blank symbol
Show the answer
A. Transducers emit labels as frames arrive, along a monotonic alignment; attention decoders attend over the whole encoded utterance before emitting
In the lattice, each blank advances one frame and labels are emitted while frame is current, so output can follow the audio with bounded delay. An attention decoder's first output already conditions on the entire input sequence.
On a test set of 2,000 utterances (40,000 words), system A has 8.0% WER and system B 7.8%. What should you do before claiming B is better?
- Nothing: lower WER is better
- Compute points and conclude that the gap is significant
- Average the per-utterance WERs instead, which removes the noise
- Run a paired test over utterances or speakers, such as matched pairs or a bootstrap, because errors are correlated within utterances
Show the answer
D. Run a paired test over utterances or speakers, such as matched pairs or a bootstrap, because errors are correlated within utterances
A 0.2-point gap is about 80 words in 40,000. Because errors cluster by utterance and speaker, the binomial formula understates the uncertainty; a paired test over the same utterances accounts for both the correlation and the shared difficulty.
Further reading
- A. Graves, S. Fernández, F. Gomez & J. Schmidhuber, "Connectionist temporal classification: Labelling unsegmented sequence data with recurrent neural networks," ICML (2006).
- A. Graves, "Sequence transduction with recurrent neural networks," arXiv:1211.3711 (2012).
- W. Chan, N. Jaitly, Q. Le & O. Vinyals, "Listen, attend and spell: A neural network for large vocabulary conversational speech recognition," ICASSP (2016).
- A. Radford, J. W. Kim, T. Xu, G. Brockman, C. McLeavey & I. Sutskever, "Robust speech recognition via large-scale weak supervision," ICML (2023).
- D. Jurafsky & J. H. Martin, Speech and Language Processing, chapter on automatic speech recognition and text-to-speech (3rd ed. draft).