โœ‚๏ธ KL Divergence

Mathematics / Information Theory

KL divergence measures the difference in two probability distributions and . If is the "true" distribution and is the "approximation," it measures

The third form is exactly the difference between ๐Ÿ’ง Cross Entropy and ๐Ÿ”ฅ Entropy. We can interpret this value as the expected extra number of bits to transmit using our predicted instead of true . It's equal to if .

Info

Note that this value is not a true distance: it's non-symmetric and does not satisfy triangle inequality. However, it is non-negative.

Reverse KL Divergence

Reverse KL divergence, as its name suggests, measures

The key difference is the following:

  1. In forward KL, is penalized for being too small when is largeโ€”failing to cover . Here, KL is mass-covering.
  2. In reverse KL, is penalized for being too large when is smallโ€”failing to match dominant modes of . Here, KL is mode-seeking.

Applications

We commonly see KL divergence or cross entropy used as loss functions in categorization problems (for example, in ๐Ÿฆ  Logistic Regression). The truth label is a one-hot encoding, and our prediction consists of softmax probabilities. In this case, our KL divergence simplifies to

for a single datapoint where is the true label. Moreover, since the entropy of the true labels is constant regardless of our model's predictions, we can instead just use cross entropy as our loss function.

We can also apply KL divergence to ๐Ÿ’ฐ Information Gain. Rather than computing it as the difference in entropies before and after knowing , it can instead be interpreted as the difference in distributions

Content by William Liang, written in Obsidian.
Thank you to all the educators who made these notes possible.