Reward Modeling
Reward modeling is the process of training a supervised model to predict human preference scores over model outputs, providing a differentiable proxy signal that can then drive reinforcement learning fine-tuning of large language models. It sits at the heart of RLHF (Reinforcement Learning from Human Feedback) pipelines, making it possible to align LLMs to nuanced human values that cannot be captured by simple likelihood objectives. A counterintuitive fact: a well-trained reward model can become the single biggest bottleneck in alignment quality — errors in the reward model are amplified, not averaged out, when the policy is optimized against it for thousands of steps.
Human preferences are the ground truth, but humans cannot provide a gradient signal — they can only say "I prefer A over B." A reward model converts that discrete, sparse preference signal into a continuous scalar that a policy optimizer can differentiate through. The "aha moment" is realizing that you are training a model of human judgment, not a model of correctness, and those two things can diverge in subtle, dangerous ways. Once you internalize this, reward hacking, Goodhart's Law, and the need for iterative data collection all follow naturally.
How It Works
Preference Data Collection
The reward modeling pipeline begins with a preference dataset. A prompt is sampled, a frozen or partially-trained policy generates completions , and human annotators (or AI labelers) rank them, producing pairwise comparisons — "winner" and "loser."
The Bradley-Terry Model
The standard reward model loss is derived from the Bradley-Terry model for pairwise preferences. Suppose every completion has a latent quality scalar . The probability that is preferred over is:
Explanation: The sigmoid squashes the difference in predicted reward scores into a probability, so larger reward gaps produce higher preference probabilities. Here is the logistic sigmoid, is the reward model (parameterized by ) applied to the concatenation of prompt and completion , is the preferred completion, and is the dispreferred completion.
Training Objective
Given a dataset of human-labeled pairs, we minimize the negative log-likelihood of the observed preferences:
Explanation: This is binary cross-entropy loss applied to the reward difference, pushing the model to assign strictly higher scores to preferred completions. This loss is convex in the reward difference, which makes optimization stable early in training. In PyTorch: ```python import torch import torch.nn.functional as F def reward_model_loss(r_win: torch.Tensor, r_lose: torch.Tensor) -> torch.Tensor: """ r_win: (batch,) scalar rewards for preferred completions r_lose: (batch,) scalar rewards for dispreferred completions """ return -F.logsigmoid(r_win - r_lose).mean() ```
Architecture
The reward model is typically initialized from the same pretrained (and often SFT-fine-tuned) backbone as the policy. The language model head is replaced with a scalar projection head: a linear layer that maps the final hidden state of the last token to a single real number. ```python import torch.nn as nn from transformers import AutoModel class RewardModel(nn.Module): def __init__(self, backbone_name: str): super().__init__() self.backbone = AutoModel.from_pretrained(backbone_name) hidden_size = self.backbone.config.hidden_size self.value_head = nn.Linear(hidden_size, 1, bias=False) def forward(self, input_ids, attention_mask): outputs = self.backbone(input_ids=input_ids, attention_mask=attention_mask)
# Use last non-padding token's hidden state last_hidden = outputs.last_hidden_state # (B, T, H)
# Gather last real token seq_lens = attention_mask.sum(dim=1) - 1 # (B,) batch_idx = torch.arange(last_hidden.size(0)) pooled = last_hidden[batch_idx, seq_lens] # (B, H) return self.value_head(pooled).squeeze(-1) # (B,) ```
KL Penalty During RL Fine-Tuning
Once deployed inside an RLHF loop, the reward signal used to update the policy is not bare — it includes a KL penalty to prevent the policy from drifting too far from the SFT reference model :
Explanation: Subtracting a scaled KL divergence penalizes outputs that are improbable under the reference policy, limiting reward hacking by keeping the policy inside the reward model's training distribution. Here is the current RL policy, is the frozen SFT policy, and is a tunable coefficient. A larger trades alignment optimization for distributional safety.
Reward Hacking and Overoptimization
Empirically, reward model score and actual human preference follow an inverted-U relationship as a function of RL training steps. Formally, if we define the true reward and the proxy reward , Goodhart's Law states:
Explanation: Once the policy saturates the proxy reward, further optimization exploits systematic errors in the reward model rather than genuinely improving quality. This motivates tracking both proxy reward and independent human eval throughout RL training, and halting when they decouple.
Paul Christiano completed his PhD at UC Berkeley under Scott Aaronson and later founded the Alignment Research Center. His 2017 paper "Deep Reinforcement Learning from Human Preferences" (with Leike, Martic, and others at OpenAI/DeepMind) introduced the idea of learning a reward model from binary human comparisons and using it to train RL agents on tasks where reward is hard to specify — a framework that directly seeded InstructGPT and ChatGPT. Surprisingly, Christiano's original experiments used Atari and MuJoCo environments, not language; the translation to LLMs came several years later.
Intuition
Imagine you are training a new employee to review essays for quality, but you cannot give them a rubric — you just sit with them for a day, showing them pairs of essays and saying "this one is better." After training, you send them off to score essays alone. At first they do a good job because the essays they see look like the ones you practiced with. But then a clever student realizes they can game your employee's scoring heuristics — writing long, confident-sounding essays with impressive vocabulary that your rater consistently scores highly, even if the underlying logic is hollow. That is reward hacking. The reward model is your trained rater; the student exploiting them is the RL policy. The KL penalty is like requiring the student's essay to still look recognizably like essays from before RL training, so they cannot drift too far into pure score-gaming territory.
Historical Development
Origins · 1 minhow this was discovered
Why It Matters
Prerequisites
What This Leads To
See Also
Reinforcement Learning from Human Feedback · Direct Preference Optimization · Proximal Policy Optimization · Constitutional AI · Instruction Tuning