Probability and statistics

DKL(q ∥ p)D_{\mathrm{KL}}(q \,\|\, p) KL divergence

How different distribution q is from p. Zero when they match; not symmetric.

In ML papers

DKL(q ∥ p)=Ex∼q[log⁡q(x)p(x)]D_{\mathrm{KL}}(q \,\|\, p) = \mathbb{E}_{x \sim q}\left[\log \frac{q(x)}{p(x)}\right] measures how much qq differs from pp. It is never negative and is zero only when the two distributions are the same. It shows up as the regularizer in a VAE's ELBO, the penalty keeping an RLHF policy near its reference model, and in distillation.

The double bar ∥\| separates the two arguments. It is not a norm.

How to type it

LaTeXShows
D_{\mathrm{KL}}(q \,\|\, p)DKL(q ∥ p)D_{\mathrm{KL}}(q \,\|\, p)
\mathrm{KL}(q \| p)KL(q∥p)\mathrm{KL}(q \| p)

A worked example

p=(0.5,0.5), q=(0.9,0.1):DKL(p ∥ q)=0.5ln⁡0.50.9+0.5ln⁡0.50.1≈0.51p = (0.5, 0.5),\ q = (0.9, 0.1): \quad D_{\mathrm{KL}}(p \,\|\, q) = 0.5 \ln\tfrac{0.5}{0.9} + 0.5 \ln\tfrac{0.5}{0.1} \approx 0.51

In nats (natural log). Swap the arguments and you get a different number, about 0.370.37.

Common confusions

Equations that use it

Related

log⁡pθ(x)\log p_\theta(x)LogarithmEx∼p[f(x)]\mathbb{E}_{x \sim p}[f(x)]Expectationp(x),  q(z)p(\mathbf{x}), \; q(\mathbf{z})Probability p(x)

Decode this example →