Causal Language Modeling › The Autoregressive Factorization
Language AI HandbookAll chapters Causal Language Modeling › The Autoregressive FactorizationOne section · Sections in this chapter2 / 13 ↓
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
Causal language modeling is built on a mathematical framework called the autoregressive factorization. Before diving into the training objective or the loss function, it helps to understand this underlying structure, because it explains both why the approach is tractable and why it naturally produces generative models. The central challenge is assigning probabilities to sequences of arbitrary length. The autoregressive factorization is the field's mathematically exact solution rather than an approximation.
How do you assign a probability to an entire sentence? This is the fundamental question that language models must answer. Given a sequence of tokens , we want to compute , the probability that this particular sequence occurs in natural language.
The Combinatorial Challenge
Consider what this means in practice. With a vocabulary of 50,000 tokens and sequences of length 100, we'd need to assign probabilities to possible sequences. That's more possibilities than atoms in the observable universe, raised to a power larger than the universe's age in seconds. Storing or computing such a distribution directly is impossible.
We need a way to break this intractable joint probability into manageable pieces. Fortunately, probability theory gives us exactly such a tool: the chain rule.
The Chain Rule of Probability
The chain rule states that any joint probability can be decomposed into a product of conditional probabilities. For a sequence, this means:
Let's trace through what each term represents:
- : The probability of the first token appearing at the start of a sequence. This has no conditioning context.
- : Given we've seen the first token, what's the probability of the second?
- : Given the first two tokens, what comes third?
- And so on, until : the final token, conditioned on everything before it.
This telescoping product captures the sequential nature of language. Each new word depends on what came before, exactly matching our intuition about how text is generated.
The Compact Notation
We can express this factorization more concisely using product notation:
where:
- : the token at position in the sequence
- : all tokens before position , that is, the sequence
- : the conditional probability of token given all preceding tokens
For the first position where , we define as empty, so .
Each factor is a conditional distribution over the entire vocabulary. Given everything we've seen so far, what's the probability of each possible next token? This is precisely the question a language model learns to answer.
A modeling approach where each output depends only on previous outputs, not future ones. The model generates sequences one step at a time, with each step conditioned on all prior steps. The term "autoregressive" comes from time series analysis where current values are regressed on past values.
Why This Factorization Works
This decomposition is mathematically exact, not an approximation. The chain rule holds for any joint distribution. What makes it practical is that we've transformed an impossible problem (representing probabilities) into a tractable one (learning a function that outputs a distribution over 50,000 tokens given any context).
The key insight is that while contexts vary enormously, they share statistical patterns. The word "the" tends to be followed by nouns. Questions end with question marks. Technical documents use technical vocabulary. A neural network can learn these patterns and generalize them to new contexts it has never seen before.
There is also a deep connection between this factorization and causality, which is where the name "causal" language modeling comes from. When a model predicts , it is computing what should come next based solely on the causal history, everything that appeared before. No information from the future leaks into the prediction. This mirrors real-world language generation: when a human writes a sentence, the word they choose at each moment is influenced by what they have already written, not by what they have not yet written. CLM formalizes this intuitive notion and enforces it architecturally through causal masking, which we'll cover later in the chapter.
Before neural language models, the autoregressive factorization was approximated using n-gram models. An n-gram model estimates by only conditioning on the previous tokens rather than the full history. A trigram model, for example, computes . This Markov approximation made computation feasible in the pre-neural era: you simply count how often each n-gram appears in the training corpus. The problem is that vocabulary grows exponentially with , so trigrams and 4-grams were roughly the practical limit. Most contexts you encounter at test time never appeared in training, leading to severe data sparsity. Neural language models broke through this ceiling by learning continuous representations that generalize across contexts, allowing effective conditioning on sequences of arbitrary length.
Notice that the factorization also implies a natural sampling procedure. To generate a sequence, you sample from , then sample from , then from , and so on. At each step you need only the distribution over the next single token, which the model can compute efficiently. This is why the same model used for training, which minimizes prediction loss, can be used directly for generation without any modifications.