Reward Modeling › Worked Example: Computing Preference Loss
Language AI HandbookAll chapters Reward Modeling › Worked Example: Computing Preference LossOne section · Sections in this chapter6 / 10 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
Let's trace through the loss computation for a single preference pair to solidify understanding. Walking through a concrete numerical example makes the abstract formulas tangible and reveals how the loss function behaves in practice across different scoring scenarios.
Suppose we have a prompt asking for a simple explanation of gravity, with two candidate responses. Response A (the chosen response) gives a simple, accessible explanation using an everyday analogy. Response B (the rejected response) gives a technically correct but overly complex description using field equations. After training, our reward model produces the following scores:
- for the preferred response (A, the accessible explanation)
- for the rejected response (B, the technical description)
Step 1: Compute the reward difference.
where:
- : the reward difference between the chosen and rejected responses
- : the reward score for the preferred response ()
- : the reward score for the rejected response ()
This positive difference of 1.3 indicates the model correctly believes the preferred response is better. The question is: how confident is this prediction, and how much loss does it incur?
Step 2: Convert to a preference probability via the sigmoid.
where:
- : the calculated probability that the model assigns to the correct preference
- : the sigmoid function applied to the reward difference
- : the resulting probability (approximately 78.6%)
The model assigns about 78.6% probability to the correct preference. This is a reasonably confident prediction. This reflects the moderately large reward margin of 1.3 points. The model is more likely than not to get this comparison right, but it is not highly certain.
Step 3: Compute the negative log-likelihood loss.
where:
- : the computed preference loss value
- : the negative log-likelihood of the correct preference
The loss of 0.241 is relatively small, showing the model is performing well on this example. For reference, a model that assigns exactly 50% probability (pure uncertainty) would incur a loss of .
Step 4: Compare with an incorrect ranking scenario.
Now consider if the model had incorrectly scored the responses, assigning higher reward to the technical description:
- (accessible explanation, incorrectly ranked lower)
- (technical description, incorrectly ranked higher)
Following the same steps: the reward difference is . The sigmoid gives . The loss is .
Step 5: Compare the two loss values.
The loss of 1.54 for the incorrect ranking is more than six times larger than the 0.241 for the correct ranking. This asymmetry demonstrates how the loss heavily penalizes incorrect rankings while giving smaller gradients when the model is already correct. The gradient signal is strongest where the model needs improvement, naturally focusing the learning process on mistakes.
Step 6: Consider the gradient implications.
The gradient of the loss with respect to the reward difference is . For the correct-ranking case (), this gradient has magnitude . For the incorrect-ranking case (), the gradient magnitude is . While the gradient magnitudes are the same (by symmetry of the sigmoid), the direction is reversed: for the correct ranking, the gradient pushes toward a larger margin; for the incorrect ranking, it pushes toward flipping the order entirely. The large loss difference between the two cases reflects the log transformation, which compresses the scale near 1 and expands it near 0, creating the six-fold difference in loss from equal-magnitude gradient contributions.


This demonstration illustrates that the preference loss is a ranking objective and a calibrated probabilistic one. The gradients it produces reflect both the direction of the error and the model's current confidence, creating a training signal that naturally focuses effort where the model most needs to improve.