Probability & Information Theory
This lesson assembles the probabilistic vocabulary a network is trained in (random variables, densities, the chain rule, expectation and covariance, the handful of distributions that recur everywhere) and then the information theory that turns a probabilistic model into a loss: self-information, entropy, and the KL divergence whose asymmetry is the cross-entropy objective itself.
╌╌╌╌
A trained network does not output a number; it outputs a distribution. A classifier emits over labels, a language model over tokens, a generative model over images. Training bends that distribution toward the data, and the gap between the two is measured information-theoretically. This lesson is the probabilistic substrate every later loss stands on, the companion to linear algebra and numerical computation.
Random variables and their distributions
A random variable is a variable whose value is uncertain; a probability distribution says how likely each value is. The form of the distribution depends on whether the variable is discrete or continuous.
The distinction matters in code: a PMF value is a probability and lies in ; a PDF value is a density and may exceed (a narrow Gaussian peaks above ), only the integral is constrained.1
| PMF | ||
|---|---|---|
| domain | discrete | continuous |
| value is | a probability | a density (prob. per unit volume) |
| range | ||
| normalization | ||
| point mass | ; use intervals |
Marginal and conditional probability
Given a joint distribution over several variables, two operations recover the pieces. Marginalization sums (or integrates) a variable away; conditioning fixes one variable's value and renormalizes.
Geometrically, a joint density over is a surface; the marginal is its shadow projected onto the -axis, while the conditional is a vertical slice at rescaled to integrate to one.
The chain rule of probability
Any joint distribution factors into a product of conditionals. Apply the conditional-probability definition repeatedly:
This is the identity an autoregressive model exploits directly: a language model writes and learns each factor with the same network applied left to right.2
Independence and conditional independence
Two variables are independent when their joint factors into marginals: knowing one tells you nothing about the other. They are conditionally independent when that factorization holds only after a third variable is fixed.
Conditional independence is strictly weaker than independence and the more useful of the two: a child's height and vocabulary are correlated marginally, but conditionally independent given age. Whole families of models (naive Bayes, hidden Markov models, the structured probabilistic models below) are built by asserting such conditional independencies to make a joint tractable.
Expectation, variance, covariance
The expectation of a function under a distribution is its probability-weighted average, the single most-used operation in the subject, since every loss is an expectation and every gradient an expectation of a gradient.
Variance measures spread around the mean; covariance measures how two variables move together; correlation is covariance normalized to .
For a random vector the pairwise covariances collect into the covariance matrix , with the variances on its diagonal. is symmetric and positive semi-definite.
A worked covariance
Let take four equally likely values: , , , . Compute the moments by the definitions above.
The sign is positive, so and tend to rise together. To read it on the bounded scale, normalize: with and ,
Common distributions
A short catalogue carries most of deep learning. Each row is a model for the output of some layer or the noise in some assumption.
| name | PMF / PDF | parameters | support | use in DL |
|---|---|---|---|---|
| Bernoulli | binary output unit (sigmoid) | |||
| Categorical | softmax classifier head | |||
| Gaussian | weight init, regression noise, VAE latents | |||
| Multivariate Gaussian | latent priors, Laplace approx. | |||
| Exponential | sparse / nonnegative variables | |||
| Laplace | heavy tails; / sparse prior | |||
| Dirac | a point mass; building block of empirical | |||
| Empirical | data | data points | the training set as a distribution | |
| Gaussian mixture | multimodal density; universal approximator |
The Gaussian is ubiquitous for two reasons: the central limit theorem makes it the default model of summed noise, and among all distributions with a given variance it is the maximum-entropy choice — the least-committal assumption you can make.3 Its bell shape is fixed by two numbers, the mean (location) and the variance (spread).
The empirical distribution is the most important row for practice: it is the training set itself, viewed as a sum of Dirac spikes, one at each data point. Every expectation under it is a plain average over the data, — the empirical risk a network minimizes.
A Gaussian mixture stacks several bells with mixing weights summing to one. With enough components it approximates any smooth density, and its multimodality is what a single Gaussian cannot capture.
Bayes' rule
Bayes' rule inverts a conditional: it turns , which you can model, into , which you want to infer. It is a one-line consequence of the chain rule.
The four pieces have standard names: the prior, the likelihood, the evidence (a normalizer), and the posterior.
A worked example
A disease afflicts of a population. A test detects it with sensitivity and has a false-positive rate. A patient tests positive; what is the probability they are sick? Let denote disease and a positive test.
The evidence is the total positive rate, sick and healthy paths combined:
A positive test leaves the patient only likely to be sick: the base rate is so low that false positives swamp true ones. The tree makes the arithmetic visible — of every people, only true positives compete against false positives, so a positive result is wrong five times out of six.
This base-rate neglect is the most common probabilistic error; Bayes' rule corrects it.4
Information theory
Information theory quantifies surprise. The guiding intuition: a likely event carries little information, an unlikely event carries a lot, and the information of independent events adds. The unique function (up to base) satisfying these is the logarithm.5
Self-information of a single outcome, averaged over the distribution, is the Shannon entropy: the expected surprise, or the irreducible number of bits needed to encode draws from .
For a single binary variable with , entropy is the binary entropy function . It peaks where uncertainty is greatest — a fair coin — and vanishes at the certain ends.
KL divergence
To compare two distributions and over the same variable, measure the extra cost of encoding 's data with a code built for . That is the Kullback–Leibler divergence.
For example, take and over two outcomes, in nats:
The two numbers differ, so KL is not a metric. Which direction to minimize is a modeling choice with visible consequences, spelled out below.
Two properties make it the right tool, and one caveat makes it tricky.
The KL divergence is not symmetric: in general , so it is not a distance. The asymmetry matters in practice. is weighted by , so it penalizes a that puts low mass where is high. Fitting to this way makes mass-covering (spread out to cover all of 's support). The reverse is weighted by and makes mode-seeking (it picks one mode of and ignores the rest), the form variational inference minimizes.6
Cross-entropy and the loss
Cross-entropy is the entropy of plus the divergence from to , the total bits to encode 's data using 's code. The decomposition is immediate from the definitions.
This is the bridge from information theory to the training loop. Set , the empirical distribution of the labels, and , the network's predictive distribution. Cross-entropy then equals the negative log-likelihood, the standard classification loss:
For a one-hot label and softmax output over classes, the per-example cross-entropy collapses to a single term, the negative log-probability the model assigned to the true class:
- 1for numerical stability
- 2log-sum-exp normalizer
- 3for to do
- 4softmax probability
- 5, stable form
- 6return
The shifted-logit form computes without ever forming the tiny probability explicitly, the same log-sum-exp trick the numerical computation lesson develops in full.
Graphical models: distributions as factorizations
A joint over many variables is astronomically large — entries for -valued variables. Structured probabilistic models (graphical models) address this by writing the joint as a product of factors over small subsets of variables, encoding the conditional independencies that make most of those entries redundant.
| directed (Bayesian network) | undirected (Markov random field) | |
|---|---|---|
| factor | conditional | clique potential |
| factorization | ||
| normalized | automatically | needs partition function |
| reads as | causal / generative ordering | symmetric affinities |
The two families are two ways to draw the same idea (a joint is the product of local factors, one per edge group of a graph), and the chain rule is the directed case made fully explicit (every variable conditioned on all predecessors).
We develop inference and learning in these models (belief propagation, sampling, the partition function's intractability) in the structured probabilistic models chapter. For now the takeaway is structural: a graph is a set of conditional independence assumptions, and without them a joint over millions of pixels or tokens would not be learnable at all.
Which KL you minimize
The information-theoretic quantities here are the objectives of whole model families, and the direction of the KL is the design choice that separates them.
Which KL you minimize is which model you get. The variational autoencoder (Kingma and Welling, 2013) minimizes the forward, mass-covering inside its evidence lower bound, which is why VAE samples tend to be blurry averages that cover the data's support. A GAN's discriminator drives the generator toward a more mode-seeking objective, which is why GAN samples are sharp but can collapse to a few modes. The mass-covering / mode-seeking split this lesson draws from a bimodal toy is, at scale, the difference between the two dominant families of generative models.
Making the expectation differentiable. Training these models needs the gradient of an expectation where the distribution depends on . The reparameterization trick (Kingma and Welling, 2013) rewrites a Gaussian draw as with fixed, moving out of the sampling step so back-propagation can flow through it — a direct application of the change-of-variable view of a distribution.
Cross-entropy, softened. The cross-entropy loss derived above assumes a one-hot target, which pushes the model toward infinite-confidence logits. Label smoothing (Szegedy et al., 2016) replaces the one-hot target with a slightly spread distribution, so the objective is cross-entropy against a target of nonzero entropy — a calibrated, better-generalizing classifier that the KL decomposition explains exactly: raising lifts the loss floor and discourages overconfidence.78
Takeaways
- A network outputs a distribution; PMFs (discrete, values in ) and PDFs (continuous, densities that may exceed ) describe it. Marginalize to drop a variable, condition to fix one.
- The chain rule factors any joint and underlies autoregressive models. Conditional independence is the weaker, more useful variant of independence.
- Expectation is the universal average; covariance measures linear co-movement (zero covariance independence). The worked example gave , .
- A short distribution catalogue — Bernoulli, categorical, Gaussian (and multivariate), exponential, Laplace, Dirac/empirical, Gaussian mixture — models every output head and noise assumption in the field.
- Bayes' rule falls out of the chain rule and inverts a conditional; the base-rate example ( sick after a positive test) is the canonical lesson in not ignoring the prior.
- Information theory ties it together: self-information , entropy (peaking at the uniform/fair-coin case), the non-negative, asymmetric , and cross-entropy .
- Minimizing cross-entropy in minimizes — which is the negative-log-likelihood cross-entropy loss every classifier trains on.
Footnotes
- Goodfellow, Deep Learning, §3.3 — Probability Distributions: PMFs for discrete variables (values in ) versus PDFs for continuous ones (densities that integrate to one and may exceed ). ↩
- Chollet, Deep Learning with Python, Ch. 6 — Deep Learning for Text and Sequences: the autoregressive factorization realized by a sequence model that shares weights across positions. ↩
- Goodfellow, Deep Learning, §3.9.3 — The Gaussian Distribution: its two justifications — the central limit theorem and the maximum-entropy property among distributions of fixed variance. ↩
- Goodfellow, Deep Learning, §3.11 — Bayes' Rule: inverting a conditional via the chain rule and the law of total probability, with the evidence as the normalizing marginal. ↩
- Goodfellow, Deep Learning, §3.13 — Information Theory: self-information and Shannon entropy as the unique (log-based) measures of surprise and expected surprise. ↩
- Goodfellow, Deep Learning, §3.13 — Information Theory: the KL divergence's non-negativity (Gibbs) and asymmetry, and the mass-covering vs. mode-seeking behavior of its two directions. ↩
- Kingma and Welling (2013), Auto-Encoding Variational Bayes, arXiv:1312.6114 — the variational autoencoder's forward-KL evidence lower bound and the reparameterization trick that makes computable. ↩
- Szegedy, Vanhoucke, Ioffe, Shlens, Wojna (2016), Rethinking the Inception Architecture for Computer Vision, CVPR — label smoothing as cross-entropy against a target of nonzero entropy, improving calibration and generalization. ↩
╌╌ END ╌╌