id, title, category, status, canonical_id, aliases, duplicate_of, source_trust_level, confidence_score, verification_status, tags, raw_sources, last_reinforced, github_commit, tech_stack
id
title
category
status
canonical_id
aliases
duplicate_of
source_trust_level
confidence_score
verification_status
tags
raw_sources
last_reinforced
github_commit
tech_stack
wiki-2026-0508-kullback-leibler-divergence
Kullback-Leibler Divergence
10_Wiki/Topics
verified
self
KL Divergence
Relative Entropy
KL-D
none
A
0.95
applied
information-theory
divergence
ml
vae
rlhf
2026-05-10
pending
language
framework
python
torch, scipy
Kullback-Leibler Divergence
매 한 줄
"매 distribution 간의 directed information loss" . KL Divergence D_{\text{KL}}(P \| Q) = \mathbb{E}_P[\log P/Q] 는 reference distribution Q 로 P 를 encode 시 expected extra bits. Kullback & Leibler (1951) 가 정의했고, 2026 ML 에서는 VAE ELBO, RLHF (PPO/DPO), variational inference, distillation 의 매 core loss term.
매 핵심
매 Definition
discrete: D_{\text{KL}}(P\|Q) = \sum_x P(x) \log \frac{P(x)}{Q(x)}
continuous: \int p(x) \log \frac{p(x)}{q(x)} dx
always \ge 0 (Gibbs inequality), =0 iff P=Q
NOT symmetric , NOT a metric (no triangle inequality)
D_{\text{KL}}(P\|Q) = H(P, Q) - H(P) — cross-entropy minus entropy
매 Mode behavior
Forward $D_{\text{KL}}(P|Q)$ : Q must cover all mass of P → "mode-covering"
Reverse $D_{\text{KL}}(Q|P)$ : Q goes where P has mass → "mode-seeking"
VAE 는 reverse, EP 는 forward
매 응용
VAE ELBO : \mathbb{E}[\log p(x|z)] - D_{\text{KL}}(q(z|x) \| p(z)).
RLHF PPO : \beta \cdot D_{\text{KL}}(\pi \| \pi_{\text{ref}}) penalty.
Knowledge distillation : D_{\text{KL}}(p_T \| p_S) with temperature.
Variational inference : \arg\min_q D_{\text{KL}}(q \| p).
Mutual information : I(X;Y) = D_{\text{KL}}(p(x,y) \| p(x)p(y)).
💻 패턴
Discrete KL
PyTorch KL (numerically stable)
KL between Gaussians (closed form)
Distillation loss with temperature
RLHF PPO KL penalty (per-token)
Forward vs reverse comparison
매 결정 기준
Need
Form
variational posterior fit
reverse D_{\text{KL}}(q\|p)
spread (cover all modes)
forward D_{\text{KL}}(p\|q)
symmetric
JS divergence
bounded, metric
Wasserstein, Hellinger
RLHF stability
per-token reverse KL with \beta schedule
기본값 : 매 problem 따라 — VAE 면 reverse, EP 면 forward.
🔗 Graph
🤖 LLM 활용
언제 : 매 distribution-level loss 정의, RLHF 의 reference model anchoring, distillation.
언제 X : 매 distance metric 이 필요할 때 — KL 은 metric 이 X — Wasserstein 사용.
❌ 안티패턴
Symmetric 가정 : D_{\text{KL}}(P\|Q) \ne D_{\text{KL}}(Q\|P).
Disjoint support : Q(x)=0, P(x)>0 이면 \infty — smooth or use JS.
F.kl_div 의 input 순서 혼동 : 첫 arg 는 log-prob.
Distillation T 무시 : temperature T 없이 sharp distribution 사용 → poor signal.
RLHF 에서 KL collapse : \beta 너무 작으면 reward hacking.
🧪 검증 / 중복
Verified (Cover & Thomas 2006 textbook ch 2, MacKay 2003 ch 2, Kingma VAE 2013).
신뢰도 A.
🕓 Changelog
날짜
변경
2026-05-08
Phase 1
2026-05-10
Manual cleanup — KL definition, mode behavior, VAE/RLHF/distillation patterns