JA EN
LearnProbability & Statistics
·★ MEMBER·8 min read

Probability and Statistics for AI — A Model's Output Is a Distribution

Classifiers and language models do not return answers; they return probability distributions. Distributions, expectation, conditional probability and Bayes explained from the symbols up — building to the payoff: why maximum likelihood is where loss functions come from. Cross-entropy and MSE were derived, not invented.

ModalitytextTaskmath

The goal: being able to read this equation

When a paper writes down what it is training for, it almost always uses this shape.

L(θ)=E(x,y)D[logpθ(yx)]\mathcal{L}(\theta) = -\,\mathbb{E}_{(x,y)\sim\mathcal{D}}\big[\log p_{\theta}(y \mid x)\big]
(1)

Written out in words it says: show the model some data, ask how much probability it put on the correct answer, take the log of that number, average over everything you showed it, and flip the sign. θ\theta is the model's parameters, E\mathbb{E} is an average, D\mathcal{D} is where the data comes from, \sim means "drawn from", pθ(yx)p_{\theta}(y \mid x) is the probability the model assigns to yy having seen xx, and the vertical bar \mid reads "given".

The notation is unfamiliar; the content is not. And once this line is readable, classification losses and language-model losses turn out to be the same equation wearing different clothes.

What a model returns is not an answer

Nothing else works until this is dislodged. A classifier does not say "cat". It returns a probability for every class it knows — cat 0.82, dog 0.15, other 0.03. The interface shows you the largest entry, which is why it looks like a single answer.

Language models do the same thing. For every next token, they build a bar chart over the entire vocabulary, tens of thousands of entries wide. After "the capital of Japan is", perhaps Tokyo 0.71, Osaka 0.04, and so on down the list.

The function that builds that chart is softmax.

pi=exp(zi)jexp(zj)p_i = \frac{\exp(z_i)}{\sum_{j} \exp(z_j)}
(2)

ziz_i is the raw score the model emits — the logit, which can perfectly well be negative — exp\exp is the exponential, and the denominator sums over every entry.

The fraction, in words, does two things: make every score positive without disturbing which one is largest, then rescale the whole set so it adds up to one. Calling something a probability requires exactly two properties, non-negative and summing to one; exp\exp delivers the first, the division delivers the second. There is no deeper philosophy in it.

FIG 1The same logits, reshaped. Lower the temperature and the distribution spikes onto one option; raise it and the bars flatten out. Peaked means confident, flat means undecided — and that peakedness turns out to matter enormously later

Expectation: the formal way to write "average"

E[X]=xxp(x)\mathbb{E}[X] = \sum_{x} x\,p(x)

XX is a quantity whose value is decided by chance and p(x)p(x) is the probability of it taking value xx.

Put in words, the sum is an average in which every possible value is weighted by how likely that value is. If a quantity is 1 with probability 90% and 100 with probability 10%, its expectation is not the naive 50.5 but 1×0.9+100×0.1=10.91 \times 0.9 + 100 \times 0.1 = 10.9.

When E\mathbb{E} appears in a paper, reading it as "average this over the data" will be right nine times out of ten. Implementations cannot afford the full dataset every step, so they substitute the mini-batch average. That is what the E\mathbb{E} in equation (1) becomes in code.

Conditional probability: what a language model is doing

p(yx)p(y \mid x) is the probability of yy given that xx has happened. Predicting umbrella sales cold is hard; predicting them given "it is raining" is a different exercise. Conditional probability is the notation for "new information changes the outlook".

A language model is that idea wired in series.

p(x1,x2,,xT)=t=1Tp(xtx<t)p(x_1, x_2, \ldots, x_T) = \prod_{t=1}^{T} p(x_t \mid x_{<t})
(3)

\prod ("pi") means "multiply all of these", xtx_t is the tt-th token, and x<tx_{<t} means every token before it.

It is one line which says: the probability of a whole passage is the product of, at each position, the probability of that token given everything written so far. A GPT-style model computes only the individual factors on the right; generation is drawing from them one at a time. This is what "it just predicts the next word" actually refers to.

is a hypothesis (the model's parameters) and is the data observed. Each of the four pieces has a name. is the prior — what you believed before looking. is the likelihood — how well that hypothesis accounts for what you saw. is the posterior — what you believe afterwards. is the division that makes everything sum to one

What's behind this

§

Members-only from here

371 walkthroughs, 26 textbook chapters, 48 student units and 6 close readings — all included for $4.99/mo, with three new explainers every day. Cancel any time; access runs to the end of the period.

Already a member? Sign in to keep reading

Comments

Sign in to comment