Information Theory for ML
Entropy, cross-entropy and KL divergence as the language of learning.
Every time you train a classifier with cross-entropy, fit a model by maximum likelihood or squeeze an input into a representation, you are doing information theory. Shannon's quantities measure uncertainty, the cost of wrong beliefs and how much one variable reveals about another. This lesson develops them with proofs, then turns them into statements about what no learner can do.
What you’ll learn
- Define entropy, cross-entropy and KL divergence, interpret them as code lengths, and prove Gibbs' inequality .
- Show that log loss is cross-entropy, that maximum likelihood minimizes , and contrast the forward and reverse KL divergences.
- Prove the chain rule for mutual information and the data-processing inequality, and explain what they imply for learned representations.
- Prove Fano's inequality and use it to derive a minimax lower bound; connect description length to generalization, and weigh the contested information-bottleneck account of deep learning.
Entropy, cross-entropy and KL divergence
Code lengths. Shannon's source coding theorem (1948) makes entropy the limit of lossless compression. For prefix codes it reads: any prefix code for uses at least bits per symbol on average, and code lengths , which satisfy the Kraft inequality and so form a valid prefix code, achieve less than . Design the code for the wrong distribution , with lengths , and the average becomes up to the same rounding bit. The KL divergence is the price of a wrong belief, in extra bits per symbol.
Apply Jensen's inequality for the concave logarithm, averaging over the support of :
Equality in Jensen's step requires to be constant on the support of , and the last step requires to put no mass outside it; together they force :
Two corollaries. Against the uniform distribution on outcomes, , so entropy is at most , attained only by the uniform distribution. And no code beats the one matched to the truth:
A coin lands heads with probability 0.9. What is its entropy, in bits per flip?
Show the answer
0.47 bits
bits. A long run of such flips can be compressed to about 47% of its raw length, and no lossless code does better on average. A fair coin, the maximum, carries exactly 1 bit.
The KL divergence is neither symmetric nor a metric. For Bernoulli distributions, nats but nats. And it can be infinite: as soon as gives zero probability to an outcome that allows. Which direction you minimize therefore matters, as the next step shows.
Log loss, maximum likelihood and the direction of KL
The average negative log-likelihood of an i.i.d. sample is the cross-entropy between the empirical distribution and the model:
does not depend on , so maximum likelihood minimizes . By the law of large numbers the average converges to its population version, whose minimizer is the KL projection of the truth onto the model:
For classification the same identity holds conditionally. The expected log loss of a predicted distribution under the true is minimized only at , so log loss is a strictly proper scoring rule: honest probabilities are its unique optimum.
For a softmax model over logits , the gradient of the log loss is strikingly simple: predicted probabilities minus the one-hot label .
Forward versus reverse. Maximum likelihood minimizes the forward divergence , which is infinite if vanishes anywhere has mass: it is mass-covering. Fit a single Gaussian to a two-component mixture this way and you get the Gaussian with the mixture's mean and variance (for exponential families, minimizing the forward KL matches expected sufficient statistics), broad enough to straddle both modes. Variational inference minimizes the reverse divergence , because it needs expectations under the tractable only and tolerates an unnormalized . It punishes for putting mass where has little, so it is mode-seeking: it tends to lock onto one mode and to underestimate uncertainty.
You approximate a bimodal distribution (two well-separated bumps) by a single Gaussian , choosing to minimize the reverse divergence , as variational inference does. What do you typically get?
- A broad Gaussian spanning both bumps, with the mixture's mean and variance
- exactly, since the KL divergence is zero only at equality
- A narrow Gaussian sitting on one of the bumps
- A Gaussian centered in the valley between the bumps, with zero variance
Show the answer
C. A narrow Gaussian sitting on one of the bumps
The reverse KL averages under , so any -mass in the valley, where is tiny, is heavily penalized, while ignoring a whole mode costs nothing. The optimum hugs one mode (which one depends on initialization) and understates the spread: the classic behavior of variational approximations.
Mutual information and the data-processing inequality
The mutual information between and is the KL divergence between their joint distribution and the product of the marginals, so it is nonnegative and vanishes exactly when they are independent. It equals the reduction in uncertainty about one variable from observing the other, with the conditional entropy :
Let be a Markov chain: depends on only through , so and are independent given . Expand with the chain rule in both orders:
The Markov property makes , and conditional mutual information is nonnegative, so:
Equality holds exactly when , that is, when is a sufficient statistic of for . The same argument shows that passing two distributions through one channel can only shrink their KL divergence.
For learning, take the label , the input and any representation computed from alone, deterministic or noisy. Then is a Markov chain, and : no feature extractor, however deep, creates information about the label. A network's layers can only discard information, ideally the irrelevant part, and each layer's representation satisfies . What learning buys is not information but usable form: a representation from which a simple classifier can read the label.
Think first is a uniform random bit. is sent through a channel that flips it with probability 0.1, and is sent through a second, independent channel of the same kind. With the binary entropy, bits. What is ?
Two flips cancel, so with probability , and is itself a binary symmetric channel: bits, below 0.531, as the data-processing inequality requires. Each noisy stage destroys information that no later processing can recover.
Fano's inequality and lower bounds for learning
Let . It is a function of , so adding it to costs no entropy given :
Expand the other way. ; when , is determined by ; when , is one of the other values:
Combine, bound and , and for uniform substitute :
Fano's method turns this into lower bounds on estimation. Choose parameters that are -separated in the loss metric, and let nature pick one uniformly at random. Any estimator within of the truth identifies it (take the nearest ), so estimation is at least as hard as this -ary test. Since is at most the largest pairwise KL divergence between the data distributions, every estimator has . The art is to pack many hypotheses (large ) that are nonetheless statistically close (small ). With the same idea, through total variation and Pinsker's inequality, is Le Cam's two-point method.
Observe samples of ; the sample mean has risk . By the Gilbert–Varshamov bound, for there are vectors at pairwise Hamming distance at least . Set :
Choose , so the KL bound is while . Fano's ratio is then at most , which is at most once :
With probability at least the estimate is at least half the minimum separation, , from the truth. Squaring and averaging, for every estimator and :
The constant is poor, but the rate is exactly that of the sample mean: in high dimensions, error grows linearly with the number of unknowns per example. The same recipe gives the minimax rates of sparse regression, nonparametric regression and density estimation, and the information-theoretic limits that the No Free Lunch & Inductive Bias lesson approaches from the combinatorial side.
Description length, bottlenecks and an open debate
Rissanen (1978) proposed the minimum description length principle: prefer the hypothesis that minimizes a two-part code, bits to describe the hypothesis plus bits to describe the data with its help. Encoding real parameters to the precision the data can resolve, about , costs about bits, so for regular parametric models the two-part code length is, to leading order, , half the Bayesian information criterion. Short descriptions are Occam's razor made quantitative, and they come with a guarantee.
The information bottleneck (Tishby, Pereira & Bialek, 1999) asks for a stochastic representation of that is as compressed as possible while staying informative about : minimize over , with trading compression against prediction. Shwartz-Ziv & Tishby (2017) estimated and for the layers of networks during training, reported a fitting phase followed by a long compression phase, and the information-bottleneck account linked that compression to how well networks generalize.
A sounder bridge between information and generalization runs through the algorithm rather than the representation. If the loss is -sub-Gaussian for every hypothesis , an algorithm that outputs from a training sample of examples satisfies (Xu & Raginsky, 2017): an algorithm that reveals little about its particular training set cannot overfit it much. For a finite class, , and with for losses in this recovers the rate of the finite-class bound.
Key takeaways
- Entropy is the best achievable average code length, cross-entropy the length with a code built for , and (Gibbs) the excess, zero only when .
- Log loss is cross-entropy, a strictly proper scoring rule, with softmax gradient . Maximum likelihood minimizes the mass-covering ; variational inference minimizes the mode-seeking .
- . For a Markov chain , : representations can only discard information about the label, and sufficient statistics keep all of it.
- Fano's inequality, , turns packings of statistically close hypotheses into minimax lower bounds, for example order for estimating a Gaussian mean in dimensions.
- Short descriptions generalize: the Occam bound , MDL and BIC, and the algorithmic bound . The information-bottleneck account of deep learning remains contested.
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
The true distribution of a label is . Which predicted distribution minimizes the expected log loss ?
- The one-hot distribution on the most likely label
- The uniform distribution, which hedges against every outcome
- itself
- , which sharpens toward its mode
Show the answer
C. itself
The expected log loss is , and by Gibbs' inequality the KL term vanishes only at . Log loss rewards honest probabilities, which is why it is a strictly proper scoring rule and why minimizing it tends to produce calibrated models.
In the large-sample limit, maximum-likelihood estimation chooses the model that minimizes which divergence from the data distribution ?
- , the mode-seeking direction
- , the mass-covering direction
- The total variation distance between and
- The Jensen–Shannon divergence between and
Show the answer
B. , the mass-covering direction
, and does not depend on . That is why maximum-likelihood fits spread mass over everything the data can produce, and why a misspecified model fitted by likelihood converges to the KL projection of the truth.
A network maps an input to a representation and then to a prediction ; the label is . Which chain of inequalities must hold?
- , since training extracts information
- for any trained network
- None: deep networks can create new information about
Show the answer
A.
is a Markov chain, because each stage is computed from the previous one alone. The data-processing inequality then forces information about to be non-increasing along the chain; training can only choose what to discard.
Nature picks one of hypotheses uniformly at random, and your data carry bits about which one. By Fano's inequality, what is the smallest possible probability of naming the wrong hypothesis?
- At least 0.3
- At least 0.6
- At least 0.7
- At least
Show the answer
B. At least 0.6
In bits, . Three bits can narrow 1,024 candidates down to about 128, so no procedure can identify the right one reliably; a confident answer would need about 10 bits of information.
Further reading
- C. E. Shannon, "A mathematical theory of communication," Bell System Technical Journal 27 (1948), 379–423 and 623–656.
- T. M. Cover & J. A. Thomas, Elements of Information Theory, 2nd ed. (Wiley, 2006).
- D. J. C. MacKay, Information Theory, Inference, and Learning Algorithms (Cambridge University Press, 2003).
- M. J. Wainwright, High-Dimensional Statistics: A Non-Asymptotic Viewpoint (Cambridge University Press, 2019), chapter 15.
- A. M. Saxe, Y. Bansal, J. Dapello, M. Advani, A. Kolchinsky, B. D. Tracey & D. D. Cox, "On the information bottleneck theory of deep learning," Journal of Statistical Mechanics: Theory and Experiment 124020 (2019).