Chapter 10 · Part 3: Learning policies
Preferences, reward models, and the KL-regularised policy
RLHF read as statistics, with a Bradley-Terry reward model fitted by logistic regression, a KL-regularised optimum read as a Bayesian posterior, DPO as maximum likelihood, and over-optimisation as overfitting.
Chapter 8 assumed the reward was given. For many tasks, among them most of what we want a language model to do, nobody can write the reward down, but people can say which of two outputs they prefer. This chapter takes that setting as a statistics problem: estimate a reward from comparisons, then use it to improve a policy without letting the policy exploit the estimate's errors.
What is the setting?
For readers who have not met RLHF (reinforcement learning from human feedback), here is the vocabulary. A language model is a policy : given a prompt , it produces a response (a sequence of tokens) by sampling. The "action" is the whole response, so the problem is a one-step decision problem with an enormous action set. We drop from the notation and write . A reference policy is the model before the procedure starts, typically one already fine-tuned on demonstrations.
The pipeline of Christiano et al. (2017) for control tasks and of Ouyang et al. (2022) (InstructGPT) for language is:
- Collect pairs of responses and a human label saying which is better.
- Fit a reward model to those labels.
- Optimise the policy to maximise reward, with a penalty that keeps it close to .
Steps 2 and 3 are the two halves of this chapter.
How is a reward fitted from comparisons?
Humans give an ordinal answer, not a number. The Bradley–Terry model (Bradley and Terry, 1952) says each response has a latent score and the probability that is preferred to is
Given independent comparisons with winner listed first, the log-likelihood is
Two statistical points matter.
Identifiability. Every row sums to zero, so adding a constant to every leaves every probability unchanged. Rewards are identified only up to a constant, and the Hessian is singular along the all-ones vector. Only differences are estimable, which is also why only differences matter downstream: a constant shift cancels in the KL-regularised optimum below. We fix the constant by centring.
Existence. If the comparison graph is disconnected, scores in different components are not comparable. If one item wins every comparison it appears in, the likelihood increases without bound in its score: complete separation, exactly as in logistic regression. With few comparisons per item this is common, so practical fits add a penalty, which is a Gaussian prior on the rewards (MAP estimation). Our code uses a ridge penalty .
A worked example by hand
Three items and five observed comparisons, winner first: , , , , . Take the candidate reward . The Bradley–Terry probabilities are
So , , and . The likelihood of the data is
For comparison, the model with all rewards equal assigns every comparison probability and gives . The likelihood ratio is about in favour of the candidate. (It is a candidate, not the MLE: the MLE would raise the score of item 3, which has won both of its comparisons, as far as the prior or penalty allows. That is complete separation for item 3 at work.)
What is the KL-regularised policy objective?
Given a reward (estimated or known), the naive goal is . Its solution is a point mass on the best response. If is estimated, that is precisely the response about which the estimate is least trustworthy. The standard fix penalises distance from :
with . This is the objective used in InstructGPT, with the penalty applied per token.
Claim. The unique maximiser is
and the maximum value is .
Derivation (Gibbs variational principle). From the definition of , , which rearranges to
Substitute into :
with equality only at (Gibbs' inequality), so is maximised uniquely at with value .
Two consequences. Adding a constant to multiplies numerator and by the same factor, so is unchanged: consistent with rewards being identified only up to a constant. And is a temperature: as , ; as , concentrates on (within the support of ).
Worked example, continued
Take the reward estimate from above and . For , , so the unnormalised weights are , with and
For , , the weights are , and
The smaller temperature moves more mass onto the high-reward item, at a price in KL: is for and for . The objective values are and , which one can confirm equal : for , .
The Bayesian reading
has the form prior times likelihood. Treat as a prior over responses and as the likelihood of an "observation" that the response is good. Then is the posterior. Korbak, Perez and Buckley (2022) argue exactly this: the KL-regularised objective is variational inference towards that posterior, since the derivation above shows , so maximising minimises the reverse KL to .
What is DPO?
The two-stage pipeline fits by maximum likelihood, then optimises a policy against it by RL, with samples, a value baseline and so on. Direct preference optimisation (Rafailov et al., 2023) observes that the optimum above can be inverted. For any reward , the policy that is optimal for it satisfies
Substitute this into the Bradley–Terry probability. The term does not depend on and cancels in the difference:
The preference probability is now a function of the policy itself. Maximum likelihood on the observed comparisons over is minimisation of the DPO loss
Its gradient is , where is the argument of the sigmoid: log-likelihood of the winner goes up, of the loser down, weighted by how badly the current implicit reward mis-ranks the pair.
DPO skips the sampling-based RL step, but it does not escape the statistical problem: it uses a fixed batch of comparisons, and its implicit reward is as noisy as an explicit one. If the loss is driven far enough, it too finds policies that exploit the particular sample.
Why does pushing harder make things worse?
Let , where is the reward model's estimation error. The policy places most mass where is high, so
and the policy is selected to make this positive: it prefers responses where the error happens to be large and positive. As the policy tends to the maximiser of , and .
Gao, Schulman and Hilton (2023) measured this with a fixed "gold" reward model standing in for humans and proxy reward models trained on its labels. They found that, as the policy moves away from the initial one (measured by KL), the gold reward first rises, then peaks and falls while the proxy keeps rising, and that the relationship depends on reward-model size and data in smooth, fitted functional forms. Our toy below reproduces the widening gap; it only partly reproduces the peak.
What is GRPO's group-normalised advantage?
Chapter 8 showed that subtracting a baseline from the return reduces the variance of a policy-gradient estimate without bias. PPO-style RLHF learns a value function as the baseline, which is costly for large models. Group relative policy optimisation (Shao et al., 2024, introduced in DeepSeekMath) removes it. For each prompt it samples a group of responses from the current policy, scores them with rewards and uses the advantage
for every token of response , inside a clipped, PPO-like objective together with a KL penalty towards added directly to the loss.
Experiment
The companion file ch10_preferences.py runs the whole experiment in about ten seconds. The response space has items with true rewards drawn from and centred, and a reference policy that is a softmax of random logits. Comparisons are between two uniformly chosen distinct items, with outcomes drawn from the Bradley–Terry model. The reward is fitted by Newton's method with ridge penalty . Part 1 reports error against the number of comparisons ; part 2 builds from the estimated reward and reports, averaged over 200 repetitions, its KL from , its expected proxy reward and its expected true reward , along with the gap between them and the fraction of repetitions in which the true reward is lower than at . Part 3 fits DPO by gradient descent on the policy logits starting from , with 400 steps and no explicit penalty, on the same comparisons.
1. Bradley-Terry fit: estimation error vs number of comparisons (100 repetitions)
n RMSE corr(r,rhat) argmax correct
20 1.223 0.456 0.13
50 1.220 0.591 0.22
100 0.830 0.756 0.35
200 0.543 0.865 0.40
500 0.323 0.939 0.60
2000 0.162 0.984 0.76
(true reward sd across items: 0.851; best item has reward 1.487)
2. KL-regularised policy under the estimated reward (mean over 200 repetitions)
true reward of the best item: 1.487; of the reference policy: 0.055
n = 50 comparisons
beta KL proxy true gap P(<beta=1)
inf 0.000 0.077 0.055 0.022 0.99
3.00 0.120 0.809 0.274 0.535 0.97
1.00 0.806 1.889 0.578 1.311 0.00
0.30 2.319 2.791 0.822 1.969 0.23
0.10 2.847 2.897 0.861 2.036 0.26
0.03 3.029 2.909 0.871 2.039 0.27
0.01 3.081 2.910 0.876 2.034 0.27
n = 500 comparisons
beta KL proxy true gap P(<beta=1)
inf 0.000 0.057 0.055 0.003 1.00
3.00 0.043 0.319 0.270 0.049 1.00
1.00 0.330 0.759 0.625 0.134 0.00
0.30 1.648 1.463 1.166 0.297 0.00
0.10 2.719 1.672 1.321 0.350 0.00
0.03 3.147 1.699 1.353 0.346 0.01
0.01 3.278 1.702 1.360 0.342 0.01
3. DPO vs two-stage (BT fit, then tilt), same preferences, n = 200, 100 repetitions
beta | two-stage KL / true | DPO KL / true | mean TV
1.00 | 0.425 0.623 | 0.545 0.663 | 0.038
0.30 | 1.904 1.087 | 1.999 1.099 | 0.029
0.10 | 2.785 1.196 | 2.809 1.196 | 0.016Reading part 1. The error falls as the data grow, and from to it halves (0.323 to 0.162) as the rate predicts. At the estimate is worse than useless: an RMSE of 1.22 exceeds the standard deviation of the true rewards (0.851), so predicting that all items are equal would do better. With 20 items and 20 to 50 comparisons, each item appears about two to five times, which is the regime of large MLE variance. Even at 2,000 comparisons the true best item is the estimated best in only 76% of runs, because the estimate still carries error comparable to the gaps between the top few items.
Reading part 2. With comparisons, pushing from down to raises the proxy reward from to , while the true reward rises only from to , and the gap between them grows from to about . The proxy tells you the policy is far better than it is, by a factor of more than three. The true reward saturates from about (0.822, then 0.861, 0.871, 0.876) while the KL cost keeps growing (2.3 to 3.1 nats). The last column shows the pathology at the level of a single experiment: in about a quarter of the repetitions at a smaller gives a lower true reward than does. With the same picture is milder: the gap is and the true reward is almost never lower than at .
This does not reproduce a decline in mean true reward, which Gao et al. observe with real reward models. In our toy the errors are the benign ones of a correctly specified model fitted to independent labels. Real reward models are misspecified, and their errors are correlated with features that optimisation can find. What the toy does show is the mechanism, selection on noise, and its two dependencies: the gap shrinks with more preference data and grows as .
Reading part 3. The two-stage policy and the DPO policy are close: the total variation distance between them is at and at , and both achieve nearly the same true reward ( against at ; for both at ). DPO's KL from the reference is slightly higher at each . That is what the regularisation story predicts: the ridge penalty in the two-stage fit shrinks the rewards a little, while DPO's early stopping shrinks them differently. Neither is "right"; they are two ways of choosing how much to trust the data. Because the policy here is a free table, the likelihoods coincide, which is why the agreement is so close; with a parametric policy class they need not.
Exercises
- (Pen and paper.) Using the worked example, compute the log-likelihood gradient with respect to at . Is the likelihood increased by raising ? What does this say about the MLE for these data?
- (Pen and paper.) Show that, for fixed , as (assume has full support) and as .
- (Pen and paper.) For two responses with a single comparison and no penalty, show the Bradley–Terry likelihood has no maximiser, and say which penalty (a ridge on the scores) gives a finite one. What is the maximiser of in the score difference when is centred, for ? (Hint: set the derivative to zero and solve numerically; is between and .)
- (Change the code.) Set
LAM = 0.01and predict how part 1 changes at and at . Run it. - (Change the code.) In
experiment_overopt, use and look at the last column. Predict whether the fraction of repetitions where a small is worse than is above or below the and values, then check.
Sources
- Bradley, R. A., Terry, M. E. (1952). Rank Analysis of Incomplete Block Designs: I. The Method of Paired Comparisons. Biometrika 39(3/4).
- Christiano, P., Leike, J., Brown, T. B., Martic, M., Legg, S., Amodei, D. (2017). Deep Reinforcement Learning from Human Preferences. NeurIPS 2017.
- Ouyang, L., Wu, J., Jiang, X., et al. (2022). Training Language Models to Follow Instructions with Human Feedback. NeurIPS 2022.
- Korbak, T., Perez, E., Buckley, C. L. (2022). RL with KL Penalties is Better Viewed as Bayesian Inference. Findings of EMNLP 2022.
- Rafailov, R., Sharma, A., Mitchell, E., Ermon, S., Manning, C. D., Finn, C. (2023). Direct Preference Optimization: Your Language Model is Secretly a Reward Model. NeurIPS 2023.
- Gao, L., Schulman, J., Hilton, J. (2023). Scaling Laws for Reward Model Overoptimization. ICML 2023.
- Shao, Z., Wang, P., Zhu, Q., et al. (2024). DeepSeekMath: Pushing the Limits of Mathematical Reasoning in Open Language Models.