Search

Search papers and lessons

Reward Model

Level 4 · 12 min read

A reward model is a network trained on human preference comparisons to give any response a single score, so reinforcement learning can optimise against human judgement.

On this page

  • Colour = topic mix
  • Probability
  • Calculus
  • Linear algebra
  • Neural network basics
  • Discrete math
  • Losses & regularization
  • Sign in to see your progress

TL;DR

A reward model is a neural network that reads a prompt and a response and outputs one number, a score for how good a human would judge that response to be. It is trained not on absolute scores but on pairs: people look at two responses to the same prompt and say which one they prefer. The network learns to give the preferred one the higher number.

Once trained, the reward model stands in for the human. A reinforcement learning algorithm can then generate millions of responses and be pushed toward the ones the model scores highly, which is how human judgement gets into a language model without a person grading every answer.

Where you'll see it: the second stage of RLHF, where a chat model is tuned to prefer answers that people rate as helpful and harmless.

Intuition

Learning taste from pairs

Asking a person to score an answer out of 10 is hard. Their scale drifts from one day to the next, and two people rarely agree on what a 7 means. Asking which of two answers is better is much easier and more consistent. A rater can say "this one" without knowing the scale at all.

A reward model turns those choices into a training signal. Each comparison says, in effect, "answer A beats answer B for this prompt". The network's only job is to make its scores agree with those choices. It never needs to know what a "7" is. Only the difference between two scores matters, and that is what the training signal pushes on.

The reason this is worth doing is that the thing we care about is hard to write down as a rule but easy to recognise when we see it. Helpfulness, tone and honesty are like that. A reward model is a learned, compressed copy of the judgement a group of raters applied to many examples, and it can be queried millions of times at almost no cost.

flowchart LR
  P[Prompt] --> A[Response A]
  P --> B[Response B]
  H[Human picks the better one] --> D[Training pair: winner and loser]
  A --> D
  B --> D
  D --> R[Reward model scores both]
  R --> L[Loss pushes winner score above loser score]

The plot below shows the training signal for one comparison. The horizontal axis is the score gap between the preferred and the rejected response. When the gap is large and positive, the model already agrees with the human and the loss is near zero. When the gap is negative, the model is ranking the pair the wrong way round and the loss grows roughly linearly with how wrong it is.

−4−2024012345score gap r(preferred) − r(rejected)value
  • loss
  • P(preferred wins)
The loss is small when the preferred answer scores higher by a clear margin. At a gap of 0 the model is guessing, with loss ln 2 ≈ 0.693.

The math

Setup

Let x\mathbf{x} be a prompt and y\mathbf{y} a response. The reward model is a function rϕ(x,y)∈Rr_\phi(\mathbf{x}, \mathbf{y}) \in \mathbb{R}, with parameters ϕ\phi. It returns a single real number. Higher means better according to the human raters it was trained on.

The training data is a set D\mathcal{D} of triples (x,yw,yl)(\mathbf{x}, \mathbf{y}_w, \mathbf{y}_l), where yw\mathbf{y}_w is the response the rater preferred (the winner) and yl\mathbf{y}_l is the one they rejected (the loser). The data says nothing about how much better the winner is, only that it was chosen.

The preference model

To turn a pair of scores into a probability, the standard choice is the Bradley–Terry model, first proposed for paired comparisons in sports and tournaments. It says that the probability a rater prefers yw\mathbf{y}_w over yl\mathbf{y}_l depends only on the difference of their scores:

Definition: Pairwise preference probability

Under the Bradley–Terry model, the probability that the rater prefers y1\mathbf{y}_1 to y2\mathbf{y}_2 given prompt x\mathbf{x} is

P(y1≻y2∣x)=σ(rϕ(x,y1)−rϕ(x,y2)),P(\mathbf{y}_1 \succ \mathbf{y}_2 \mid \mathbf{x}) = \sigma\big(r_\phi(\mathbf{x}, \mathbf{y}_1) - r_\phi(\mathbf{x}, \mathbf{y}_2)\big),

