The model says 70%. Seventy percent of what?
A small language model reads the cat sat on the and says the next word is mat, with probability 0.7. This series follows that one number until it becomes the training loss. Along the way it covers what the number is, how a sentence multiplies it, why it can mislead, how noisy it is to measure, where the model’s Gaussians come from, and why training minimises −log 0.7.
The map is Chapter 6 of Mathematics for Machine Learning (MML). This part asks the first question: what kind of thing is 0.7?
The 30-second version
Of all the ways the sentence could go on. The model hands you a whole distribution, not a word: picture 20 tickets in a hat, 14 saying mat, 3 floor, 2 sofa, 1 moon. Sampling a word is drawing one ticket, so about 70% of draws say mat. The 70% is a share of a total that is always exactly 1, which is why raising one word must lower another. And a probability can never pass 1. A density can, and that is the other half of this part.What exactly does the model hand you?
Not a word. A number for every word it knows, and the numbers add up to exactly 1. Here the vocabulary has four words, and the model’s numbers are the 20 tickets:
\[p(\text{mat}) + p(\text{floor}) + p(\text{sofa}) + p(\text{moon}) = 0.70 + 0.15 + 0.10 + 0.05 = 1\]MML builds this from three ideas (§6.1.2). The sample space is every outcome that can happen, here the four words. An event is any set of outcomes, like “something you can sit on”. Its probability is the share of the total it covers:
\[P(A) = \sum_{x \in A} p(x)\]A list of numbers that are never negative and add up to 1 is a probability mass function, or pmf: the model’s whole output.
What does temperature do to the 70%?
The model does not store tickets. Its last layer outputs a score $z$ for every word, and softmax turns the scores into probabilities. Sampling at temperature $T$ divides every score by $T$ first:
\[p(\text{word}) = \frac{e^{z_{\text{word}}/T}}{\sum_{v} e^{z_v/T}}\]The scores here are the logs of the ticket counts, so at $T = 1$ the formula gives the tickets back. Guess what a small $T$ does before you slide it.
At $T = 0.5$ mat gets 0.933. At $T = 2$ it drops to 0.474, and the long tail fills in. As $T$ goes to 0 the model says mat every time, which is greedy decoding.
Through all of it the total stays exactly 1. Temperature never creates probability: it only moves it from word to word.
How does the model actually pick a word?
It throws a dart. Lay the four bars end to end into one strip from 0 to 1. The strip’s boundaries, 0.70, 0.85, 0.95 and 1, are the cumulative distribution function: the probability of landing at or before each word.
Now draw one uniform random number $u$ between 0 and 1 and take the word whose slice it lands in. mat owns the first 0.70 of the strip, so it wins 70% of the time.
That is the answer to the puzzle: 70% of the draws. It is also how every sampler works, one uniform number turned into a word through the cumulative distribution. MML’s Theorem 6.15, the probability integral transform, is this trick read the other way.
Top-$p$ sampling cuts the strip before the dart flies. It keeps the smallest set of top words whose probabilities reach $p$, and stretches them to fill the strip. At $p = 0.9$ that is mat, floor and sofa, renormalised to 0.737, 0.158 and 0.105.
What is a random variable?
Draw two words, putting the ticket back each time, and count the mats. The count is a random variable. MML’s margin note puts it best: a random variable is neither random nor a variable. It is a function, here from the four possible pairs of words to the numbers 0, 1 and 2.
Its distribution comes from adding every outcome it sends to the same number. Two pairs have exactly one mat, so:
\[P(X = 2) = 0.49, \qquad P(X = 1) = 0.21 + 0.21 = 0.42, \qquad P(X = 0) = 0.09\]This is MML’s Example 6.1, a funfair game with two coins, with its 0.3 replaced by our 0.7.
Can a probability be bigger than 1?
A probability, never. A density, easily. Not everything a model handles comes in tickets: the noise a diffusion model starts from is a continuous number.
A continuous number has a probability density $p(x)$ instead: never negative, with total area 1 (MML Definition 6.1). Probability is the area over an interval:
\[P(a \le X \le b) = \int_a^b p(x)\,\mathrm{d}x\]MML’s Example 6.3 spreads the probability evenly over [0.9, 1.6], an interval 0.7 wide, so the density stands 1/0.7 = 1.43 tall. A Gaussian with $\sigma = 0.2$ peaks at 1.99. Neither breaks a rule, because height is probability per unit of width.
The price is that a single exact value has probability 0: an interval of width zero has no area. Step 3 of the figure shrinks an interval to watch it happen. In MML’s terms, a discrete variable has a pmf with point probabilities $P(X = x)$. A continuous one has a pdf, and its probabilities live in intervals and in the cumulative distribution $P(X \le x)$ (Table 6.1).
The model never says just one word, though. It says a sentence, and the probabilities of its words multiply: Part 2.
Rapid fire: can you do these from memory?
- The model gives mat 0.70, floor 0.15, sofa 0.10. What must moon get, and why?
- What is the probability of the event “the next word is not mat”?
- What does temperature T → 0 do to sampling, and what does a very large T do?
- Explain how one uniform random number between 0 and 1 becomes a sampled word.
- With top-p = 0.8, which of the four words survive, and what are their new probabilities?
- Why does MML say a random variable is neither random nor a variable?
- A Gaussian density reads 1.99 at its peak. Is the model broken?
- Why is the probability of one exact value of a continuous variable zero?
Where can you go deeper?
This part follows Chapter 6, Probability and Distributions, of Mathematics for Machine Learning by Deisenroth, Faisal and Ong (Cambridge University Press, 2020), free at mml-book.github.io:
- §6.1.2, probability and random variables: sample space, event space and probability, and the random variable as a function (eq. 6.8), with Example 6.1, the two-coin funfair game.
- §6.2.1, discrete probabilities and the probability mass function.
- §6.2.2, continuous probabilities: the density (Definition 6.1, eq. 6.16) and the cumulative distribution function (Definition 6.2).
- §6.2.3, discrete against continuous, with Example 6.3 (a density taller than 1) and Table 6.1.
- §6.7.1, Theorem 6.15, the probability integral transform behind dart-throwing samplers.