Decoder Architecture › Understanding Autoregressive Generation
Language AI HandbookAll chapters Decoder Architecture › Understanding Autoregressive GenerationOne section · Sections in this chapter3 / 16 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
Before diving into the architecture, let's clarify what autoregressive generation means in practice. The decoder generates text one token at a time, where each new token is conditioned on all previously generated tokens.
Given a prompt "The cat sat on the", generation proceeds as follows:
- Process the prompt through the decoder to get a representation for each position
- Use the representation at the final position to predict the next token: "mat"
- Append "mat" to the sequence and process again
- Use the new final position to predict the next token: "and"
- Continue until generating a stop token or reaching a length limit
Mathematically, we're factorizing the joint probability of a sequence into a product of conditional probabilities. This is known as the chain rule of probability, and it expresses the idea that generating a sequence is equivalent to making a series of next-token predictions:
where:
- : the joint probability of the entire sequence of tokens
- : the token at position in the sequence
- : the total sequence length
- : the product over all positions from 1 to
- : the conditional probability of token given all previous tokens
Each factor in this product represents one prediction step. The factor predicts the first token with no context. The factor predicts the second token given the first. By the time we reach , we're predicting the final token given the entire preceding context.
The decoder computes each of these conditional probabilities. It takes the sequence so far, applies its transformer blocks to build contextual representations, and outputs a probability distribution over the vocabulary for the next token.