Summary
KL divergence averages a log probability ratio under its first distribution. Swapping the arguments changes that weighting, so the same candidates can receive opposite rankings. Start with expected surprisal, not a distance analogy.
Task: compare only two candidates for a three-outcome target:
Each vector sums to one. Use natural logarithms, giving scores in nats:
Properties
Terms with contribute zero, including when . If but , the divergence is infinite. Otherwise finite probability vectors give a nonnegative score, zero exactly when the distributions agree. KL is not symmetric and does not satisfy metric guarantees such as the triangle inequality.
Forward vs. reverse KL
Hold the target and both candidates fixed while changing only the sampling weights.
Learning objective
Changing which distribution does the averaging reverses this candidate ranking
Derivation
Which distribution supplies the averaging weights in reverse KL?
Connection to cross-entropy
Combining equal terms gives four complete expectations:
| Expectation | Weighted log terms | Score, nats |
|---|---|---|
Forward KL prefers cover; reverse KL prefers left among these candidates. Reversing KL is not negating a forward score: it also changes the weights. For fixed discrete , add and subtract :
Only stays constant when optimizing . Categorical log-loss minimization and forward-KL minimization therefore have the same optimizer over the chosen model family.
Remove candidate support
New task: replace the left candidate with . Picture and change: the target’s final outcome still has mass , but the candidate now assigns zero. Check: forward KL becomes infinite; reverse KL remains nats. Use when: truncation or exact zeros remove support; exchanging arguments changes the requirement.
Expand the candidate set
New task: permit as another candidate. Every log ratio is now zero for that candidate. Check: both objectives attain zero at , beating the original choices. Use when: a richer approximation family becomes available; reverse KL does not inevitably select one mode.
Failure and transfer
For and , the wrong average is . The actual is . Wrong sampling weights changed the quantity, not the nonnegativity theorem.
Reconstruct: fixed has entropy nats and cross-entropy nats. What is KL?
Answer
It is nats. Minimizing cross-entropy over also minimizes forward KL only because this , and hence its entropy, stays fixed.
Why the divergence is nonnegative
For positive , . Apply this with wherever :
Equality requires on the positive support and no remaining candidate mass outside it. Zero candidate probability at positive target mass instead gives infinite KL immediately. The coding interpretation compares expected ideal code lengths under the same sampling law; base-two logarithms give bits rather than nats.
Continuous laws and empirical samples
For general measures, finite KL requires absolute continuity and suitable integrability. For densities, use against the common base measure. An atomic empirical measure has infinite KL to a continuous law assigning zero probability to every observed point. Empirical negative log density remains meaningful; it is not that literal finite empirical-to-continuous KL identity.
Common usage in ML
| Use case | Direction |
|---|---|
| Classification cross-entropy loss | Forward |
| Variational inference | Approximate posterior versus model posterior |
| Policy regularization | Name both policies, expectation, and penalty direction explicitly |
| Knowledge distillation | Teacher versus student distributions at the specified temperature |
| t-SNE | High-dimensional versus low-dimensional pairwise probability distributions |
PPO’s clipped surrogate is not generally an exact KL constraint. Information bottleneck objectives also use distinct joint, marginal, and conditional laws; name them before applying an identity.
Common pitfalls
Jensen-Shannon divergence averages and with . That symmetric bounded quantity is not KL with swapped arguments or a universal GAN objective. Finite-sample density estimates introduce their own support choices and estimation bias. Changing the feasible family can matter as much as divergence direction.
Related: entropy, mutual information, and information gain, cross-entropy and softmax, and variational autoencoders.