Large Models & Agents/Speech Recognition: Front-Ends and Alignment

Lesson 11.52,645 words

Speech Recognition: Front-Ends and Alignment

Speech is a long, high-rate sequence whose label is short and unaligned, so the whole subject turns on bridging that mismatch. This first part builds the spectral front-ends that compress a waveform into frames (STFT, mel spectrogram, MFCC, with a worked frame-count), derives CTC's marginalization over alignments and its forward-backward recursion with a two-frame numeric example, and contrasts it with attention-based seq2seq (LAS) and the RNN transducer.

╌╌╌╌

Text arrives pre-tokenized; speech does not. A spoken utterance is a pressure wave sampled tens of thousands of times a second, and the transcript it corresponds to is a handful of characters whose boundaries are nowhere marked in the signal. Automatic speech recognition (ASR) is the problem of mapping the long acoustic sequence to the short label sequence with and no given alignment between them.1 Everything specific to the field, the spectral front-ends, the CTC loss, the transducer, follows from that one structural fact.

Three numbers define the problem. The input rate is high (tens of thousands of samples a second), the output rate is low (a few characters a second), and the map between them is unknown. A ten-second clip at is samples; its transcript is maybe characters. No dataset tells you that samples through spell the word cat. A supervised frame-classifier would need exactly that annotation, and it does not exist at scale. The three model families in this lesson (CTC, attention seq2seq, and the transducer) are three ways to train through the missing alignment, and the representation learning at the end (wav2vec 2.0, HuBERT, Whisper) is three ways to train when even the transcript is scarce or noisy.

Audio as a sequence

A microphone produces a continuous pressure signal; sampling it at rate yields a discrete waveform . The Nyquist theorem fixes the floor on : to represent content up to frequency without aliasing, . Human speech carries information up to roughly , so telephone audio samples at and wideband speech at .

The consequence is severe length. A ten-second utterance at is samples, against a transcript of perhaps a hundred characters: a ratio of more than . A single sample carries almost no linguistic content; what matters is the local frequency content of the signal, how energy is distributed across pitches in a short window, and that is invisible in the raw amplitude. Two utterances of the same word, one high-pitched and one low, share almost no samples in common yet must map to the same characters. Feeding raw scalars to a network is both wasteful (the sequence is too long for attention, which costs ) and statistically hard (the network must rediscover the Fourier basis from scratch), which is why classical and modern systems alike first transform the waveform into a time-frequency representation.

The transform trades one long axis for two shorter ones. Instead of samples on a single time axis, a spectrogram is roughly frames on a time axis by a few hundred bins on a frequency axis. The frame rate ( frames/s) is now only about the character rate rather than , and each frame is a rich vector describing the energy at every pitch, exactly the cue a phoneme classifier needs.

RepresentationRate / size (10 s, 16 kHz)CapturesUsed by
Raw waveform samplesamplitude vs. timewav2vec 2.0 encoder
STFT magnitude frames 257 binslinear-frequency energyspectrogram models
Mel spectrogram frames 80 binsperceptual-frequency energyWhisper, most ASR
MFCC frames 13 coeffsdecorrelated spectral envelopeclassical HMM-GMM

Reading the table top to bottom is the front-end pipeline: each row is the previous row after one more transform, and each transform trades length or channel count for a more compact, more linguistically salient description. The figure below tracks the tensor shape through every stage for the running ten-second, clip.

Tensor shapes through the front-end for a 10 s, 16 kHz clip. The waveform's single long time axis (160,000) becomes a short time axis of frames times a frequency axis, which the mel filterbank then narrows from 257 bins to 80.

Spectral front-ends

The core tool is the short-time Fourier transform (STFT): chop the waveform into overlapping frames, window each, and take its discrete Fourier transform. Frame starts at hop and spans a window of length ; its spectrum at frequency bin is

The window (Hann or Hamming) tapers each frame to zero at its edges, suppressing the spectral leakage a hard cutoff would introduce. Chopping the signal into frames is itself a multiplication by a rectangular window, and in the frequency domain multiplication becomes convolution with the window's spectrum. A rectangle's spectrum is a with tall side-lobes, so a rectangular frame smears each true tone across many bins. The Hann window has a far more compact spectrum, so its convolution keeps each tone concentrated near its own bin. The spectrogram is the magnitude , a two-dimensional image with time on one axis and frequency on the other.

The frame count follows from the hop, not the window. With hop the number of frames is . For the running clip, , , give frames, i.e. the frames per second promised above. Real-valued input makes the DFT conjugate-symmetric, so only of the bins are unique; a common choice of a -point FFT on the -sample window (zero-padded) yields bins, the number in the shape figure. The window sees of audio, long enough to resolve pitch yet short enough that the vocal tract is roughly stationary across it, the compromise the ms defaults encode.

The front-end pipeline: a waveform is framed with overlap, each frame is windowed and Fourier-transformed, and the stacked magnitudes form a spectrogram.

