---
title: Define entropy, cross-entropy and KL divergence for discrete distributions, show how they relate, and explain why…
url: https://gurkanozkan.ai/learn/questions/research-entropy-cross-entropy-kl-014/
markdown: https://gurkanozkan.ai/learn/questions/research-entropy-cross-entropy-kl-014.md
kind: question
role: Research
stage: Technical
difficulty: Medium
json: https://gurkanozkan.ai/api/learn/questions/research-entropy-cross-entropy-kl-014.json
robots: noindex
---

# Define entropy, cross-entropy and KL divergence for discrete distributions, show how they relate, and explain why minimising cross-entropy loss equals maximum likelihood. Why is KL asymmetric, and when does the direction matter?

Research · Technical · Medium

Theme reported publicly: [OpenAI](https://www.aced.io/guides/openai-research-engineer-interview)

## Answer

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

### In short

- H(p) = -Σ p_i log p_i; H(p,q) = -Σ p_i log q_i; KL(p||q) = Σ p_i log(p_i/q_i) = H(p,q) - H(p).
- KL(p||q) >= 0 by Gibbs' inequality, equality only when p = q (and q > 0 wherever p > 0).
- With p the empirical data, H(p,q_theta) = -(1/N) Σ log q_theta(x_i) = -(1/N) log L(theta), so minimising cross-entropy is maximising likelihood.
- Forward KL (data||model) is mass-covering; reverse KL (model||data) is mode-seeking and can collapse to a subset of modes.
- Perplexity = exp(cross-entropy in nats) (2^H if cross-entropy is in bits).

### In full

For discrete distributions over the same support, entropy is H(p) = -Σ p_i log p_i, cross-entropy is H(p,q) = -Σ p_i log q_i, and KL divergence is KL(p||q) = Σ p_i log(p_i/q_i) = H(p,q) - H(p). KL is nonnegative by Gibbs' inequality, with equality only when p and q match (assuming q is positive wherever p is). If p is the empirical data distribution, H(p,q_theta) = -(1/N) Σ log q_theta(x_i) = -(1/N) log L(theta), so minimising cross-entropy over theta is exactly maximising the likelihood, since H(p) is constant. KL is asymmetric because it is an expectation under p of log(p/q), not under q of log(q/p), so KL(p||q) and KL(q||p) measure different failures. The direction matters: forward KL (data||model) forces the model to cover data mass, while reverse KL (model||data) lets the model ignore low-probability data regions and concentrate on a mode, which is why variational inference uses reverse KL and why the RLHF KL penalty to a reference policy behaves as a mode-seeking/support-constraining term rather than a full data-covering fit. Perplexity is just exp(cross-entropy in nats), or 2^H if the cross-entropy is measured in bits.

*Checked against sources by an independent AI reviewer.*

## What a strong answer covers

- H(p) = −Σp log p. H(p,q) = H(p) + KL(p‖q).
- KL ≥ 0 (Gibbs' inequality), with equality only when the distributions match.
- With p as the empirical data, minimising cross-entropy is the same as maximising likelihood.
- Forward KL is mass-covering; reverse KL is mode-seeking (variational inference, the KL penalty in RLHF).
- Perplexity = exp(cross-entropy in nats).

## Common mistakes

- Calling KL a metric.
- Getting the argument order wrong.

## Topic guides

- [Maths and statistics for ML interviews](https://gurkanozkan.ai/learn/topics/maths-statistics.md)
---

*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.*
