Encoder-Decoder ASR
The model hears the whole clip before it writes a single word. Then it spells out the transcript left to right, glancing back at the exact audio frames each word came from.
Why Does This Exist?
Sound arrives over time, but meaning often arrives late. If someone mumbles a name at the start of a sentence, you usually decode it from the words that follow. A recognizer that commits to each sound the instant it hears it can never do that. It's stuck with its first guess.
Frame-by-frame systems work exactly that way. They score each slice of audio on its own and merge the scores into text, the pipeline automatic speech recognition walks through. Treating frames as independent buys speed and live output, but it throws away the future. A mumbled word stays mumbled even when the next second of audio would have settled it.
Encoder-decoder ASR takes the opposite trade. An encoder reads the entire clip first and turns every frame into a vector that has seen what came before and after it. Only then does a decoder start writing, one token at a time, aiming back at the relevant frames through cross-attention. You pay with latency, because no word leaves before the clip ends, and you gain accuracy on anything ambiguous. The classic instance is Listen, Attend and Spell, and the same skeleton sits inside Whisper.
This page covers that skeleton: the two halves, the attention bridge between them, and one decoding step worked by hand. The frame pipeline it builds on lives in automatic speech recognition, and the search that picks the final transcript lives in beam search.
You need one prerequisite to follow along. Audio enters the model as frames: each frame covers a few tens of milliseconds of sound and is summarized as a vector of spectral energies, so a two-second clip becomes a sequence of about two hundred vectors. Everything the encoder and decoder do operates on that sequence, never on raw samples. The full pipeline from waveform to frames is in automatic speech recognition.
Think of It Like This
A voicemail you hear out before answering
A friend leaves you a rambling two-minute voicemail with three questions buried in it. You do not reply after the first ten seconds. You listen to the whole thing, then you answer point by point, replaying the fuzzy middle bit to check the name you half heard.
The full listen is the encoder. Answering point by point is the decoder. Hitting replay on one section while you compose your reply is cross-attention: your next sentence is guided by the part of the message it answers.
Where it stops: you actually understand your friend, so you can paraphrase, ask what they meant, or admit you could not hear them. The decoder understands nothing. It matches sound patterns to text patterns, it can't ask for clarification, and it delivers a wrong word with the same fluency as a right one.
How It Actually Works
Call the frame sequence , where each is one spectral vector and is the number of frames. The encoder transforms it into , a sequence of -dimensional vectors where each has absorbed context from the whole clip. The decoder holds a state built from the tokens written so far, through , and must choose the next token .
The encoder hears everything first
The encoder is typically a Transformer stack or a bidirectional recurrent network, often with a convolutional front end that subsamples the frames. Because each output vector is computed with access to past and future frames, knows what happened at frame 10 and frame 90. That full context is the whole point: the representation of a mumbled sound carries the later sounds that disambiguate it.
Cross-attention aims before each word
To write token , the decoder forms a query from its state , a summary of what it has written and what it expects next. It compares that query against every encoder vector, which serve as keys, and the comparison decides how much of each frame's content, serving as values, flows into the decision:
In plain words: is a match score between the query and frame , scaled by (the vector width) so the numbers stay tame. The weights are those scores passed through a softmax, so they are positive and sum to 1 across frames. The context is the weighted average the decoder actually reads. The next token distribution is , where is a learned output matrix and just means the two vectors glued together.
Worked example: four frames, one query
Keep the width tiny, , so . Suppose the encoder produced four frame vectors and the decoder query is :
- , , , (a silent frame).
Dot products with give , , , . Divide by : scores . Exponentiate: twice, , , for a sum of about . The weights are therefore
which sum to . Frame 3 wins with because it matches both active query entries. Taking values equal to keys in this toy, the context is . The diagram above draws these exact numbers: four frames in, the winning weight on frame 3, and the context flowing down into the next word. The decoder then scores its vocabulary from and writes one token.
This design assumes the full utterance is available before writing starts, which is why it cannot stream. It also trains on gold-standard prefixes but tests on its own guesses, so one wrong word skews the query and the error compounds left to right. That's the price of the accuracy: use this shape when the whole clip exists and correctness matters, and reach for a streaming transducer when words must appear while the speaker is still talking. Two voices talking over each other break the one-transcript assumption entirely; splitting speakers first is the separate job of speaker diarization.
Code
The point of this snippet is the check, not the formula. It recomputes the worked example in plain Python so you can see the weights sum to 1 and the context land on .
import math
def softmax(xs: list[float]) -> list[float]: m = max(xs) # shift by the max for safety; the result is unchanged exps = [math.exp(x - m) for x in xs] total = sum(exps) return [e / total for e in exps]
scores: list[float] = [0.5, 0.5, 1.0, 0.0]weights = softmax(scores)print([round(w, 3) for w in weights]) # -> [0.235, 0.235, 0.387, 0.143]print(round(sum(weights), 3)) # -> 1.0
keys: list[list[float]] = [[1, 0, 0, 0], [0, 1, 0, 0], [1, 1, 0, 0], [0, 0, 0, 0]]context = [sum(w * k[d] for w, k in zip(weights, keys)) for d in range(4)]print([round(c, 3) for c in context]) # -> [0.622, 0.622, 0.0, 0.0]Frame 3 carries the largest weight, so both active entries of the context come out near while the silent frame contributes nothing.
Watch Out For
Using it as a live captioner
You hook the model to a microphone and expect words to appear as the person speaks. Nothing shows up until the pause at the end of the sentence, because the encoder refuses to start until the clip is complete and the decoder refuses to start until the encoder is done.
That silence is the architecture, not a bug or a tuning knob. If your product needs partial results mid-sentence, this family is disqualified no matter how accurate it is. Switch to a streaming design such as a transducer with a bounded lookahead, or chunk the audio explicitly and accept the accuracy hit at chunk edges.
One wrong word derails the rest
Training feeds the decoder the true previous words, but at test time it feeds its own guesses. So the first mistake corrupts the query, the corrupted query aims attention at the wrong frames, and the transcript veers off and never recovers. The symptom is distinctive: a fluent transcript whose middle suddenly describes audio that was never spoken.
Don't try to fix this by retraining louder. Decode with a wider beam search so alternative prefixes survive one bad step, and check whether the derailment point coincides with noise or an accent the acoustic encoder never learned. A beam keeps candidates alive; it cannot rescue frames the encoder already misheard.
The Quick Version
- An encoder-decoder ASR model reads the whole audio clip into context-rich vectors before its decoder writes a single token.
- Cross-attention aims each output word at the frames it came from: match scores become weights that sum to 1, and the weighted average becomes the context.
- Future context is the accuracy win: a frame's vector carries sounds that arrive after it, so later words can disambiguate earlier ones.
- The price is latency plus compounding errors: nothing is emitted until the clip ends, and a wrong word skews every word after it.
- Use it for transcribed recordings, captions prepared after the fact, and voice messages; never for live captioning, where a streaming design wins.