KL divergence
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
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.