Mel scale and MFCCs

The linear frequency axis of the STFT wastes resolution: human pitch perception is roughly logarithmic, finely resolving low frequencies and coarsely resolving high ones. The mel scale warps hertz to a perceptual axis,

where the constants are chosen so and the map is nearly linear below and logarithmic above. The warp is what a listener hears: the perceived jump from to (one octave, mel , a gap of ) is close to the jump from to (also an octave, mel , a gap of compressed onto far fewer bins), so equal musical intervals map to comparable mel distances while the raw hertz gap grows tenfold. A bank of triangular filters, equally spaced in mel, sums STFT energy into (typically ) perceptual bands. The mel spectrogram is the log of those band energies,

where is the -th triangular filter. The filters are narrow and dense at low frequency and broad and sparse at high frequency, the signature of the logarithmic mel warping.

A mel filterbank: triangular weights, narrow at low frequency and broad at high, sum STFT energy into perceptual bands spaced evenly on the mel axis.

Taking a discrete cosine transform of and keeping the low-order coefficients gives the MFCCs (mel-frequency cepstral coefficients), a compact, decorrelated descriptor of the spectral envelope that dominated ASR front-ends for decades.2

StageOperationOutput dim per frame
STFTwindowed DFT, magnitude
Mel filterbanktriangular bands on mel axis
Logcompress dynamic range
DCT (truncated)decorrelate, keep low orders (MFCC)

The alignment problem

After the front-end, the input is a frame sequence at roughly frames per second; the target is a label sequence over an alphabet of characters or word-pieces. Three facts define the difficulty.

A frame-level classifier needs a label per frame, but the data gives only the unaligned transcript. The classical solution was a hidden Markov model with forced alignment; the modern solutions, CTC, attention seq2seq, and the transducer, learn the alignment as a latent variable instead.

Connectionist temporal classification

CTC sidesteps alignment by introducing a special blank symbol and marginalizing over every alignment consistent with the target.3 Let the network emit, at each frame , a distribution over the augmented alphabet . A path (or alignment) is one label per frame. The collapse map turns a path into a label sequence by first merging adjacent duplicates, then deleting blanks.

The blank is what lets a path emit the same label twice in a row (separate the two by a blank) and what absorbs the silence and over-sampling between labels. The probability of a target is the total probability of all paths that collapse to it.

The sum is over exponentially many paths, so the definition is not directly computable. The saving structure is that is a left-to-right, monotonic map, which makes the marginal a dynamic program identical in form to the HMM forward algorithm.

The CTC lattice for target "cat". Each column is a frame; blue dots mark the blank-augmented label states a monotone path may occupy, with allowed moves.

The forward-backward recursion

Expand the target with blanks into of length . The forward variable is the total probability of all paths that have consumed the first frames and sit at position in :

Monotonicity restricts the moves into state to three: stay at , step from , or skip from (the skip is permitted only when is a non-blank label distinct from , so two identical letters cannot be merged).

The recursion fills a table in time. The gradient of with respect to the network's frame logits is obtained from a symmetric backward variable , exactly as in the HMM Baum-Welch algorithm. The two variables combine into the posterior occupation , the probability that a path sits at state on frame . Summing over the states that emit a given label gives the soft target the network is pulled toward, and the gradient of the loss with respect to the pre-softmax logit for at frame is the difference

softmax-output minus soft-alignment target, the same shape as an ordinary cross-entropy gradient with the CTC forward-backward supplying the target.

