Negative Log-Likelihood, Entropy, Cross-Entropy, and KL Divergence
September 12, 2026 · Updated September 24, 2026
Contents
Throughout this note, let be an outcome, such as a class, token, or complete sequence, and let and be probability distributions over the same outcomes.
Negative Log-Likelihood
Suppose an observed outcome is and a model assigns it probability . Its likelihood is , so its negative log-likelihood (NLL) is
A likely outcome has a small NLL, while an outcome assigned near-zero probability has a very large NLL. For a dataset of observed outcomes , the average loss is
When the observations are drawn from a distribution , the expected NLL under is the cross-entropy defined below.
Entropy
In information theory, entropy () measures the average uncertainty, surprise, or information content in a distribution of messages or data. The concept was introduced by Claude Shannon.
For a distribution , entropy is
For example:
- A concentrated distribution such as has low entropy.
- A flat distribution such as has high entropy.
Equivalently, entropy is the expected surprise when outcomes come from and are evaluated using itself:
Cross-Entropy
Cross-entropy measures how well a distribution predicts outcomes distributed according to a target distribution :
This form comes from expected negative log-likelihood. For one outcome , the loss under is . Because produces that outcome with probability , averaging the loss over outcomes from gives
Here, determines how much weight the target distribution gives outcome , while measures how poorly predicts it.
KL Divergence
KL divergence measures how one probability distribution differs from another. For discrete distributions, it is1
For continuous distributions with densities and , the sum becomes an integral:
KL divergence can also be written as an expectation. When is the target distribution and is the approximation, the direction from to is called forward KL:
Swapping the arguments gives the reverse KL:
The direction changes the distribution used to weight the expectation: forward KL samples from , while reverse KL samples from . KL divergence is not symmetric, so the order of the arguments matters:
By Gibbs’ inequality, both directions are nonnegative. The individual log-ratio terms inside the expectation can still be negative.2
Cross-Entropy and Forward KL
Cross-entropy decomposes into the entropy of the target distribution and the forward KL divergence:
When is fixed, is constant. A learned distribution can therefore minimize cross-entropy only by minimizing forward KL:
Both objectives consequently have the same optimum.3 This is why a cross-entropy objective against a fixed teacher or data distribution can be interpreted as forward-KL minimization.
SFT and RL Through the KL Lens
Adapted from Cameron R. Wolfe’s explanation of SFT and RL through KL divergence.[2]
The same KL perspective clarifies an important difference between supervised fine-tuning (SFT) and KL-regularized reinforcement learning. For a fixed prompt , let denote a complete output sequence. To keep the equations uncluttered, all distributions below are implicitly conditioned on .
The key distinction is the distribution from which completions are sampled. SFT averages its loss over a fixed dataset distribution, so its training signal is offline. RL averages reward over completions sampled from the current model, so its training signal is online, or on-policy.
SFT as Forward KL
Let be the distribution represented by the SFT dataset and the model being trained. The SFT negative log-likelihood is
Because does not depend on the model parameters, minimizing the SFT loss is equivalent to minimizing the forward KL divergence:
The data distribution appears first in the KL and therefore supplies the samples in the expectation.
KL-Regularized RL as Reverse KL
For KL-regularized RL, let be the current policy, a fixed reference policy, the reward, and the strength of the KL penalty. The idealized objective is
Define the reward-induced target distribution
This target reweights the reference policy toward higher-reward completions. Substituting its log-probability into the reverse KL gives
Because does not depend on , maximizing this KL-regularized RL objective is equivalent to minimizing . This is a reverse KL because the learned policy appears first and the fixed reward-induced target appears second.
The explicit term inside is the regularizer that keeps the policy near the reference. The reverse-KL interpretation comes from rewriting the complete reward-plus-regularization objective.
Mode Covering Versus Mode Seeking
These two KL directions help explain the different tendencies of SFT and RL:
- SFT is mode-covering. Forward KL averages over . If the data assigns positive probability to a completion while the model assigns it near-zero probability, its contribution grows without bound. The model is therefore encouraged to assign probability across all modes represented in the data.
- KL-regularized RL is mode-seeking. Reverse KL averages over . Completions to which the current policy assigns very little probability are rarely sampled and receive little direct weight. The policy can therefore concentrate on a subset of high-reward modes instead of covering every mode of .
Mode covering and mode seeking describe tendencies, not guarantees. The practical behavior also depends on model capacity, optimization, reward quality, sampling, and the strength of the reference-policy constraint.
TODO
- Jensen-Shannon divergence
Footnotes
-
Take two distributions over three outcomes:
A 0.50 0.25 B 0.30 0.25 C 0.20 0.50 Summing the final column gives
↩ -
For outcome C in the worked example, . This is one term inside the weighted sum, not the complete KL divergence. Other terms compensate for it, and the total KL remains nonnegative. ↩
-
For a numerical check, suppose and . Using natural logarithms:
Quantity Calculation Cross-entropy Target entropy KL divergence The displayed values satisfy . If improves until , then and . The minimum cross-entropy occurs when matches , but it does not generally become zero because the fixed target entropy remains. ↩
Bibliography
- Howard Chen, Noam Razin, Karthik Narasimhan, and Danqi Chen, “Retaining by Doing: The Role of On-Policy Data in Mitigating Forgetting,” arXiv preprint arXiv:2510.18874, 2025.
- Cameron R. Wolfe, “SFT and RL Training Objectives as Forward and Reverse KL Divergence,” X, 2026.