What is the difference Cross-entropy and KL divergence? Both the cross-entropy and the KL divergence are tools to measure the distance between two probability distributions, but what is the difference between them?
$$ H(P,Q) = -\sum_x P(x)\log Q(x)  $$
$$ KL(P | Q) = \sum_{x} P(x)\log {\frac{P(x)}{Q(x)}} $$
Moreover, it turns out that the minimization of KL divergence is equivalent to the minimization of cross-entropy.
I want to know them instinctively.
 A: This is how I think about it:
$$
D_{KL}(p(y_i | x_i) \:||\: q(y_i | x_i, \theta)) = H(p(y_i | x_i, \theta), q(y_i | x_i, \theta)) - H(p(y_i | x_i, \theta)) \tag{1}\label{eq:kl}
$$
where $p$ and $q$ are two probability distributions. In machine learning, we typically know $p$, which is the distribution of the target. For example, in a binary classification problem, $\mathcal{Y} = \{0, 1\}$, so if $y_i = 1$, $p(y_i = 1 | x) = 1$ and $p(y_i = 0 | x) = 0$, and vice versa. Given each $y_i \: \forall \: i = 1, 2, \ldots, N$, where $N$ is the total number of points in the dataset, we typically want to minimize the KL divergence $D_{KL}(p,q)$ between the distribution of the target $p(y_i | x)$ and our predicted distribution $q(y_i | x, \theta)$, averaged over all $i$. (We do so by tuning our model parameters $\theta$. Thus, for each training example, the model is spitting out a distribution over the class labels $0$ and $1$.) For each example, since the target is fixed, its distribution never changes. Thus, $H(p(y_i | x_i))$ is constant for each $i$, regardless of what our current model parameters $\theta$ are. Thus, the minimizer of $D_{KL}(p,q)$ is equal to the minimizer of $H(p, q)$.
If you had a situation where $p$ and $q$ were both variable (say, in which $x_1\sim p$ and $x_2\sim q$ were two latent variables) and wanted to match the two distributions, then you would have to choose between minimizing $D_{KL}$ and minimizing $H(p, q)$. This is because minimizing $D_{KL}$ implies maximizing $H(p)$ while minimizing $H(p, q)$ implies minimizing $H(p)$. To see the latter, we can solve equation (\ref{eq:kl}) for $H(p,q)$:
$$
H(p,q) = D_{KL}(p,q) + H(p) \tag{2}\label{eq:hpq}
$$
The former would yield a broad distribution for $p$ while the latter would yield one that is concentrated in one or a few modes. Note that it is your choice as a ML practitioner whether you want to minimize $D_{KL}(p, q)$ or $D_{KL}(q, p)$. A small discussion of this is given in the context of variational inference (VI) below.
In VI, you must choose between minimizing $D_{KL}(p,q)$ and $D_{KL}(q,p)$, which are not equal since KL divergence is not symmetric. If we once again treat $p$ as known, then minimizing $D_{KL}(p, q)$ would result in a distribution $q$ that is sharp and focused on one or a few areas while minimizing $D_{KL}(q, p)$ would result in a distribution $q$ that is wide and covers a broad range of the domain of $q$. Again, the latter is because minimizing $D_{KL}(q, p)$ implies maximizing the entropy of $q$.
A: I suppose it is because the models usually work with the samples packed in mini-batches. For KL divergence and Cross-Entropy, their relation can be written as
$$H(q, p) = D_{KL}(p, q)+H(p) = -\sum_i{p_ilog(q_i)}$$
so have $$D_{KL}(p, q) = H(q, p) - H(p)$$
From the equation, we could see that KL divergence can depart into a Cross-Entropy of p and q (the first part), and a global entropy of ground truth p (the second part).
In many machine learning projects, minibatch is involved to expedite training, where the $p'$ of a minibatch may be different from the global $p$. In such a case, Cross-Entropy is relatively more robust in practice while KL divergence needs a more stable H(p) to finish her job.
A: @zewen's answer can be misleading as he claims that in mini-batch training, CE can be more robust than KL. In most of standard mini-batch training, we use gradient-based approach, and the gradient of $H(p)$ with respect to $q$ (which is a function of our model parameter) would be zero. So in these cases, CE and KL as a loss function are identical.
I actually want to add a comment below @zewen's answer but I can't because I do not have enough reputation...
A: You will need some conditions to claim the equivalence between minimizing cross entropy and minimizing KL divergence. I will put your question under the context of classification problems using cross entropy as loss functions.
Let us first recall that entropy is used to measure the uncertainty of a system, which is defined as
\begin{equation}
 S(v)=-\sum_ip(v_i)\log p(v_i)\label{eq:entropy},
\end{equation}
for $p(v_i)$ as the probabilities of different states $v_i$ of the system. From an information theory point of view, $S(v)$ is the amount of information is needed for removing the uncertainty.
For instance, the event $I$ I will die within 200 years is almost certain (we may solve the aging problem for the word almost), therefore it has low uncertainty which requires only the information of the aging problem cannot be solved to make it certain. However, the event $II$ I will die within 50 years is more uncertain than event $I$, thus it needs more information to remove the uncertainties. Here entropy can be used to quantify the uncertainty of the distribution When will I die?, which can be regarded as the expectation of uncertainties of individual events like $I$ and $II$.
Now look at the definition of KL divergence between distributions A and B
\begin{equation}
 D_{KL}(A\parallel B) = \sum_ip_A(v_i)\log p_A(v_i) - p_A(v_i)\log p_B(v_i)\label{eq:kld}, 
\end{equation}
where the first term of the right hand side is the entropy of distribution A, the second term can be interpreted as the expectation of distribution B in terms of A. And the $D_{KL}$ describes how different B is from A from the perspective of A. It's worth of noting $A$ usually stands for the data, i.e. the measured distribution, and $B$ is the theoretical or hypothetical distribution. That means, you always start from what you observed.
To relate cross entropy to entropy and KL divergence, we formalize the cross entropy in terms of distributions $A$ and $B$ as
\begin{equation}
 H(A, B) = -\sum_ip_A(v_i)\log p_B(v_i)\label{eq:crossentropy}. 
\end{equation}
From the definitions, we can easily see
\begin{equation}
 H(A, B) = D_{KL}(A\parallel B)+S_A\label{eq:entropyrelation}. 
\end{equation}
If $S_A$ is a constant, then minimizing $H(A, B)$ is equivalent to minimizing $D_{KL}(A\parallel B)$.
A further question follows naturally as how the entropy can be a constant. In a machine learning task, we start with a dataset (denoted as $P(\mathcal D)$) which represent the problem to be solved, and the learning purpose is to make the model estimated distribution (denoted as $P(model)$) as close as possible to true distribution of the problem (denoted as $P(truth)$).
$P(truth)$ is unknown and represented by $P(\mathcal D)$. Therefore in an ideal world, we expect
\begin{equation}
 P(model)\approx P(\mathcal D) \approx P(truth)
\end{equation}
and minimize $D_{KL}(P(\mathcal D)\parallel P(model))$. And luckily, in practice $\mathcal D$ is given, which means its entropy $S(D)$ is fixed as a constant.
A: Some answers are already provided, while I would like to point out regarding the question itself

measure the distance between two probability distributions

that neither of cross-entropy and KL divergence measures the distance between two distributions-- instead they measure the difference of two distributions [1]. It's not distance because of the asymmetry, i.e. CE(P,Q) != CE(Q,P) and KL(P,Q) != KL(Q,P).
Reference:
[1] I. Goodfellow, Y. Bengio, A. Courville, and Y. Bengio, Deep learning, vol. 1 (MIT Press Cambridge, 2016).
