The Big Question
Fine-tuning taught the model to imitate good examples. If the dataset contains a helpful burger answer, supervised fine-tuning makes that kind of answer more likely.
How do we train a language model when there is no single correct answer?
Many real prompts have multiple valid answers. One answer may be shorter, another more useful, another safer, another better formatted. Preference optimisation asks a new question: among possible answers, which one would people prefer?
Fine-tuning asks what a good answer looks like. Preference optimisation asks which answer is better. That contrast is the heart of this chapter.
Core Intuition
Imagine Jessie is training at a burger restaurant. At first, she watches good employees answer customers. That is supervised fine-tuning.
Later, her manager shows two possible replies and asks which one should be used:
Response A
Make a burger.
Response B
Make a cheeseburger. Shape the beef into a patty, cook it in a pan, melt the cheese on top, toast the bun, and add fried onion.
The manager chooses Response B. Jessie learns something more subtle than imitation: useful answers tend to be specific, constraint-aware, practical, safe, and neither too short nor too long.
Preference optimisation tries to teach that judgement. It is useful because comparison is often easier than creation. A person may struggle to write the perfect answer, but can still recognize which of two answers is better.
Interactive Demo
Preference pair
Reward model gap
Shift toward the winner
DPO compares how much the policy has moved toward chosen and rejected responses relative to a frozen reference model.
Preference optimisation learns from contrasts. The chosen answer and rejected answer together define the training signal.
Preference Data
A preference dataset usually contains triples:
Here is the prompt, is the preferred response, and is the rejected response.
{
"prompt": "I only have beef, buns, onion, and cheese. What can I make?",
"chosen": "Make a cheeseburger. Shape the beef into a patty, cook it in a pan, melt the cheese on top, toast the bun, and add fried onion.",
"rejected": "Make food with the ingredients."
}The label does not say the chosen response is the only possible correct answer. It says that, for this prompt, this response is better than that one.
Close comparisons are especially valuable. If the rejected answer is nonsense, the model learns little. If both answers are plausible but one is safer, clearer, or more constraint-aware, the model learns judgement.
Reward Models
One way to learn from preferences is to train a reward model. A reward model takes a prompt and response and outputs a scalar score:
A higher reward should mean the response is more likely to be preferred. For a preferred response and rejected response , we want:
Bradley-Terry Loss
A common differentiable model says the probability that humans prefer the winner is:
The difference matters because preferences are relative. The loss for one pair is:
If the reward model gives the winner score and the loser score , the gap is , , and the loss is small. If the scores are reversed, the loss is large.
The reward model does not need perfect absolute scores. It needs to rank preferred responses above rejected ones.
RLHF
RLHF stands for reinforcement learning from human feedback. The classic pipeline has three broad stages: pretrain a language model, fine-tune it on demonstrations, then use preference data to train a reward model and optimise the language model against that reward.
| 1 | Pretraining | Learn broad language ability from next-token prediction |
| 2 | Supervised fine-tuning | Learn what assistant-style answers look like |
| 3 | Generate candidates | Sample several responses to the same prompt |
| 4 | Collect preferences | Humans or AI judges rank responses |
| 5 | Optimise preferences | Update the model toward preferred responses |
| 6 | Evaluate behavior | Check helpfulness, honesty, harmlessness, and failure cases |
Let be the language model policy and be the reward model. A naive objective would be:
But optimizing only reward is dangerous. The model can exploit weaknesses in the reward model and drift away from useful behavior. So RLHF usually keeps the model close to a reference model, often the supervised fine-tuned model:
The reward term pulls toward preferred behavior. The reference penalty keeps the model from moving too far from a model we already trust. The coefficient controls that trade-off.
Reward Hacking
Reward hacking happens when the model gets high reward without satisfying the true goal. If a reward model overvalues confident wording, the assistant may become overconfident. If it overvalues long answers, the assistant may become bloated.
The measured objective is not always the real objective. This is why models need human evaluation after preference optimisation, not only reward-model scores.
Direct Preference Optimisation
DPO, or direct preference optimisation, learns from preference pairs without training a separate reward model and without running a full reinforcement learning loop.
It asks: can we directly update the language model so it assigns higher probability to preferred responses than rejected responses?
Let be the policy we are training and be the frozen reference model. For one preference pair, DPO defines:
The first ratio asks how much more the new model favors the winner compared with the reference. The second ratio asks how much more it favors the loser. The difference asks whether the policy shifted more toward the winner than toward the loser.
DPO folds reward learning and policy optimization into a supervised-style objective. It is simpler than classic RLHF, but it still depends heavily on high-quality preference data.
Constitutional AI And RLAIF
Human preference labels are expensive, and some tasks can expose labelers to harmful content. Constitutional AI uses a written set of principles, a constitution, to guide critique, revision, and AI-generated feedback.
A simple burger constitution
- Give practical cooking advice.
- Respect the user's constraints.
- Do not recommend unsafe food handling.
- Admit uncertainty when needed.
- Prefer concise answers unless the user asks for detail.
RLAIF means reinforcement learning from AI feedback. Another AI system compares or critiques responses according to principles or rubrics. This can scale feedback, but it does not remove the need for human judgement. Human judgement moves upstream into designing principles, audits, and evaluations.
What Preferences Can Teach
Preference optimisation can teach many qualities, but it only optimises what the feedback process rewards.
| Helpfulness | Satisfy the user's actual request with useful, specific information |
| Honesty | Avoid inventing facts and admit uncertainty when appropriate |
| Harmlessness | Avoid harmful assistance while still giving safe alternatives |
| Instruction-following | Respect format, constraints, tone, and scope |
| Style | Be clear, concise, calm, and appropriately detailed |
These goals can conflict. A request for harmful instructions may require refusing the harmful part while still offering safe alternatives. A bad safety model refuses too much. A good one balances helpfulness, harmlessness, and honesty.
How The Methods Differ
| Method | Data signal | Main idea |
|---|---|---|
| Supervised fine-tuning | Demonstrations | Imitate this good response |
| Reward-model RLHF | Preference rankings plus a learned reward model | Generate responses the reward model scores highly |
| DPO | Chosen/rejected response pairs | Make chosen responses more likely than rejected ones relative to a reference |
| Constitutional AI | Principles, critique, revision, and AI feedback | Improve behavior according to a written constitution |
Preference optimisation changes model behavior. Retrieval gives the model external information. If the problem is missing current facts, use retrieval. If the problem is poor judgement or constraint-following, use fine-tuning or preference optimisation.
Implementation Sketches
Reward Model
for batch in dataloader:
prompt = batch["prompt"]
chosen = batch["chosen"]
rejected = batch["rejected"]
reward_chosen = reward_model(prompt, chosen)
reward_rejected = reward_model(prompt, rejected)
difference = reward_chosen - reward_rejected
loss = -log_sigmoid(difference)
loss.backward()
optimizer.step()
optimizer.zero_grad()DPO
for batch in dataloader:
prompt = batch["prompt"]
chosen = batch["chosen"]
rejected = batch["rejected"]
chosen_logp = policy.log_prob(prompt, chosen)
rejected_logp = policy.log_prob(prompt, rejected)
with torch.no_grad():
chosen_ref_logp = reference.log_prob(prompt, chosen)
rejected_ref_logp = reference.log_prob(prompt, rejected)
chosen_shift = chosen_logp - chosen_ref_logp
rejected_shift = rejected_logp - rejected_ref_logp
z = beta * (chosen_shift - rejected_shift)
loss = -log_sigmoid(z)
loss.backward()
optimizer.step()
optimizer.zero_grad()The policy model is trained. The reference model stays frozen. The objective rewards the policy for shifting probability toward the chosen response more than toward the rejected response.
Interview Discussion
Why is supervised fine-tuning not enough?
Many prompts have multiple valid answers. Preference optimisation teaches the model which answers are better according to comparisons.
What does a reward model learn?
It learns to score prompt-response pairs so preferred responses receive higher reward than rejected responses.
Why does RLHF use a reference model or KL penalty?
To prevent the policy from drifting too far from a trusted model or exploiting reward-model weaknesses.
How does DPO differ from RLHF?
DPO directly trains the language model on preference pairs, avoiding a separate reward model and reinforcement learning loop.
What makes a good preference pair?
Both responses are plausible, but one is meaningfully better on usefulness, safety, honesty, format, or constraint-following.
Active Recall
1. What problem does preference optimisation solve?
2. What do x, y_w, and y_l represent?
3. Why does the reward loss use a difference of rewards?
4. What is reward hacking?
5. What does the KL or reference penalty protect?
6. What does DPO remove from the classic RLHF pipeline?
7. Why does DPO still need a reference model?
8. Why does preference optimisation not guarantee truth?
Common Mistakes
- Thinking preference optimisation finds truth. It optimises behavior preferred by the feedback process.
- Thinking the reward model is the assistant. The reward model judges responses; the language model generates them.
- Ignoring the reference model. Without a reference constraint, optimisation can drift into strange behavior.
- Treating DPO as magic. DPO simplifies the method, but data quality still decides what the model learns.
- Confusing harmlessness with refusal. A good model refuses harmful help while still offering useful safe alternatives.
Connection To Inference And Decoding
We have now trained the model in stages. Pretraining gave broad language ability. Fine-tuning taught assistant behavior. Preference optimisation taught the model to prefer better answers over worse ones.
But training is over. The weights are fixed. When a user asks a new question, the model must generate an answer one token at a time. Inference and decoding decide how that probability distribution becomes actual text.