Probability and Statistics
Probability, random variables, and distributions
Formalizing chance and its shapes
Most of the world you care about is uncertain - the next token, the next click, the next measurement. Probability is the one language that lets you reason about that uncertainty quantitatively instead of hand-waving. You start with a set of things that can happen, attach numbers that obey three tiny rules, and out of that falls everything: expectation, variance, the bell curve, and - you will see it here - the very layer that lets a language model choose what to say.
The whole subject in one picture
Three rules pin down all of chance
A sample space is the set of all possible outcomes of an experiment - for one die, . An event is any subset of ("rolled even" is ). A probability is a function that assigns each event a number, and it only has to obey three axioms (Kolmogorov, 1933):
The Kolmogorov axioms
In words: probabilities are never negative, something in is certain to happen, and the chance of " or " for two outcomes that cannot co-occur is just their sum. Every identity you will ever use - , the whole distribution summing to - is squeezed out of these three lines.
Random variables turn outcomes into numbers
A random variable is a function that maps each outcome to a number - the count of heads in 3 flips, the height of a person. Two flavors matter:
- Discrete takes countable values. Its PMF (probability mass function) gives an honest probability to each value, and .
- Continuous takes a whole range of real values. Its PDF (probability density function) gives density, not probability - you get a probability only by taking area: , with . A single exact point has .
From either one you read off the two summary numbers. The expectation is the mass-weighted average - the balance point:
The variance measures spread - the average squared distance from that balance point, with standard deviation :
The distribution lab
Four shapes cover most of what you will meet. Uniform: every outcome equally likely. Bernoulli(): one trial, success with probability . Binomial(): how many successes in independent trials - , mean . Normal(): the continuous bell curve, . Below, the amber is the true distribution. Press Sample and watch teal draws pile into a histogram that converges to it - the law of large numbers, live - while the green fulcrum marks , the balance point of the mass.
A softmax is a probability distribution
import numpy as np
# 10,000 binomial draws: mean → n·p, variance → n·p·(1-p)
n, p = 10, 0.5
draws = np.random.binomial(n, p, size=10_000)
print(draws.mean(), draws.var()) # ~5.0 ~2.5
# a normal, and a softmax that IS a distribution over 3 tokens
x = np.random.normal(loc=0.0, scale=1.0, size=10_000)
logits = np.array([2.0, 1.0, 0.1])
probs = np.exp(logits) / np.exp(logits).sum() # sums to 1.0
token = np.random.choice(3, p=probs) # one draw = one tokenCheck yourself
For a continuous random variable, the probability that X equals one exact value is:
As you draw more and more samples in the lab, the histogram of outcomes will:
What is the difference between a PMF and a PDF, and what does each add up to?
The distinction discrete vs continuous governs how you compute probabilities. Try to state it, then check.
Lock it in
- Three axioms (non-negative, total = 1, additive for disjoint events) pin down all of probability.
- A random variable maps outcomes to numbers; its distribution (PMF or PDF) spreads exactly 1.0 of mass across them.
- Expectation is the balance point; variance is the average squared distance from it.
- Binomial counts successes in n trials; Normal is the continuous bell curve; both converge empirically via the law of large numbers.
- A softmax IS a PMF over a vocabulary - sampling a token is one draw from a distribution.
Where this leads
Primary source