TL;DR
Reinforcement learning from human feedback (RLHF) teaches a model to do what people prefer when they cannot write down a score for "good". People compare pairs of model outputs and say which one they like better. A separate network, the reward model, learns to predict those choices. Then the language model is tuned with reinforcement learning to earn high reward from that network, with a penalty that stops it drifting too far from where it started.
Where you'll see it: the final tuning stage of chat assistants such as InstructGPT and its successors, where it turns a model that only predicts text into one that follows instructions politely and helpfully.
Intuition
Why a score is hard to write down
Suppose you want a model to write a good summary of an article. You can measure whether it contains the right facts, but "good" also means concise, readable, polite, and honest about uncertainty. Writing a formula for that is hopeless. Asking a person to rate each answer from 1 to 10 is also unreliable, because two raters use the scale differently.
Comparing two answers is much easier. "Which of these two summaries is better?" is a question people answer quickly and consistently. RLHF is built on that observation. It turns many small comparisons into one number that a learning algorithm can push upward.
Three stages
The recipe has three stages. A pretrained Language Model is the starting point. A reward model is trained on comparisons. Then the language model is improved against that reward model.
flowchart LR A[Pretrained language model] --> B[Supervised fine-tuning on demonstrations] B --> C[Human rankings of pairs of outputs] C --> D[Reward model] B --> E[Policy: the tuned model] D -- reward --> E E -- sampled answers --> C
The first stage is ordinary Fine-Tuning on examples written by people. It gives a sensible starting policy. The second stage fits the reward model. The third stage runs reinforcement learning, so the model's own answers are scored and the model is nudged toward the high-scoring ones.
The reward model is a judge, not a teacher
The reward model never sees the right answer. It only learns which of two answers a person would pick. That is why it can be trained on a modest number of comparisons and then used to score millions of new answers during reinforcement learning. Its output is a scalar, and only differences between scalars matter.
The math
Setting
Let be a prompt and a response of tokens. The language model defines a policy , the probability that the model with parameters writes given . Call the model before reinforcement learning . Its job is to remember what sensible text looks like.
Stage 2: fitting the reward model
For each prompt, a labeller sees two responses (the preferred one) and (the rejected one). The model of human choice is the Bradley–Terry model, which says the probability that wins depends on how far apart the two scores are:
Here is the reward model with parameters , and is the logistic sigmoid. Training maximises the likelihood of the observed labels, which is the same as minimising the negative log-likelihood averaged over the comparison dataset :
This is a maximum likelihood problem with a cross-entropy-style loss. The reward is only identified up to a constant, because adding the same number to both scores changes nothing.
Stage 3: the RL objective with a KL penalty
Once is fixed, the language model is trained to maximise expected reward while staying close to the reference model:
The second term is the KL divergence between the tuned and reference models, and sets its strength. Without it, the policy can find strange text that the reward model happens to score highly. With it, the policy is paid to stay in the region where the reward model was trained.
In practice the expectation is estimated from sampled responses. For one sampled response, the per-sequence reward used by the RL algorithm is
The log ratio is a one-sample estimate of the KL term. Its value is positive when the tuned model has become more confident in than the reference model was.
Stage 3 continued: the optimiser
The reward is treated as the return of a single-step episode, and the policy is improved with a Policy Gradient method. The InstructGPT paper and most later systems use PPO, which limits how far one update can move the policy so that training stays stable. The Advantage Function is usually estimated with a learned value head, but the core idea is the same as any policy gradient: raise the probability of responses whose reward beat expectations, and lower it for responses that did worse.
Worked examples
Let the reward model give the preferred answer and the rejected answer .
- Difference: .
- Win probability: .
- Loss for this pair: .
Now suppose the reward model is wrong and scores them the other way, and .
- Difference: , so .
- Loss: .
Interpretation: the loss is small when the reward model already ranks the pair correctly and large when it does not. The gradient pushes the preferred score up and the rejected score down, with a size that shrinks as the margin grows.
Take a single response to a prompt. The reference model gives it probability . The current tuned model gives it . The reward model scores it . Use .
- Log ratio: .
- KL penalty: .
- Total reward used by RL: .
Now imagine the tuned model has drifted until , while the reward model still says .
- Log ratio: .
- Penalty: .
- Total reward: .
Interpretation: the reward model's opinion did not change, but the total reward fell. The KL term makes the tuned model pay for moving probability mass away from the reference. A larger would make that cost steeper.
The loss from the first example, as a function of the reward gap, is plotted below.
- loss for one pair
Tradeoffs and failure modes
RLHF is powerful, but each stage has a characteristic way to go wrong.
| Situation | Problem | Better choice |
|---|---|---|
| The reward model is weak or narrow | The policy finds outputs that score well but are bad, called reward hacking. | Retrain the reward model on samples from the current policy, and add a KL penalty. |
| is too small | The policy drifts far from the reference and loses fluency or diversity. | Raise or use an adaptive KL target. |
| is too large | The policy barely changes, so the tuning has little effect. | Lower and watch win rates against the reference. |
| Labellers prefer longer answers | The model learns to pad, a form of length bias. | Control for length in the data or add length-aware rewards. |
| Labellers disagree | The reward model learns the average of conflicting tastes. | Write clearer labelling guidelines and measure agreement between raters. |
| Comparisons are expensive | Coverage of the answer space is thin. | Use AI-written feedback or a smaller set of targeted comparisons. |
RLHF is also not free to run. It needs a supervised starting point, thousands to millions of human comparisons, and several copies of a large model in memory during the RL stage. Simpler alternatives such as direct preference optimisation skip the explicit reward model and optimise the preference loss directly. They are cheaper to run but rely on the same preference data.
History
Preference-based learning is older than language models. The Bradley–Terry model for paired comparisons dates from 1952. Its use in training deep networks from human choices was shown by Christiano and colleagues in 2017, who trained agents in simulated robot and Atari tasks from human comparisons of short video clips. Their work showed that a small amount of human feedback, far less than the number of environment steps the agent took, could be enough to teach behaviour that a hand-written reward would have been hard to specify.
In 2019, Ziegler and colleagues applied the same recipe to language models, tuning them for text continuation and summarisation. In 2020, Stiennon and colleagues trained a summarisation model this way and showed that human raters preferred its summaries to those from models trained only on reference summaries.
The method caught on with InstructGPT in 2022. Ouyang and colleagues fine-tuned GPT-3 on demonstrations, trained a reward model on rankings, and used PPO to optimise against it. Labellers preferred the resulting model's answers over those of the much larger base model, which made the approach central to later assistant models.
Check yourself
QuestionWhat does a single comparison in the reward model's training data contain?Show answer
A prompt , a preferred response and a rejected response . The reward model is trained so that is larger than . The label is the human's choice, not an absolute score for either response.
QuestionA reward model gives two answers scores of 3.0 and 1.0. Under the Bradley–Terry model, what is the probability that the first answer is preferred?Show answer
The difference is , so the probability is , about 88 percent. The model is confident, but not certain, that the first answer wins.
QuestionWhy does the objective include a KL penalty instead of only maximising the reward?Show answer
The reward model was trained on comparisons from the original model's outputs, so it is only reliable near those outputs. Without a penalty, the policy can move into regions where the reward model gives high scores for poor text. The KL term keeps the tuned model near the reference model, where the reward model's judgments are trustworthy. It also limits reward hacking.
QuestionA tuned model's response has reference probability 0.10 and tuned probability 0.40, with reward 0.8 and . What total reward does the RL algorithm see?Show answer
The log ratio is . The penalty is . The total reward is . The reward model alone would have said 0.8, but the penalty lowers the signal because the tuned model has become four times more likely to produce this response than the reference did.