All courses
Courses › How LLMs really work · foundation

Probability and distributions

Read a discrete distribution as a probability vector that sums to 1, and compute simple probabilities.

▶ Watch this lesson Start the whole course

What the animation says

Every word needs a number

The cat sat on the... Before a model writes the next word, it scores every word it knows. Mat: quite likely. Floor: less likely. Banana: almost never. That is tens of thousands of numbers at once, and they all share one whole of certainty. Picture a pie that stands for one hundred percent. Each possible word gets a slice. A slice of one quarter means: draw the next word many times, and this word comes up about twenty-five times in a hundred.

Two rules, one missing slice

Slices obey two rules. No slice is negative, and no slice is bigger than the whole. And all the slices together make exactly one. A list like this is called a discrete distribution, or a probability vector. Here is the model's list: mat point five, floor point two, sofa point one, other point one five. Bed is hidden. Using only the rules, what must bed be?

An event: add its slices

Bed is point zero five: one minus everything else, which is point nine five. Now ask about a group of words. A group of outcomes is called an event. What is the chance the next word is mat or floor? Light up both slices and add: point five plus point two, point seven. Each outcome counts only once, even if you name it twice. Your turn: what is the chance the next word is sofa or bed?

Not happening, and many draws

Sofa or bed is point one five: the two slices added together. Now the chance the next word is not mat. That is everything except mat. You could add four slices, or just take mat away from the whole: one minus point five, which is point five. Probabilities also predict counts. Imagine drawing the next word a thousand times. Drag the marker to about how often floor should appear.

What to remember

A discrete distribution is one number per outcome. None is negative, and together they make exactly one. For an event, add the slices of its outcomes, each counted once. For something not happening, subtract its chance from one. And a hidden value is whatever is left of the whole.

How do you write down 'how likely'?

Before a language model writes its next word, it has to say how likely **every** possible next word is: 'mat' quite likely, 'floor' less, 'banana' almost never. That means tens of thousands of numbers at once. What kind of numbers are these, what rules must they obey, and how do you read answers from them, such as *how likely is it the next word is one of these three?*

Sharing out one whole unit of certainty

Think of a pie that stands for 100% certainty. You cut it into slices, one slice per possible outcome. A bigger slice means a more likely outcome. No slice can be negative, and together the slices make exactly the whole pie. A slice of $0.25$ means that if the outcome is drawn at random according to these slices many times, this outcome comes up about 25 times out of 100.

A distribution is a list summing to 1

Give each of $n$ outcomes a probability $p_1, p_2, \dots, p_n$. The small number below the $p$ just says which outcome it belongs to. Two rules: $$0 \le p_i \le 1, \qquad p_1 + p_2 + \dots + p_n = 1$$ This list is a **discrete distribution**, also called a **probability vector** (an ordered list of numbers). An **event** is a group of outcomes. Its probability, written $P(\text{event})$, is the sum of its outcomes' probabilities, counting each outcome once. The chance that an event does *not* happen, its **complement**, is $1 - P(\text{event})$.

Next word after 'The cat sat on the'

Model's distribution: mat $0.5$, floor $0.2$, sofa $0.1$, bed $?$, other (all remaining words together) $0.15$. 1. Missing value: bed $= 1 - (0.5+0.2+0.1+0.15) = 1 - 0.95 = 0.05$. 2. P(mat or floor) $= 0.5 + 0.2 = 0.7$. 3. P(not mat) $= 1 - 0.5 = 0.5$. 4. P(sofa or bed) $= 0.1 + 0.05 = 0.15$. 5. If the next word is drawn at random according to these probabilities 1000 times, 'floor' appears about $0.2 \times 1000 = 200$ times.

What to remember

A discrete distribution is a list of non-negative numbers, one per outcome, that add up to exactly 1. To get the probability of an event, add up the probabilities of its outcomes, each counted once. To get the probability that something does *not* happen, subtract its probability from 1.

On Bytewise this lesson comes in small steps with a check at the end, and the app brings it back right before you would forget it.