Algorithm:CtcForward(P,y)\textsc{CtcForward}(P, y) — marginal likelihood of target yy over all alignments
  1. 1
    y(blank,y1,blank,,yU,blank)y' \gets (\text{blank}, y_1, \text{blank}, \dots, y_U, \text{blank}); S2U+1S \gets 2U+1
    blank-expand
  2. 2
    α1(1)P1(blank)\alpha_1(1) \gets P_1(\text{blank}); α1(2)P1(y1)\alpha_1(2) \gets P_1(y_1)
    seed first frame
  3. 3
    for s3s \gets 3 to SS do α1(s)0\alpha_1(s) \gets 0
  4. 4
    for t2t \gets 2 to TT do
  5. 5
    for s1s \gets 1 to SS do
  6. 6
    aαt1(s)+αt1(s1)a \gets \alpha_{t-1}(s) + \alpha_{t-1}(s-1)
    stay or step
  7. 7
    if ysblanky'_s \neq \text{blank} and ysys2y'_s \neq y'_{s-2} then
    skip allowed across blank
  8. 8
    aa+αt1(s2)a \gets a + \alpha_{t-1}(s-2)
  9. 9
    αt(s)Pt(ys)a\alpha_t(s) \gets P_t(y'_s) \cdot a
    emit current symbol
  10. 10
    return αT(S)+αT(S1)\alpha_T(S) + \alpha_T(S-1)
    accept on final label or trailing blank

In practice the recursion runs in log-space with a log-sum-exp to avoid underflow, and the per-frame distribution comes from a softmax over an encoder, an LSTM/GRU stack in the original deep-speech systems4 and later a deep CNN or Transformer encoder.5

Sequence-to-sequence ASR

An alternative drops the blank and the marginalization entirely and treats ASR as ordinary conditional generation: an encoder reads the frames, and an attention decoder emits labels autoregressively, . The canonical instance is Listen, Attend and Spell (LAS).6

Because the decoder conditions each label on all previous labels, the model carries its own implicit language model, the structural advantage over CTC. The cost is that the soft attention is unconstrained: nothing enforces the monotonic, left-to-right alignment that speech actually obeys, so early attention models could attend out of order or skip ahead, especially on long utterances. Two pathologies result. Looping: the decoder re-attends a region it already transcribed and repeats a word. Skipping: attention jumps past a span and drops words. Both show up as high word-error rate on long inputs and were mitigated by adding a monotonic-attention penalty or by training with a joint CTC loss whose monotone lattice regularizes the attention alignment.

Attention seq2seq ASR dataflow. The encoder turns T mel frames into T' states (pyramid or strided down-sampling); at each step the decoder attends over all encoder states and emits the next label from its own history.

The third option, the RNN transducer (RNN-T), keeps CTC's blank-driven, monotonic, streaming structure but adds a prediction network over previous labels, so the output distribution depends on emission history while alignment stays strictly left-to-right. Where CTC scores one label per frame, the transducer scores a joint distribution over the next symbol given both the acoustic step and the label position , and its lattice is a two-dimensional grid: emit a blank to advance time, emit a label to advance . The forward-backward marginalization over this grid is the transducer analogue of the CTC recursion, still , but now the label history conditions every emission through the prediction network. This combines CTC's streaming and monotonicity with the attention decoder's implicit language model, at a heavier training cost (the joint network materializes a tensor). It is the dominant choice for on-device, streaming ASR.

PropertyCTCAttention seq2seq (LAS)RNN transducer
Alignmentmonotone, marginalizedsoft, learned, unconstrainedmonotone, marginalized
Label dependencenone (frame-independent)full ()on previous labels
Streamingyesno (needs full input)yes
External LM at decodeusually neededoptionaloptional
Failure modeweak language modelmisalignment on long audioheavier to train

This continues in Self-Supervised Speech Models and Synthesis, which trains the same encoders without transcripts (wav2vec 2.0, HuBERT), scales weak supervision to hundreds of thousands of web hours (Whisper), and runs the whole length mismatch backwards for text-to-speech.

Takeaways

  • Audio is a long, high-rate sequence: mono is samples per second, roughly longer than its transcript, and a single sample is linguistically meaningless, so systems first compute a time-frequency front-end.
  • The STFT frames and Fourier-transforms the waveform; the mel spectrogram warps frequency to the perceptual mel axis and takes a log; a truncated DCT yields the classical MFCCs. The frame count follows the hop, not the window: .
  • The defining difficulty is alignment: , with the frame-to-label map unknown, monotonic, and many-to-one.
  • CTC adds a blank symbol and a collapse map , then marginalizes via an forward-backward recursion (the two-frame example gives by both the recursion and direct path enumeration); it assumes per-frame independence and so leans on an external language model.
  • Attention seq2seq (LAS) generates labels autoregressively with an implicit language model but an unconstrained alignment (looping, skipping); the RNN transducer keeps CTC's monotone streaming structure while adding label-history dependence, the dominant on-device choice.

Footnotes

  1. Goodfellow, Deep Learning, §12.3 — Speech Recognition: mapping an acoustic frame sequence to a word sequence, the move from HMM-GMM systems to deep acoustic models, and the role of CTC.
  2. Chollet, Deep Learning with Python, Ch. 11 — sequence models for non-text modalities: spectrogram and log-mel front-ends as the standard fixed feature representation feeding 1-D conv and recurrent acoustic models.
  3. Graves et al., Connectionist Temporal Classification: Labelling Unsegmented Sequence Data with Recurrent Neural Networks, ICML 2006 — the blank symbol, the collapse map, and the forward-backward marginalization over alignments.
  4. Graves & Jaitly, Towards End-to-End Speech Recognition with Recurrent Neural Networks, ICML 2014 (Graves 2013 deep-RNN line) — deep bidirectional LSTM acoustic models trained directly with CTC, end-to-end from spectrogram to characters.
  5. Amodei et al., Deep Speech 2: End-to-End Speech Recognition in English and Mandarin, ICML 2016 — a deep conv-plus-recurrent CTC system scaled across languages with heavy data and compute.
  6. Chan et al., Listen, Attend and Spell, ICASSP 2016 — a pyramidal BiLSTM listener and an attention-based character speller, an alternative to CTC that learns the alignment as soft attention.

╌╌ END ╌╌