Part I · Ch. 6 — Chance and Choice

Part I · Chapter 6 of 21

Chance and Choice

Probability: spreading belief across possibilities


Finish the sentence

“The cat sat on the ___.” We can imagine mat, couch, or keyboard, with different expectations for each. A language model also weighs possibilities before selecting one. Both steps can be made precise.

One unit of belief, spread out

A probability measures a chance. Draw blindly from ten equally likely marbles: five mint, three amber, two violet.

Left: ten marbles in a bag outline — five, three and two marbles, grouped by color. Right: a bar chart with three bars at heights 0.5, 0.3, and 0.2 for the three colors, the y-axis labeled probability p from 0 to 1, with a note that the bars always total 1.00.
Probability shares always total one.
$$ p(\text{mint}) = \frac{5}{10} = 0.5 $$

In words: out of every ten equally likely draws, five are mint, so the chance of mint is one half.

$$ p(\text{mint}) + p(\text{amber}) + p(\text{violet}) = 0.5 + 0.3 + 0.2 = 1 $$

In words: add up the chances of every marble color and you get one whole.

A probability distribution assigns a share to every outcome. Like a function, p takes an outcome and returns its share. Each share is between zero and one; together they total one.

$$ \sum_{i=1}^{n} p(x_i) = 1 $$

In words: add up the probability of every possible outcome and the total is always 1.

The sum symbol $\sum$ means “add them all up.” Here $x_i$ names outcome i and n counts the outcomes.

The shapes of belief

Two bar charts sharing a y-axis from 0 to 1. Left, for the prompt 2 + 2 = blank: one tall bar for 4 at 0.98, and two tiny slivers for 5 and 22 at 0.01. Right, for My favorite color is blank: five near-equal bars for blue, green, red, purple, orange between 0.16 and 0.24.
Belief can concentrate or spread out.
Read confidence from the shape
ShapeExample sharesMeaning
Peaked4: 0.98; 5: 0.01; 22: 0.01.One strong favorite for “2+2=___.”
FlatBlue 0.24, green 0.22, red 0.20, purple 0.18, orange 0.16.Several plausible favorite colors for a stranger.

The bars report the model's confidence, not a guarantee that its favorite is correct. Both examples total one.

Belief with strings attached

Conditional probability depends on what we know. Read $p(\text{next}\mid\text{context})$ as “probability of next, given context.” The context goes to the right of the bar.

Worked example

The corpus below is made up. The numbers are invented so the arithmetic stays checkable, and they are not statistics about English. Suppose that across a shelf of storybooks the phrase "the cat sat on the ___" appears 20 times, followed by mat 12 times, couch 5 times and keyboard 3 times. The conditional probability of mat is those 12 hits out of 20:

$$ p(\text{mat} \mid \text{the cat sat on the}) = \frac{12}{20} = 0.6 $$

In words: of the 20 times that phrase showed up, 12 were followed by mat, so given that context, mat carries 60% of the belief.

The other two come out the same way: $p(\text{couch} \mid \dots) = 5/20 = 0.25$ and $p(\text{keyboard} \mid \dots) = 3/20 = 0.15$. That is counting and dividing, the same as with the marbles.

Two bar charts sharing a y-axis from 0 to 1. Left, for the cat sat on the blank: mat 0.60, couch 0.25, keyboard 0.15, with count fractions 12/20, 5/20, 3/20. Right, for the WET cat sat on the blank: towel 0.70, mat 0.20, couch 0.10, with fractions 7/10, 2/10, 1/10. An arrow labeled one added word points from the left mat bar to the shorter right mat bar.
Adding “wet” changes the distribution.

In another invented sample, “the wet cat sat on the” occurs ten times: seven towels, two mats, one couch.

$$ p(\text{towel} \mid \text{the wet cat sat on the}) = \frac{7}{10} = 0.7 $$

In words: once we know the cat is wet, towel jumps to 70% of the belief.

