Introduction
Welcome back. In our last lesson, we unpacked the full complexity of the Proximal Policy Optimization (PPO) pipeline for Reinforcement Learning from Human Feedback (RLHF). We identified the four separate models required: the learning Actor and Critic, alongside the frozen Reward Model and Reference Model. This intricate, multi-model setup is not only computationally expensive but also notoriously difficult to train and stabilize.
This complexity motivates a crucial question: can we achieve the same alignment with human preferences without the overhead of training a separate reward model and using a full reinforcement learning loop?
This lesson introduces Direct Preference Optimization (DPO), an elegant and powerful technique that answers this question with a resounding "yes." Our learning outcome is to describe Direct Preference Optimization (DPO) and how it eliminates the need for a separate reward model.
By the end of this session, you will understand the mathematical insight that allows DPO to reframe the alignment problem from a complex RL task into a simple, stable, supervised learning objective.
The Problem with RLHF and the DPO Solution
The standard RLHF pipeline is a multi-stage process that can be cumbersome. Let's first watch a brief recap of the RLHF process and how DPO offers a more direct path.
Direct Preference Optimization (DPO) - How to fine-tune LLMs directly without reinforcement learning
This video from Serrano.Academy starts by recapping the RLHF process with its two learning models (policy and reward) and then introduces DPO as a more efficient single-model approach.
Please watch from 00:23 to 03:55. Focus on the distinction between the two-network RLHF approach and the single-network DPO approach.
As the video explains, the core issue with the standard RLHF approach is its complexity. You need to:
- Train a separate reward model on human preference data.
- Use this reward model in a complex RL loop (PPO) to train the policy, which itself requires managing an actor, a critic, and a reference model.
DPO simplifies this dramatically by merging these steps. It finds a way to optimize the language model policy directly on the preference data, eliminating the need to ever explicitly train a reward model.
Let's look at a visual comparison.

The Core Idea: Your Language Model is Secretly a Reward Model
The key insight of DPO is that the RLHF objective, which tries to maximize rewards while staying close to a reference model, has an exact analytical solution. This solution connects the optimal policy directly to the reward function. DPO cleverly inverts this relationship to express the reward function in terms of the policy.
This means we don't need a separate model to represent rewards; the policy model itself can implicitly contain the reward function. Let's walk through the mathematical journey that makes this possible.
Step 1: Modeling Preferences with Bradley-Terry
Both RLHF and DPO start with the same type of data: a dataset of human preferences, where for a given prompt x, one response y⁺ (the "winner") is preferred over another y⁻ (the "loser").
Humans are better at comparative judgments than assigning absolute scores. The Bradley-Terry model formalizes this by modeling the probability that y⁺ is preferred over y⁻ using the difference in their latent reward scores. This probability is typically expressed with a sigmoid (logistic) function, :
Here, is the unknown, latent reward score for a given response. In traditional RLHF, the goal is to train a separate reward model to predict .
For a deeper dive into how this model turns preference scores into probabilities, the following video provides an excellent explanation.
Direct Preference Optimization (DPO) - How to fine-tune LLMs directly without reinforcement learning
Understanding the Bradley-Terry model is the first step in the DPO derivation. This segment explains how it uses the sigmoid function to convert reward differences into a preference probability.
Watch from 06:29 to 11:32. This will clarify how we get from a pair of reward scores (e.g., 5 and 2) to a probability distribution over the preferences.
Step 2: The DPO "Trick" — An Implicit Reward Function
The goal of RLHF is to find a policy that maximizes the reward while not straying too far from the original reference policy . This is captured by the KL-penalized objective:
The authors of the DPO paper showed that this optimization problem has a closed-form solution for the optimal policy :
where is a normalization term (the partition function) that ensures the probabilities sum to 1.
This equation shows a direct link between the reward and the optimal policy . DPO's key insight is to rearrange this equation to define the reward function in terms of the policy:
This is our implicit reward function. It states that the reward is simply the scaled log-probability ratio between the optimal policy and the reference policy, plus a term that only depends on the prompt x.
Step 3: Deriving the DPO Loss Function
Now, we substitute this implicit reward function back into the Bradley-Terry model. When we compute the difference in rewards, , the prompt-dependent term conveniently cancels out!
This leaves us with a preference probability that depends only on the policy we are trying to learn (, which takes the place of ) and the frozen reference policy ():
Since our goal is to train to satisfy the human preferences in our dataset, we can use a simple maximum likelihood objective. This is equivalent to minimizing the negative log-likelihood of the "correct" preference choices, which gives us the final DPO loss:
This might look complex, but it's just a binary cross-entropy loss! We are training the policy with a simple supervised objective, completely side-stepping the need for an explicit reward model or RL.
For a detailed walkthrough of this derivation, from the RL objective to the final loss function, please study the following article and video.
This article from Deep (Learning) Focus provides a clear, step-by-step mathematical derivation of the DPO loss, starting from the RLHF objective.
Read the section 'Deriving the DPO Loss'. Follow the four key steps outlined: deriving the optimal policy, forming the implicit reward, plugging it into the Bradley-Terry model, and arriving at the training loss. This connects all the mathematical pieces we've discussed.
Direct Preference Optimization (DPO) explained: Bradley-Terry model, log probabilities, math
For a narrated walkthrough of the derivation, this video by Umar Jamil is excellent. It explains why the standard RL objective is hard to optimize directly and how DPO provides a computable analytical solution.
Watch from 21:27 to 38:59. This covers the RL objective, its non-differentiable nature, DPO's analytical solution, and the crucial step where the uncomputable Z(x) term cancels out.
What the DPO Loss is Actually Doing
The DPO loss function effectively trains the policy to do two things simultaneously:
- Increase the likelihood of chosen responses (
y⁺). - Decrease the likelihood of rejected responses (
y⁻).
This is done relative to the reference model, which prevents the policy from drifting too far and ensures it maintains its pretrained capabilities. The hyperparameter controls this trade-off: a higher focuses more on fitting the preferences, while a lower sticks more closely to the reference model.

Because DPO is a simple supervised loss, it is far more stable than PPO. It avoids the challenges of online sampling, value function estimation, and reward hacking that make RLHF notoriously difficult.
Conclusion
In this lesson, we explored Direct Preference Optimization (DPO) as a simpler, more stable, and more efficient alternative to PPO-based RLHF. We saw how a clever mathematical re-framing allows DPO to achieve the same alignment objective without needing to train a separate reward model or use reinforcement learning.
Key Takeaways:
- DPO optimizes a language model directly on a static dataset of human preferences .
- It uses an implicit reward function that is defined in terms of the policy being trained and a frozen reference policy.
- By substituting this implicit reward into the Bradley-Terry preference model, the complex RLHF objective is transformed into a simple binary cross-entropy-like loss.
- This approach eliminates the need for a separate reward model and the entire complex, unstable RL training loop, making alignment more accessible and efficient.
Preview of the Next Lesson:
DPO represents a significant shift towards simpler, supervised methods for alignment. However, it's not the only modern alternative to the full PPO pipeline. In our next lesson, we will investigate Group Relative Policy Optimization (GRPO). GRPO stays within the reinforcement learning framework but, like DPO, finds a way to simplify the process—in its case, by eliminating the need for a trained critic network. This will be especially relevant as we transition towards using these alignment techniques for control tasks like autonomous driving.