Compute a sequence probability from conditionals
Watch the spaces around tokens and probability values. · 158 words
Language models estimate the probability of a token sequence by multiplying probabilities that are conditioned on the tokens before them. This is the chain rule. For example, let P(The) = 0.20, P(cat | The) = 0.50, and P(sat | The cat) = 0.80. Then P(The cat sat) = 0.20 * 0.50 * 0.80 = 0.08. The answer means the model assigns an 8 percent probability to that exact three-token sequence.
A sequence probability depends on order because each conditional probability uses a different context. For the tokens "red car," suppose P(red) = 0.40 and P(car | red) = 0.10. Their joint probability is 0.40 * 0.10 = 0.04, or 4 percent. By contrast, P(car red) = P(car) * P(red | car); if P(car) = 0.05 and P(red | car) = 0.30, the probability is 0.05 * 0.30 = 0.015, or 1.5 percent. Computing the sequence from left to right lets us reuse a pretrained model at each step.
Check your recall
Using P(The) = 0.20, P(cat | The) = 0.50, and P(sat | The cat) = 0.80, what probability does the model assign to "The cat sat"?
Check your answer
The probability is 0.20 * 0.50 * 0.80 = 0.08, which is 8 percent.
Sources and credits
Original KeyTouch lesson. Background reading · Hugging Face · LLM Course.