Learning from preferences
hard 6 minPreference learning trains a system to favor one response over another for the same prompt.
Video lesson · Chapter 1 of 4
The eloquent wrong answer
Theory
Read or listen first. About 2 min.
What it is
Preference learning trains a system to favor one response over another for the same prompt. Human feedback, AI critiques and a reference policy can be used in different combinations. The learned signal captures what the feedback process rewards, including accidental preferences.
Why it exists
An evaluator that consistently rewards verbosity can produce a model that sounds more helpful without solving more tasks. Hold out human judgments, vary presentation order and audit cases where a higher preference score conflicts with factual correctness.
A judge prefers long answers to correct answers
Inside this chapter
Chapter sources- RLHF
- In a common RLHF pipeline, people compare candidate responses, a reward model learns those preferences, and policy optimization favors higher-scoring outputs subject to constraints. The learned reward is a proxy. If verbosity correlates with preference labels, optimizing it can reward long answers that add little information.
The reward model only sees what labellers rewarded, so it absorbs their incidental tastes as well as their real ones. Policy optimisation then pushes hard on whatever the reward model scores highly, which is how a slight preference for longer answers turns into padded, repetitive answers. A penalty for drifting from the reference model slows this down but does not remove it. You notice it when reward keeps rising while blinded human ratings flatten or fall.
Example. If a reward model prefers longer responses to the same factual answer, test length-matched pairs before increasing optimization pressure.
Another example. A coding assistant's reward model gives higher scores to answers with more comments. After optimisation, answers grow by an illustrative 40% while test pass rates stay flat: the extra length was rewarded, not the correctness.
The classic RLHF loop - 1Sample two answerssame prompt, current policy
- 2People pick the betterpairwise preference label
- 3Fit reward modelscores answers like the labellers
- 4Optimise the policyraise reward, stay near reference
- 5Audit for shortcutslength-matched and blinded checks
Repeat: back to Sample two answersThe reward model is a learned proxy. Stronger optimisation finds its blind spots faster.
- DPO (Direct Preference Optimization)
- Direct preference optimization trains on chosen and rejected completions relative to a reference policy. It avoids a separate online reinforcement-learning loop in the usual formulation. The quality of the preference pairs still matters. Evaluate whether the trained policy improves the preference you actually intended.
DPO shows that the RLHF objective with a reference penalty can be rewritten so the policy itself acts as the reward model. Each step looks at one chosen and one rejected answer and nudges the policy to raise the chosen answer's probability relative to the reference more than the rejected one's. Beta controls how strongly it may move away from the reference. There is no sampling loop during training, which makes it simpler and more stable, but it inherits every bias in the preference pairs.
Example. For one preference pair, hold the reference fixed and increase the chosen response’s relative log probability. Check that the pairwise DPO loss decreases.
Another example. For a support bot, pairs where the chosen answer cites the refund policy and the rejected one invents a deadline teach groundedness. If most chosen answers are also shorter, check that the model learned groundedness and not brevity.
DPO loss for one pair as the margin grows
beta x margin sigmoid Pair loss Reading 0 0.500 0.693 (ln 2) policy no better than reference 1 0.731 0.313 chosen answer gaining relative odds 2 0.881 0.127 clear preference learned -1 0.269 1.313 rejected answer favoured, large loss Margin = s(chosen) minus s(rejected), where s is the log ratio of policy to reference probability. - Constitutional AI
- Constitutional AI uses written principles to guide critique and revision and can use AI-generated preference feedback during training. Make principles concrete enough to distinguish two candidate responses. Test cases where principles compete, and examine whether applying them preserves useful task performance.
Instead of people labelling every comparison, a model is asked to critique and revise answers against a written list of principles, and later to choose between candidate answers using those principles. The principles become the specification, so their wording matters: a principle that cannot decide between two concrete answers adds noise. Test cases where principles pull in opposite directions, such as privacy against helpfulness, to see whether the trained model finds the helpful safe answer or simply refuses.
Example. Apply principles about privacy and helpfulness to a request for another customer’s address. Evaluate whether the response protects privacy while offering a permitted alternative.
Principles turned into training signal - 1Draft a responserequest for a customer's address
- 2Critique vs principleprivacy: does it expose a person?
- 3Revise the draftdecline, offer a permitted route
- 4AI preference labelsmodel compares candidate pairs
- 5Train on the labelssupervised and preference stages
Concrete principles produce consistent critiques; vague ones produce arbitrary labels.
- Red Teaming & Adversarial Testing
- Adversarial evaluation probes the limits of a system with controlled, authorized test cases. Define failure criteria and protected resources, use inert fixtures, and track both missed risks and unnecessary refusals. A passed test suite measures behavior on those cases; it cannot establish universal safety.
A red-team suite is a set of authorised probes with written pass and fail rules, run against fixtures that cannot cause real harm. Track two numbers: risks that got through and legitimate requests that were refused, because tightening a model usually trades one for the other. Keep the suite versioned and add every real incident to it. A clean run says the model behaved on these cases, not that it is safe in general.
Example. Use an inert record marked private and a permitted public record. A useful release must preserve the former and still retrieve the latter.
Another example. An HR assistant suite holds 60 probes asking for a fixture employee's salary and 60 ordinary policy questions. An illustrative release blocks all 60 probes but also refuses 9 policy questions, so it is not ready.
Score both failure directions
A release that blocks everything passes the first check and fails the second. - KL regularisation to a reference policy
- Preference optimisation usually maximises reward minus a penalty for moving away from a frozen reference model. The penalty keeps the policy fluent and limits how far it can chase flaws in the reward signal.
The reference is typically the SFT model the preference stage started from. Every token the policy makes much more likely than the reference costs reward, so improvements must be worth the drift. When the KL value climbs steeply during training while human ratings stall, the policy is probably exploiting the reward model.
Example. With a small beta the policy drifts far and starts producing odd, reward-pleasing text; with a large beta it barely changes. Sweep beta and watch both reward and held-out human ratings.
Reward with a leash
r is the learned reward and beta sets the strength of the penalty. DPO optimises this same objective without sampling.
How it works
Step through the idea, or press Play.
Response pairs. Chosen: precise · rejected: verbose error
Understand it
Worked example
A judge prefers long answers to correct answers
- 1
Chosen: precise · rejected: verbose error
Keep pairs for the same prompt. Inspect the labels for shortcuts such as length, style or source order.
- 2
Chosen odds rise vs reference
DPO uses the relative preference of the policy and reference. RLHF can instead fit a reward model and then optimize a policy under constraints.
- 3
Order and length controlled
Repeat evaluation with shuffled order and length-matched outputs. A preference gain that disappears may reflect a shortcut rather than improved correctness.
Relative preference for a chosen response
Follow the handoffs
A gain that disappears under controls
| Evaluation setup | New policy win rate | What it suggests |
|---|---|---|
| Original order, raw lengths | 70% | looks like a clear win |
| Order swapped | 52% | the judge favours a position |
| Length-matched pairs | 49% | the remaining gain was length |
| Blinded human labels, length-matched | 50% | no real improvement |
Summary
The whole topic in one minute.
An independent evaluation changes the source of evidence and controls the confounder that may explain the improvement.
An evaluator that consistently rewards verbosity can produce a model that sounds more helpful without solving more tasks. Hold out human judgments, vary presentation order and audit cases where a higher preference score conflicts with factual correctness.