where σ\sigma is the sigmoid function σ(z)=1/(1+e−z)\sigma(z) = 1/(1 + e^{-z}).

Here ≻\succ reads "is preferred to", and ∣\mid reads "given". The quantity inside the sigmoid, Δ=rϕ(x,y1)−rϕ(x,y2)\Delta = r_\phi(\mathbf{x}, \mathbf{y}_1) - r_\phi(\mathbf{x}, \mathbf{y}_2), is the score gap. Because the sigmoid maps any real number into (0,1)(0, 1), the model always gives a valid probability, whatever the scores are.

An equivalent form makes the link to softmax clear. Since σ(a−b)=ea/(ea+eb)\sigma(a - b) = e^{a}/(e^{a} + e^{b}), the same probability is a two-way softmax over the two scores:

P(y1≻y2∣x)=erϕ(x,y1)erϕ(x,y1)+erϕ(x,y2).P(\mathbf{y}_1 \succ \mathbf{y}_2 \mid \mathbf{x}) = \frac{e^{r_\phi(\mathbf{x}, \mathbf{y}_1)}}{e^{r_\phi(\mathbf{x}, \mathbf{y}_1)} + e^{r_\phi(\mathbf{x}, \mathbf{y}_2)}}.

Maximum likelihood gives a loss

Assume the comparisons are independent. The likelihood of the whole dataset is the product over pairs of the probability the model assigns to each observed choice. Taking the logarithm turns the product into a sum, and maximum likelihood estimation means maximising that sum. Equivalently, we minimise the negative log-likelihood:

L(ϕ)=− E(x,yw,yl)∼D[log⁡σ(rϕ(x,yw)−rϕ(x,yl))].\mathcal{L}(\phi) = -\,\mathbb{E}_{(\mathbf{x}, \mathbf{y}_w, \mathbf{y}_l) \sim \mathcal{D}} \Big[ \log \sigma\big(r_\phi(\mathbf{x}, \mathbf{y}_w) - r_\phi(\mathbf{x}, \mathbf{y}_l)\big) \Big].

Here E\mathbb{E} is the average over the dataset, and log⁡\log is the natural logarithm. This is the whole training objective. It is a binary cross-entropy in disguise: each comparison is a binary label that says the first response won, and the model's predicted probability for that label is σ(Δ)\sigma(\Delta). With label 1 the binary cross-entropy −ln⁡p-\ln p reduces to −ln⁡σ(Δ)-\ln \sigma(\Delta).

Two facts that follow from the form

The loss depends only on differences. If we add the same constant cc to every score, Δ\Delta does not change, so the loss does not change. A reward model is therefore only defined up to an additive constant. Nothing in the training signal fixes the zero point, and the absolute number a reward model outputs has no meaning on its own. Only comparisons between responses mean something.

The gradient is bounded in a useful way. Write m=Δm = \Delta for the score gap of one pair. The derivative of the loss with respect to mm is

∂∂m(−ln⁡σ(m))=−(1−σ(m))=−σ(−m).\frac{\partial}{\partial m}\big(-\ln \sigma(m)\big) = -\big(1 - \sigma(m)\big) = -\sigma(-m).

When the model already ranks the pair correctly by a wide margin, σ(−m)\sigma(-m) is close to zero, so the pair contributes almost nothing. When the model ranks it wrongly, the push is close to full strength. The model therefore spends its effort on the comparisons it gets wrong.

Architecture

The reward model is almost always built from a pretrained language model. The usual recipe is to take a transformer trained to predict text, remove its output head that produces a distribution over tokens (the Softmax over the vocabulary), and attach a single linear layer that maps the final hidden state of the last token to one scalar. Writing h\mathbf{h} for that hidden state, the score is

rϕ(x,y)=w⊤h(x,y)+b.r_\phi(\mathbf{x}, \mathbf{y}) = \mathbf{w}^{\top} \mathbf{h}(\mathbf{x}, \mathbf{y}) + b.

