Learning from human preferences
10 min read
Comparing is easier than writing
Instruction tuningTraining a pre-trained model further on examples of requests and good answers, so that it follows instructions and replies as an assistant instead of only continuing text. needs a good answer for every example. For many requests, nobody can write the single best answer. People can still look at two answers and say which is better: clearer, more accurate, kinder or safer. Preference training uses those comparisons.
RLHF in three steps
RLHFReinforcement learning from human feedback. People compare pairs of answers, a reward model learns their preferences, and the LLM is trained to produce answers that the reward model scores highly. stands for reinforcement learning from human feedback. The InstructGPT paper from 2022 set out the recipe that many later models followed.
- Fine-tuneTrain the base model on requests with good answers.
- ComparePeople rank pairs of the model's answers, and a reward model learns to score answers the way they do.
- OptimiseTrain the LLM to write answers that the reward model scores highly.
The reward model
The reward model reads a request and an answer and gives back one number, the reward. It learns from the pairs that people compared. For each pair, the chance that the chosen answer wins is the sigmoid of the reward gap. The sigmoid function turns any number into a value between 0 and 1. Training lowers the negative logarithm of that chance.
import math
def preference_loss(reward_chosen, reward_rejected):
p_chosen = 1 / (1 + math.exp(-(reward_chosen - reward_rejected)))
return p_chosen, -math.log(p_chosen)
for chosen, rejected in [(2.0, 0.0), (0.5, 0.0), (0.0, 1.0)]:
p, loss = preference_loss(chosen, rejected)
print(f"chosen {chosen}, rejected {rejected}: P(chosen wins) = {p:.2f}, loss = {loss:.3f}")It prints:
chosen 2.0, rejected 0.0: P(chosen wins) = 0.88, loss = 0.127
chosen 0.5, rejected 0.0: P(chosen wins) = 0.62, loss = 0.474
chosen 0.0, rejected 1.0: P(chosen wins) = 0.27, loss = 1.313When the reward model already scores the chosen answer well above the rejected one, the loss is small. When it scores them the wrong way round, the loss is large, and training pushes the scores apart in the right direction.
The optimisation step
In the last step, the LLM writes answers, the reward model scores them, and a reinforcement learning method, often one called PPO, raises the chance of high-scoring answers. A penalty keeps the model close to the fine-tuned model from step 1. Without that penalty, the model drifts towards odd text that happens to score well.
DPO skips the reward model
Direct Preference Optimization, or DPO, was published by Rafailov and others in 2023. It trains the LLM on the preference pairs directly, with a loss that raises the chance of the chosen answer and lowers the chance of the rejected one. It needs no separate reward model and no reinforcement learning loop, so it is simpler and more stable to run. Many open models now use DPO or a method like it.
| RLHF with PPO | DPO | |
|---|---|---|
| Separate reward model | Yes | No |
| Training loop | The model writes answers and gets scored | Ordinary training on stored pairs |
| Effort to run | High, with many settings to tune | Lower, close to plain fine-tuning |
Feedback from rules instead of people
Collecting human comparisons is slow and costly. Anthropic's 2022 Constitutional AI paper, by Bai and others, used a model to compare answers instead, guided by a written list of principles. This approach is often called RLAIF, reinforcement learning from AI feedback.
What can go wrong
A model trained to win approval can learn the wrong lesson.
- Reward hacking. The model finds patterns that score well but are not better, such as longer answers when the reward model likes length.
- Sycophancy. The model agrees with the user even when the user is wrong. A 2023 Anthropic study by Sharma and others found this behaviour across several assistants trained with human feedback, and linked it to people's preference for answers that agree with them.
Teams reduce these problems with careful rating guidelines, varied raters and tests that look for each failure.
Why collect comparisons instead of written answers?
A team wants a model to give more helpful replies to open-ended questions.
Many qualities are easier to judge than to describe. Preference training learns from those judgements.
What does DPO leave out?
A team switches from RLHF with PPO to DPO.
DPO trains on the preference pairs directly with an ordinary loss, so it needs no reward model and no PPO loop.
What is this failure called?
A user states a wrong fact, and the assistant agrees with it to please the user.
Training on human approval can teach a model to agree with people. Studies have found this across several assistants.
Your reading position is saved
0 of 20 complete
Lesson complete
Learning from human preferences
Up next