Mat falls from 0.60 to 0.20; towel rises to 0.70. We changed the question by changing the known information.

Rolling the die: from belief to choice

Sampling turns the distribution into one choice. Random does not mean equally likely.

Left: a spinner wheel divided into three slices — a large slice labeled mat 0.60, a medium slice labeled couch 0.25, and a thin slice labeled keyboard 0.15, with a fixed pointer at the top. Right: a twenty-sided die icon above a mapping table reading 1 to 12 mat, 13 to 17 couch, 18 to 20 keyboard, each with a color swatch, captioned same distribution, two machines.
Both machines encode the same shares.

Give each candidate its share of a die

  1. Assign faces 1–12 to mat: 12/20=0.60.
  2. Assign 13–17 to couch: 5/20=0.25.
  3. Assign 18–20 to keyboard: 3/20=0.15.
  4. Roll once. A 16 chooses couch even though mat has the largest share.

In 100 rolls we expect 60, 25, and 15 on average. The illustrative run below gives 57, 29, and 14. In ten rolls, 8, 1, and 1 is possible too.

With many independent draws, proportions tend toward the assigned probabilities. For independent zero-mean noise with finite variance, averaging also reduces typical error; ten coin flips need not give exactly five heads.

Two ways to choose
RuleWhat happens
GreedyChoose the tallest bar, here mat.
SamplingChoose using the whole distribution, allowing less likely outcomes.
Two bar charts. Left, 10 rolls: solid bars at 8, 1, 1 for mat, couch, keyboard, with dashed expected marks at 6, 2.5, 1.5 sitting far from the bars. Right, 100 rolls: solid bars at 57, 29, 14, with dashed expected marks at 60, 25, 15 sitting right next to the bars.
More samples tend toward expected shares.

From scores to shares

Counts gave us probabilities above. A model instead produces logits. Softmax turns them into shares: exponentiate each score, then divide by the sum. A temperature T first divides every score.

Reshape the die

For scores 2, 1, 0 at T=1, exponentials are approximately 7.39, 2.72, 1. Their total is 11.11, giving shares 0.665, 0.245, 0.090. At T=2, scores become 1, 0.5, 0 and shares are about 0.506, 0.307, 0.186: flatter. At T=0.5, shares are about 0.867, 0.117, 0.016: sharper. Rounded shares can miss one slightly.

In words: temperature changes the die's weighting; sampling still rolls it. Lower temperature favors the leader without guaranteeing it for every positive T.

Chapter 9 develops this score-to-share calculation fully.

Averages of independent, zero-mean errors tend toward zero over many samples. Biased or correlated errors need not cancel. This is why the sampling lesson does not guarantee that deterministic rounding errors disappear in a model.

See it move

Watch (2:01): what to notice. Raw scores 4.0, 2.0 and 0.5 become shares 0.86, 0.12 and 0.03 that add to one, a die whose faces are sized to those shares rolls “mat”, temperature sharpens the bars at $T=0.5$ and flattens them at $T=2$, and the same sentence is written greedily and by sampling.

Why the LLM cares

$$ p(\text{next} \mid \text{context}) $$

In words: the probability of each possible next word, given everything written so far.

The model builds a distribution over word-pieces, chooses one, appends it to the context, and repeats. Sampling explains why repeated prompts can produce different answers. Changing context explains why adding “wet” changes what comes next.

Training will score the probability assigned to the correct piece. The logarithm from Chapter 4 will turn that probability into a penalty.

What you now know

  • Probabilities lie between zero and one and total one.
  • Conditioning changes the distribution when known information changes.
  • Sampling follows the shares; greedy selection picks a maximum.
  • Small samples can differ greatly from expected counts.
  • Softmax converts scores to shares; temperature reshapes them.
  • A model repeats prediction, selection, and appending.

Where we're headed

Part I is complete: vectors, similarity, matrices, curves, slopes, and probability. Now we'll turn text into tokens so these tools can work on language.