Maths for ML / Notation

DKL(P ∥ Q)D_{\mathrm{KL}}(P \,\Vert\, Q)

KL divergence

Probability and statisticsAdvanced

Say it “K L divergence of P from Q”

Measures how different distribution Q is from P. Not symmetric: swapping P and Q changes the answer.

Example

DKL(P∥Q)=∑xP(x)log⁡P(x)Q(x)D_{\mathrm{KL}}(P\Vert Q) = \sum_x P(x)\log\frac{P(x)}{Q(x)}

In code

scipy.stats.entropy(p, q)
torch.nn.functional.kl_div(q.log(), p, reduction='sum')

Where you’ll see it in ML

VAEs, knowledge distillation, RLHF penalty keeping a model near its reference.

Don’t confuse it with

← All 94 symbols