DPO Derivation › Worked Example
Language AI HandbookAll chapters DPO Derivation › Worked ExampleOne section · Sections in this chapter7 / 12 ↓
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 derivation with concrete numbers to build intuition. Suppose we have a prompt = "Write a haiku about autumn" and two responses:
- (preferred): "Crimson leaves descend / Dancing on October wind / Earth prepares to sleep"
- (dispreferred): "Leaves fall down in fall / The weather gets cold outside / I like pumpkin spice"
The preferred response demonstrates poetic craft through concrete imagery ("crimson," "dancing"), sensory detail, and thematic resonance with the natural world. The dispreferred response is grammatically correct but prosaic, repeating "fall" clumsily and ending on an unrelated tangent about pumpkin spice. A human evaluator would clearly prefer the first response, and a well-trained reward model should assign it a higher score.
Assume our reference model assigns:
- (log probability of generating the preferred response)
- (log probability of generating the dispreferred response)
The reference model assigns higher probability to the dispreferred response because it's simpler and uses more common words. The word "fall" is far more common in training data than "crimson" or "descend," and the dispreferred response is shorter and uses everyday vocabulary throughout. This is exactly the distribution shift DPO is designed to fix: the reference model, trained to predict natural text, has no built-in preference for poetic quality over simplicity.
Now suppose our current policy assigns:
With , the implicit rewards are:
The difference is:
The loss contribution from this example:
The model is doing okay on this example (probability of correct preference is about 60%), but there's room to improve. The gradient will push the model to further increase relative to the reference and decrease relative to the reference.
Let's also trace through what a "good" and a "bad" model state look like for this same example. Suppose after more training the policy reaches:
- (probability has increased from reference)
- (probability has decreased from reference)
Now the implicit rewards are:
The reward margin is now , and the preference probability is . The loss drops to . The model has learned to "see" the quality difference between these two responses, even though it never directly observed a reward signal during this training phase.


