Concept · Chapter 2: The Math Toolkit
Probability of Sequences
The probability of a whole sequence equals the product of each element's probability given everything before it — the identity that turns 'model language' into 'predict the next token'.
The problem
There are astronomically many possible sentences; we can't list a probability for each one directly.
The solution
Factor the joint probability into a chain of conditional probabilities: first word, then second given the first, then third given the first two, and so on.
The consequence
A single model that predicts the next token given the past defines a probability for every possible text — the foundation of autoregressive language models.
You should understand first
- Probability and Distributions
- Conditional Probability and Bayes' Theorem
- Probability of Sequences
Intuition
What's the probability of the sentence "the cat sat"? Build it one word at a time: how likely is the to start a sentence; given the, how likely is cat; given the cat, how likely is sat. Multiply those.
Tiny numeric example
Each factor
, ,Multiply
Use logs
, and . Adding logs avoids numbers so small a computer rounds them to zero.
The equation
Where it appears in AI
This identity is why "predict the next token" is a complete recipe for modelling text. Train a network to estimate well, and you have a model of whole documents; sample one token at a time from it, and you have a generator. The training loss for each factor is cross-entropy.
What to remember
- P(x₁, …, xₙ) = P(x₁) · P(x₂ | x₁) · … · P(xₙ | x₁, …, xₙ₋₁).
- This is exact — no approximation — for any sequence.
- An LLM models each factor: P(next token | all previous tokens).
- In practice we sum log-probabilities instead of multiplying tiny numbers.