Foundations
Probability you actually need
Conditional probability, distributions, expectation, and log probabilities provide the working vocabulary for language models.
Updated
1
Concept
A probability is a number between zero and one expressing uncertainty under a model. Zero rules an event out; one makes it certain within that model. For mutually exclusive possibilities, the probabilities add to one. A language model’s next-token output is a categorical distribution: one probability for each vocabulary item. The distribution is the prediction. Selecting one token from it is a separate decoding operation.
Probability is always attached to assumptions and information. We write for the probability of event , and for the probability of given that is known. Language modelling is conditional: . The same token can be likely after one prefix and unlikely after another. “Mercury” after “the closest planet to the Sun is” differs from “the liquid metal is.”
A random variable maps possible outcomes to values. A distribution says how probability is allocated among them. For a discrete variable , its expected value is a probability-weighted average, . Expectation is not necessarily an outcome you will observe. The expected roll of a fair six-sided die is 3.5, although no face shows 3.5. In machine learning, expected loss summarizes performance across examples or possible outputs.
The chain rule decomposes the probability of a sequence. For tokens ,
This identity explains why repeated next-token prediction defines a probability for an entire passage. It also explains why long sequence probabilities become tiny: many numbers below one are multiplied. Tiny values are awkward for finite-precision computers, so implementations work with logarithms.
Because , a product of probabilities becomes a sum of log probabilities. The log of a probability is at most zero. A more likely event has a log probability closer to zero; an impossible event tends toward negative infinity. Training often minimizes negative log-likelihood, which simply changes the sign so better predictions yield a smaller objective. Averaging it over tokens makes sequences comparable.
Two probability rules prevent common reasoning errors. First, is not generally . A symptom may be common among people with a condition while the condition remains rare among people with that symptom. Second, high probability is not truth. A language model estimates regularities in its data and training process; a fluent misconception can receive high probability. Calibration asks whether events assigned, say, 70 percent probability occur about 70 percent of the time across comparable cases.
Softmax bridges arbitrary model scores and a distribution. Given logits , it computes . Adding the same constant to every logit leaves probabilities unchanged, because only relative differences matter. Temperature divides logits before softmax and changes how concentrated the distribution is. These transformations manipulate uncertainty; they do not supply new evidence.
The practical toolkit is small: normalize distributions, condition on context, use the chain rule for sequences, use expectations for averages, and use logs for stable products. Keep the distinction between a model’s distribution and the world it describes. With those pieces, loss, entropy, perplexity, sampling, and cross-entropy become variations on familiar ideas rather than isolated formulas.
2
Explain it like I am five
Picture a weather desk with one hundred chips spread across tomorrow’s possibilities: sixty on rain, thirty on cloud, ten on sun. New radar evidence does not declare one future; it moves the chips. A forecast is the whole arrangement, not the label under the largest pile. Language models do the same with vocabulary tokens. Context moves probability mass, decoding selects one outcome, and the next context begins with that selection included.
3
Teach it back
Explain conditional probability and log probability using a next-token example, including why the most likely token need not be certain.
Minimum: 80 characters and 15 words. Your text stays only in this browser.
Saved only on this device.
Show a model answer
The model estimates P(next token | tokens already seen). Context changes the distribution: after “peanut butter and,” “jelly” may be likely without receiving probability one. A complete sequence probability is a product of conditional probabilities. Taking logs turns that product into a sum, which is numerically stable and convenient for training. Choosing the largest probability is a decoding decision, not proof that the chosen token is true.
4
Check your understanding
Complete the teach-back and answer the quiz correctly to finish this lesson.
Sources
- Claude E. Shannon (1948). A Mathematical Theory of Communication.