One-Line Summary: Entropy, KL divergence, and mutual information -- quantifying uncertainty, surprise, and the difference between distributions.

Prerequisites: Probability Fundamentals, Maximum Likelihood Estimation.

What Is Information Theory?

Imagine you learn that the sun rose this morning. That is unsurprising -- it carries almost no information. Now imagine learning that a major earthquake just struck your city. That is highly surprising and carries enormous information. Information theory, founded by Claude Shannon in 1948, formalizes this intuition: unlikely events carry more information, and the average information content of a source is its entropy.

In ML, information theory provides the mathematical foundation for loss functions (cross-entropy), model comparison (KL divergence), feature selection (mutual information), and the theoretical limits of data compression and communication. It is the bridge between probability and learning.

How It Works

Shannon Entropy

The entropy of a discrete random variable with PMF is:

By convention, (justified by continuity). When using , entropy is measured in bits; with , in nats.

Entropy quantifies the average uncertainty or "surprise" in a distribution:

  • Deterministic ( for some ): bits. No surprise.
  • Uniform over outcomes: bits. Maximum surprise for outcomes.
  • Biased coin (): bits. Less surprising than fair coin ( bit).

For continuous variables, the differential entropy is:

Unlike discrete entropy, differential entropy can be negative. Among continuous distributions with fixed variance , the Gaussian maximizes differential entropy: .

Cross-Entropy

The cross-entropy between a true distribution and a model distribution is:

Cross-entropy measures the average number of bits needed to encode data from using a code optimized for . It decomposes as:

Since is constant with respect to , minimizing cross-entropy is equivalent to minimizing KL divergence. This is precisely why cross-entropy is the standard loss function for classification: it drives the model distribution toward the data distribution .

KL Divergence

The Kullback-Leibler divergence from to is:

Key properties:

  • (Gibbs' inequality), with equality iff .
  • Not symmetric: in general. This asymmetry has practical consequences.
  • Not a metric: Violates symmetry and the triangle inequality.

The asymmetry matters in practice:

  • Forward KL : penalizes for assigning low probability where is high. Produces mean-seeking approximations. Used in MLE.
  • Reverse KL : penalizes for assigning high probability where is low. Produces mode-seeking approximations. Used in variational inference.

Mutual Information

The mutual information between and measures how much knowing one reduces uncertainty about the other:

where is the conditional entropy.

Properties:

  • , with equality iff and are independent.
  • (symmetric, unlike KL divergence).
  • (self-information equals entropy).

Mutual information is used in:

  • Feature selection: Rank features by .
  • Information Bottleneck: Compress representations while preserving relevant information.
  • Representation learning: InfoNCE loss in contrastive learning is a lower bound on mutual information.

Information Gain and Decision Trees

Information gain is the reduction in entropy achieved by splitting on a feature:

This is exactly mutual information. Decision tree algorithms like ID3 and C4.5 greedily select the feature with maximum information gain at each split. CART uses the closely related Gini impurity instead, which approximates entropy near its maximum.

Connection to ML Loss Functions

The deep connection between information theory and ML loss functions:

ML LossInformation-Theoretic View
Binary cross-entropy for Bernoulli distributions
Categorical cross-entropy for categorical distributions
MSE (Gaussian model)Proportional to under Gaussian
KL loss in VAEs$D_{\text{KL}}(q(z

Why It Matters

Information theory provides the theoretical underpinning for why certain loss functions work. Cross-entropy is not an arbitrary choice -- it is the information-theoretically optimal objective for matching distributions. KL divergence tells you exactly how "far apart" two distributions are. Mutual information quantifies relevance without assuming linearity. These tools are essential for understanding generative models (VAEs, diffusion), contrastive learning, and the information-theoretic limits of learning.

Key Technical Details

  • Jensen's inequality underlies the non-negativity of KL divergence: for concave .
  • Data processing inequality: For a Markov chain , . Processing data cannot create information.
  • KL divergence for Gaussians has a closed form: .
  • Label smoothing in classification adds a small uniform component to one-hot labels, preventing the model from driving to extreme values and implicitly regularizing the cross-entropy.
  • Entropy is maximized by the uniform distribution (discrete) or the Gaussian (continuous, given fixed variance). This is the principle of maximum entropy, used to derive least-informative priors.

Common Misconceptions

  • "KL divergence is a distance metric." It is not symmetric and does not satisfy the triangle inequality. The Jensen-Shannon divergence where is a true metric (after taking the square root).
  • "Cross-entropy and KL divergence are different objectives." When optimizing over model parameters, they differ only by a constant (), so they have identical gradients and optima.
  • "Low entropy means a good model." A model can have low entropy by being overconfident about wrong predictions. Calibration matters as much as sharpness.

Connections to Other Concepts

  • probability-fundamentals.md: Entropy is defined in terms of probability distributions. All information-theoretic quantities are functions of distributions.
  • maximum-likelihood-estimation.md: MLE minimizes cross-entropy, which equals KL divergence up to a constant. This is the fundamental link between information theory and parameter estimation.
  • statistical-inference.md: Fisher information (different from Shannon information) bounds estimator variance but is conceptually related -- both quantify "information" in data.
  • derivatives-and-gradients.md: The gradient of cross-entropy loss drives parameter updates in neural network training.
  • norms-and-distance-metrics.md: KL divergence measures distributional distance, complementing geometric distances (L2, cosine) in feature space.

Further Reading

  • Cover & Thomas, Elements of Information Theory (2006) -- The standard reference, comprehensive and rigorous.
  • MacKay, Information Theory, Inference, and Learning Algorithms (2003) -- Beautifully written, bridges information theory and ML; freely available online.
  • Shannon, "A Mathematical Theory of Communication" (1948) -- The foundational paper that started it all.