Here w\mathbf{w} is a learned vector and bb a learned scalar. The earlier layers are initialised from the language model and fine-tuned on the comparison data, usually for a single pass over the data. The head is a plain feedforward layer with no activation, because the score is allowed to take any real value.

Worked examples

Example
One comparison, by hand

Take a prompt with two candidate responses. The reward model gives rϕ(y1)=2.0r_\phi(\mathbf{y}_1) = 2.0 and rϕ(y2)=0.5r_\phi(\mathbf{y}_2) = 0.5.

  1. Score gap: Δ=2.0−0.5=1.5\Delta = 2.0 - 0.5 = 1.5.
  2. Preference probability: P(y1≻y2)=σ(1.5)=1/(1+e−1.5)P(\mathbf{y}_1 \succ \mathbf{y}_2) = \sigma(1.5) = 1 / (1 + e^{-1.5}).
  3. Compute e−1.5≈0.2231e^{-1.5} \approx 0.2231, so the denominator is 1.22311.2231 and σ(1.5)≈0.8176\sigma(1.5) \approx 0.8176.
  4. Suppose the rater picked y1\mathbf{y}_1. The loss is −ln⁡(0.8176)≈0.2014-\ln(0.8176) \approx 0.2014.
  5. Suppose instead the rater picked y2\mathbf{y}_2. The probability of that choice is 1−0.8176=0.18241 - 0.8176 = 0.1824, and the loss is −ln⁡(0.1824)≈1.7014-\ln(0.1824) \approx 1.7014.

Interpretation: when the model already agrees with the rater, the loss is small (0.20). When it disagrees, the loss is about eight and a half times larger (1.7014/0.2014≈8.41.7014 / 0.2014 \approx 8.4). The model was fairly confident in y1\mathbf{y}_1, so the surprise of the rater choosing y2\mathbf{y}_2 is large. As a check, the two losses are ln⁡(1+e−1.5)\ln(1 + e^{-1.5}) and ln⁡(1+e1.5)\ln(1 + e^{1.5}), which match the values above.

Example
A small batch and the shift test

Three comparisons produce score gaps Δ=1.5\Delta = 1.5, Δ=−0.4\Delta = -0.4 and Δ=0.8\Delta = 0.8. Each term in the loss is ln⁡(1+e−Δ)\ln(1 + e^{-\Delta}).

  1. First pair: ln⁡(1+e−1.5)=ln⁡(1.2231)≈0.2014\ln(1 + e^{-1.5}) = \ln(1.2231) \approx 0.2014.
  2. Second pair: ln⁡(1+e0.4)=ln⁡(2.4918)≈0.9130\ln(1 + e^{0.4}) = \ln(2.4918) \approx 0.9130. The model ranked this pair the wrong way round, so the loss is high.
  3. Third pair: ln⁡(1+e−0.8)=ln⁡(1.4493)≈0.3711\ln(1 + e^{-0.8}) = \ln(1.4493) \approx 0.3711.
  4. Mean loss: (0.2014+0.9130+0.3711)/3≈0.4952(0.2014 + 0.9130 + 0.3711) / 3 \approx 0.4952.

Now add 10 to every score in all three pairs. The gaps are unchanged, so the mean loss is still 0.49520.4952. This is the shift invariance from the math section: the loss cannot tell an absolute score of 10 from an absolute score of 0, and training will not try to.

Interpretation: a mean loss near ln⁡2≈0.693\ln 2 \approx 0.693 means the model is no better than a coin flip on these pairs. Here it is better than that on average, but the wrong-way pair dominates the loss, which is exactly where the next round of training pushes hardest.

Example
Realistic scale: ranking several answers

Human raters often rank more than two answers at once. If a rater orders KK responses to one prompt, the ranking splits into (K2)\binom{K}{2} pairwise comparisons. In the InstructGPT work, labellers ranked between four and nine outputs per prompt, so one prompt yielded between 6 and 36 pairs from a single rating task. This is a cheap way to get many training pairs from one piece of human effort, and it is why the pairs in a batch share a prompt: the score gaps are only meaningful within one prompt.

