How much does it cost to use the wrong distribution?
See how the true and predicted probabilities enter the entropy formula, then derive KL divergence as the extra log loss incurred by using the predicted distribution.
Let $p(x)$ be the probability that outcome $x$ occurs, and let $q(x)$ be the probability I assign to it. Changing my prediction changes $q(x)$. The outcome still occurs with probability $p(x)$. With that distinction in mind, consider the entropy formula from Part 1.
\[H(p)=\sum_x p(x)\,[-\ln p(x)]=\mathbb{E}_{X\sim p}[-\ln p(X)].\]The same probability appears twice. Inside the logarithm, $p(x)$ determines the information content of one outcome. The less likely $x$ is, the more information $-\ln p(x)$ we gain when we observe it. Outside the logarithm, $p(x)$ gives that outcome its weight in the average.
Cross entropy
If I assign probability $q(x)$ to an outcome and it occurs, my log loss is $-\ln q(x)$. Giving the observed outcome a high probability yields a small loss. Giving it a low probability yields a large one. To find the average loss per prediction, weight the loss $-\ln q(x)$ by the probability $p(x)$ that the outcome occurs. This average is the cross entropy.
\[H(p,q)=\sum_x p(x)\,[-\ln q(x)]=\mathbb{E}_{X\sim p}[-\ln q(X)].\]If I assign every outcome its true probability, then $q=p$, so $H(p,q)=H(p)$. Even if I know exactly how often each outcome occurs, I can still be uncertain which one will occur next.
KL divergence
Predicting with $q$ gives an average log loss of $H(p,q)$. Using the true distribution $p$ gives an average log loss of $H(p)$. To find out how much extra loss I incur by using $q$, take the difference.
\[\begin{aligned} H(p,q)-H(p) &=\sum_x p(x)\bigl[-\ln q(x)+\ln p(x)\bigr] \\ &=\sum_x p(x)\ln\frac{p(x)}{q(x)} \\ &=\mathbb{E}_{X\sim p}\!\left[\ln\frac{p(X)}{q(X)}\right] =D_{\mathrm{KL}}(p\parallel q). \end{aligned}\]This difference is the Kullback–Leibler divergence, or KL divergence. For an individual outcome, assigning it more than its true probability can give me a smaller loss when it occurs. Averaged over the true distribution $p$, the difference is always nonnegative. It is zero only when $q=p$. The smallest average log loss I can achieve is therefore $H(p)$, and using $q$ adds $D_{\mathrm{KL}}(p\parallel q)$ to that loss.
Why is the difference nonnegative on average?
Suppose $p$ and $q$ both assign positive probability to every outcome. Since $-\ln t$ is strictly convex, Jensen’s inequality gives
\[\begin{aligned} D_{\mathrm{KL}}(p\parallel q) &=\mathbb{E}_{X\sim p}\!\left[-\ln\frac{q(X)}{p(X)}\right] \\ &\ge -\ln\mathbb{E}_{X\sim p}\!\left[\frac{q(X)}{p(X)}\right] =-\ln\sum_x q(x)=0. \end{aligned}\]Equality requires the ratio $q(x)/p(x)$ to be the same for every outcome. Since each distribution sums to one, that ratio must be one. If an outcome has positive probability under $p$ and I assign it $q(x)=0$, the log loss for that outcome is infinite.