---
title: Define entropy, cross-entropy and KL divergence. Derive the evidence lower bound for a latent-variable model and…
url: https://gurkanozkan.ai/learn/questions/mle-kl-divergence-entropy-and-the-elbo-21/
markdown: https://gurkanozkan.ai/learn/questions/mle-kl-divergence-entropy-and-the-elbo-21.md
kind: question
role: ML engineering
stage: Technical
difficulty: Hard
json: https://gurkanozkan.ai/api/learn/questions/mle-kl-divergence-entropy-and-the-elbo-21.json
robots: noindex
---

# Define entropy, cross-entropy and KL divergence. Derive the evidence lower bound for a latent-variable model and explain each term in a VAE.

ML engineering · Technical · Hard

## Answer

*Model answer, written in a candidate's voice*

### In short

- H(p) = -Σ p log p; cross-entropy H(p,q) = -Σ p log q = H(p) + KL(p‖q).
- KL(p‖q) = Σ p log(p/q) ≥ 0, zero iff p=q, and asymmetric.
- ELBO: log p(x) ≥ E_q[log p(x|z)] - KL(q(z|x)‖p(z)), with gap KL(q(z|x)‖p(z|x)).
- VAE: reconstruction term E_q[log p_theta(x|z)] plus regulariser KL(q_phi(z|x)‖p(z)) towards the prior.
- Reparameterisation: z = mu_phi(x) + sigma_phi(x) ⊙ epsilon, epsilon ~ N(0,I), enabling gradients through z.
- Forward KL is mode-covering/zero-avoiding; reverse KL is mode-seeking/zero-forcing. The ELBO minimises reverse KL from q(z|x) to the true posterior, so q tends to under-cover posterior modes; maximum likelihood is forward KL from the data.

### In full

Entropy is H(p) = -Σ p_i log p_i, cross-entropy is H(p,q) = -Σ p_i log q_i, and they are related by H(p,q) = H(p) + KL(p‖q). KL(p‖q) = Σ p_i log(p_i/q_i) is nonnegative by Jensen/Gibbs, equals zero only when p=q, and is asymmetric, so KL(p‖q) and KL(q‖p) are different objectives. For a latent-variable model, log p(x) = log ∫ q(z|x) p(x,z)/q(z|x) dz ≥ E_q[log p(x,z) - log q(z|x)] = E_q[log p(x|z)] - KL(q(z|x)‖p(z)), with the remaining gap equal to KL(q(z|x)‖p(z|x)). In a VAE, the encoder q_phi(z|x) and decoder p_theta(x|z) give an objective that is a reconstruction term, E_q[log p_theta(x|z)], plus a regulariser pulling the approximate posterior towards the prior, KL(q_phi(z|x)‖p(z)), usually a standard normal. The reparameterisation trick writes z = mu_phi(x) + sigma_phi(x) ⊙ epsilon with epsilon ~ N(0,I), so the sample is differentiable and gradients can flow from the reconstruction loss into the encoder. Forward KL, KL(p‖q), is mode-covering/zero-avoiding, while reverse KL, KL(q‖p), is mode-seeking/zero-forcing. Maximising the ELBO minimises the reverse KL from q(z|x) to the true posterior p(z|x), so the approximate posterior tends to lock onto one mode and understate posterior spread; maximum-likelihood training, by contrast, minimises the forward KL from the data distribution to the model and is mode-covering.

*Corrected by an independent AI reviewer.*

## What a strong answer covers

- H(p) = −Σ p log p; CE = H(p) + KL(p‖q); KL ≥ 0 and is asymmetric.
- log p(x) ≥ E_q[log p(x|z)] − KL(q(z|x) ‖ p(z)), via Jensen's inequality or the KL gap.
- VAE: a reconstruction term plus a regulariser towards the prior; the reparameterisation trick.
- Forward vs reverse KL behaviour (mode-covering vs mode-seeking).

## Common mistakes

- treating KL as a distance metric
- dropping the expectation over q.
---

*Study material compiled with AI: drafted by a local model (Inkling 2 Mini) from public sources, then checked against those sources by independent AI reviewers (Claude) in November 2026. Not reviewed line by line by a person.*
