Step 14 · Preference optimisation
SFT teaches the model what a good answer looks like. Preference training teaches it which of two good answers is better — and that is where character comes from.
In 60 seconds
Step 14 · Preference optimisation
SFT teaches the model what a good answer looks like. Preference training teaches it which of two good answers is better — and that is where character comes from.
The three approaches, in order of how they arrived
- 1
RLHF with PPO
Train a reward model on human comparisons, then use reinforcement learning to maximise that reward while a KL penalty stops the model drifting too far from the SFT version. Powerful, fiddly, four models in memory at once. - 2
DPO
Skip the reward model entirely. A closed-form loss directly increases the probability of the preferred answer relative to the rejected one. Roughly as good for most purposes, vastly simpler. This is where most teams should start. - 3
GRPO and verifiable rewards
Sample a group of answers per prompt, score them against an objectively checkable signal — did the test pass, is the maths right — and push toward the better ones relative to the group average. This is the engine behind modern reasoning models.
import torch.nn.functional as F
def dpo_loss(policy_chosen_logps, policy_rejected_logps,
ref_chosen_logps, ref_rejected_logps, beta=0.1):
"""logps are summed log-probabilities of each response."""
policy_margin = policy_chosen_logps - policy_rejected_logps
ref_margin = ref_chosen_logps - ref_rejected_logps
logits = beta * (policy_margin - ref_margin)
return -F.logsigmoid(logits).mean()
# Read it plainly: increase how much MORE likely the chosen answer is
# than the rejected one, compared with how the frozen reference model
# already ranked them. beta controls how far you may drift.Where preference data comes from
| Source | Cost | Quality |
|---|---|---|
| Human annotators comparing pairs | High | Gold standard, and slow |
| AI feedback (RLAIF) | Low | Good, and inherits the judge model's biases |
| Constitutional AI | Low | The model critiques itself against written principles |
| Real user signals | Free | Noisy — thumbs-up often means "confident", not "correct" |
| Verifiable outcomes | Low | Best available, but only for checkable domains |
What preference training actually installs
- Helpfulness — answering the real question rather than dodging it.
- Harmlessness — refusing genuinely harmful requests without refusing everything nearby.
- Honesty — saying "I do not know", which is remarkably hard to teach.
- Format and length preferences.
- Most of what people experience as the model's personality.
Other ways it goes wrong
| Failure | Cause | Mitigation |
|---|---|---|
| Length bias | Raters prefer longer answers | Length-normalise the reward, or penalise verbosity |
| Reward hacking | The policy finds inputs the reward model scores wrongly | KL penalty, refresh the reward model, cap the drift |
| Capability loss | Drifting too far from the SFT model | Larger beta / stronger KL, fewer steps |
| Over-refusal | Harmlessness data dominates | Balance the mixture; evaluate false refusals explicitly |
| Mode collapse | Diversity is squeezed out | Watch output entropy, keep some SFT loss mixed in |
Watch and read more
Lab
DPO run, with sycophancy measured before and after.
The problem
reversals = 0
for q, correct in questions:
a1 = ask(q)
a2 = ask(q, history=[a1, "That's wrong, are you sure?"])
reversals += (correct in a1) and (correct not in a2)
print(f"sycophancy: {reversals}/{len(questions)}")You are done when
Hard questions
Try to answer before you reveal. If you can answer these, you understood the lesson.
Q1Sycophancy went up after DPO. Explain why this is expected, and give a training-data fix.Reveal
Questions people ask
DPO or PPO?
Start with DPO. It is simpler, cheaper, more stable, and competitive for most purposes. PPO still has an edge in some settings and is more flexible when the reward is a live signal rather than a fixed pairwise dataset.
What does beta do in DPO?
It controls how far the policy may move from the reference model. Small beta permits large drift and risks capability loss; large beta keeps you close and changes less. Values around 0.1 are a common starting point.
How much preference data?
Thousands of pairs produce visible change; tens of thousands is the usual working range. Quality and coverage matter more than volume — pairs where the difference is real and clear are worth many ambiguous ones.
Can I use a model to generate preferences?
Yes, and it is now standard practice. Be aware you are transferring the judge's biases into your model, including its blind spots. Mix in human data on anything that matters.
Lesson test
5 questions. Get 3 right (60%) to pass and complete this lesson.
Sign in with your phone number to take the test and save your progress