Entropy and KL Divergence

Entropy measures uncertainty in a distribution. KL divergence measures how much one distribution differs from another.

Entropy:

Cross-entropy:

KL divergence:

Equivalently:

These are related:

For a data distribution and model , maximum likelihood minimizes:

Since does not depend on , minimizing cross-entropy minimizes the forward KL from data to model.

For a finite dataset , the empirical negative log-likelihood is:

For token models, the same idea is usually averaged over tokens:

This is why comparing language-model losses requires knowing whether the loss is averaged per sequence, token, byte, or example.

Direction Matters

KL is not symmetric:

Forward KL tends to strongly penalize missing support where and is small. Reverse KL can prefer modes that avoid low-probability regions. This difference matters in variational inference, generative modeling, and policy optimization.

Support Conditions

KL is finite only when wherever :

If the model assigns zero probability to an event that the target distribution can produce, becomes infinite. In implementations, smoothing, clipping, or finite precision can hide this issue, but the modeling assumption is still there.

Continuous Variables

For continuous variables, sums become integrals:

Differential entropy can be negative and changes under reparameterization, so it should not be interpreted exactly like discrete entropy. KL divergence remains invariant to smooth invertible reparameterizations.

Common Objective Patterns

PatternFormula ShapeMeaning
classification cross-entropynegative log probability of the target class
maximum likelihoodfit model density to data
VAE regularizationkeep approximate posterior near prior
distillationmatch teacher distribution
policy regularization or reversecontrol policy drift

Why It Matters

  • Classification often minimizes cross-entropy.
  • VAEs use KL regularization.
  • Distribution shift can be described as a difference between training and deployment distributions.
  • Preference optimization and policy learning often compare distributions.
  • Calibration and uncertainty depend on interpreting probabilities, not only rankings.

Checks

  • Which distribution is the target and which is the model?
  • Is the divergence direction or ?
  • Are probabilities calibrated or only useful for ranking?
  • Is the loss averaged over examples, tokens, or classes?
  • Is the KL term a training objective, regularizer, diagnostic, or theoretical bound?
  • Is support mismatch possible?
  • Is the entropy discrete or differential?
  • Is the reported value normalized per token, per sequence, per dimension, or per example?