Tradeoffs and failure modes

A reward model is a proxy. It is useful only as long as its scores track what the raters actually wanted, and the optimiser that uses it will look for every place they stop tracking.

SituationWhat goes wrongBetter choice
Policy is optimised hard against the reward modelReward hacking: the policy finds responses the model scores highly but humans dislike, such as long, confident or flattering textAdd a KL penalty to a reference model, stop early, or ensemble several reward models
Raters disagree or are inconsistentThe loss averages over contradictory labels, and the model learns a blurred notion of qualityMeasure inter-rater agreement, write clearer guidelines, and drop low-agreement pairs
Responses drift away from the training distributionScores on new kinds of answers are unreliable, and the policy exploits thatCollect fresh comparisons from the current policy and retrain the reward model
The task has a checkable answer, such as a unit test or a maths resultPreference labels are a noisy and expensive stand-in for the truthUse a programmatic reward or verifier, which cannot be flattered
Using reward scores as calibrated probabilitiesOnly differences are identified, so absolute values have no fixed meaningCompare scores within one prompt, and do not threshold them across prompts

The most important failure is reward overoptimisation. In the summarisation work of Stiennon et al., training against a learned reward model improved the score on that model well past the point where human judgements stopped improving. Gains on the proxy and gains for people came apart.

History

The idea of ranking things from pairwise comparisons is old. Ralph Bradley and Milton Terry set out the model in 1952, for paired comparisons such as taste tests. Its use for training a neural network to match human preferences came much later.

In 2017, Paul Christiano and co-authors at OpenAI and DeepMind trained a reward model from human comparisons of short video clips of simple robot and Atari behaviour, then used it as the reward for reinforcement learning. This showed that a learned reward could replace a hand-written one. In 2020, Nisan Stiennon and co-authors applied the same recipe to summarising text, and showed that the reward model could guide a language model toward summaries people preferred. In 2022, Long Ouyang and co-authors at OpenAI used reward models in the InstructGPT pipeline, which combined supervised fine-tuning, reward modelling and reinforcement learning to produce a model that follows instructions better. The reward model became a standard component after that, because it is the cheapest way to turn a small amount of human judgement into a training signal for a very large model.

Check yourself

QuestionRecall: what does a reward model output for a single prompt and response, and what is its training data?Show answer

It outputs one real number, a score for how good the response is. It is trained on triples of a prompt, a preferred response and a rejected response, taken from human comparisons. The scores are never supervised directly, so only their differences are learned.

QuestionCompute: a reward model gives the preferred response a score of 1.0 and the rejected response a score of −0.5. What is the loss for this pair, to three decimal places?Show answer

The score gap is Δ=1.0−(−0.5)=1.5\Delta = 1.0 - (-0.5) = 1.5. The loss is ln⁡(1+e−1.5)=ln⁡(1.2231)≈0.201\ln(1 + e^{-1.5}) = \ln(1.2231) \approx 0.201. The model agrees with the rater, so the loss is small.

QuestionWhy: adding 100 to every score a reward model outputs leaves the training loss unchanged. Why is that the right behaviour?Show answer

The loss depends only on the score gap between the preferred and rejected response, and adding a constant to both scores cancels in the subtraction. The comparisons carry no information about absolute values, so the model should not be penalised for a shift that makes no difference to the ranking. It also means the absolute score has no fixed meaning.

QuestionApplied: a team trains a reward model on comparisons from an early chat model, then uses it to tune a much stronger later model. Scores climb sharply but the human evaluators are unimpressed. What is the most likely cause, and what would you change?Show answer

The later model produces responses that lie outside the distribution the reward model was trained on, and the optimiser has found responses the proxy scores highly but people do not value. The fix is to collect fresh comparisons from the current policy, retrain or update the reward model on them, and add a KL penalty so the policy does not move too far from its starting point while it is being tuned.

Sources