- Key idea
- Joint distributions, marginalising (summing out), conditioning (zoom in and renormalise)
- Real world
- Of 1,000 days, 120 had a cloudy morning and a rainy afternoon. Knowing the morning is cloudy, the chance of rain is not 155/1,000 but 120/300: you only look at cloudy mornings.
- In an LLM
- A model’s accuracy is 67% overall, but 60% on maths, 50% on code and 85% on chat. Each of those is a conditional probability: accuracy given the task.
Two things at once
Usually there is more than one random thing going on: the weather in the morning and in the afternoon; the kind of prompt and whether the answer was right. The joint distribution gives the probability of every combination.
A joint distribution of two variables fits in a table. Each cell is “this and that”, and all the cells add up to 1.
Try it
| grade →task ↓ | total | ||
|---|---|---|---|
0.18 180 | 0.12 120 | 0.30 | |
0.15 150 | 0.15 150 | 0.30 | |
0.34 340 | 0.06 60 | 0.40 | |
| total | 0.67 | 0.33 | 1.00 |
Marginals: forget one variable
To get the distribution of just one variable, add up across the other. This is called marginalising, because people used to write those totals in the margins of the table.
Marginalising is the most common operation in probabilistic machine learning: whenever there is something you can’t see or don’t care about (which reasoning path the model took, which hidden “concept” a prompt is about), you add it up over all its possibilities.
Conditionals: zoom in and renormalise
A conditional probability , read “A given B”, is the probability of among the cases where B happened. Two steps:
- Zoom in: throw away every case where didn’t happen.
- Renormalise: divide by what’s left, so the remaining probabilities add up to 1 again.
Of 1,000 days, 300 had cloudy mornings and on 120 of those it rained in the afternoon. On the 700 clear mornings, it rained 35 times.
- — the marginal.
- .
- .
The forecast for “rain given cloudy” is very different from “rain” on its own, and also very different from . The order of a conditional matters.
A model was graded on 1,000 prompts: 300 maths, 300 code and 400 chat. It got 180, 150 and 340 of them right.
- Overall accuracy, the marginal: .
- .
- : of the right answers, about a quarter were maths.
The overall number depends on the mix of prompts. Change the benchmark to be half maths and the same model scores lower, without changing at all. This is why papers report per-category results, and why comparing scores across benchmarks with different mixes is risky.
Weighted averages of conditionals
You can rebuild a marginal from conditionals: weight each conditional by how common its condition is. This is the law of total probability:
Hospital A saves 95% of mild cases and 70% of severe ones; hospital B saves 90% and 60%. A is better at both. But A is the regional trauma centre and 80% of its patients are severe, while 80% of B’s are mild. Overall, A saves and B saves . The better hospital has the worse total.
Model A scores 90% on easy prompts and 40% on hard ones; model B scores 85% and 30%. If A was evaluated on a set that is 80% hard and B on one that is 20% hard, A’s headline number is 50% and B’s is 74%. Leaderboards that mix results from different test sets, or RL papers that change the prompt filter between runs, can produce exactly this.
Everything in a language model is conditional
A language model never outputs . It outputs : a different distribution for every context. Prompting, few-shot examples and system prompts all work by changing what is being conditioned on. The chain rule shows how these conditionals combine into the probability of a whole answer.
Where this shows up
- A policy is a conditional distribution over actions given the state: the RL loop.
- Bayes’ theorem flips the order of a conditional: Bayes’ theorem.
- Summing out a hidden reasoning path is marginalising: latent variables.
Definitions
For random variables and with joint distribution :
The law of total probability, and its version for expectations (the tower rule):
In papers
The objective of nearly every LLM fine-tuning paper is a nested expectation of this kind: average over prompts from a dataset , and for each prompt, average over answers from the policy:
Read it inside out: for one prompt , the inner expectation is the model’s expected reward on that prompt; the outer one averages over prompts. Some papers write the pair as or just . A semicolon, as in , marks parameters rather than conditioning on a random variable: same idea, different status.