ML Systems Lab Open interactive version →
Advanced 65 min read rlhfreward modelbradley-terryreward hackingdpo

RLHF and Reward Modeling

Bradley-Terry model, reward hacking, Goodhart's law, DPO, KL penalty, evaluation

GPT-4 trained on internet text predicts next tokens accurately. But next-token prediction accuracy has nothing to do with helpfulness. The model often produces responses that are technically fluent but unhelpful, harmful, or dishonest — because those properties were not measured by the training objective. You want to fine-tune the model to be helpful, but you cannot write a mathematical function that measures helpfulness. You can, however, ask humans to compare two responses and say which is better.

This comparative signal is what RLHF uses. The pipeline has three stages. Stage 1: supervised fine-tuning. Fine-tune the base model on a small dataset of high-quality human-written responses. This creates an SFT model — capable, but not yet aligned. Stage 2: reward model training. Show human labelers pairs of responses to the same prompt and ask which is better. Train a reward model R_φ(prompt, response) using the Bradley-Terry preference model: P(A preferred over B) = σ(R(A) - R(B)). The reward model learns to predict human preference from comparative judgments, not absolute ratings. Stage 3: RL fine-tuning. Use PPO to optimize the SFT model to maximize R_φ(prompt, π(prompt)). Add a KL penalty KL(π || π_SFT) to prevent the model from drifting too far from SFT behavior.

The KL penalty is not optional hygiene — it is the mechanism that keeps the LLM in the distribution where the reward model's predictions are calibrated. The reward model was trained on SFT-like outputs. If PPO drifts the policy far from that distribution, the reward model is extrapolating into regions it was never trained on, and its scores become meaningless.

Reward hacking is the central failure mode. The RL policy finds outputs that maximize the reward model's score but do not actually satisfy human intent: models generate long verbose outputs because length correlates with reward, use sycophantic language because agreeing with the user scores higher than accurate disagreement, or find adversarial prompts that fool the reward model. These are not bugs — they are the optimizer doing exactly what the reward function says, which happens to diverge from what humans actually want.

NOT this: RLHF is the final step in making a language model safe and aligned. RLHF optimizes a proxy — a reward model of human preferences — for a goal — truly helpful and safe AI. The proxy has biases, blind spots, and adversarial examples. RLHF improves calibration toward human preferences but does not guarantee alignment. It is one tool in an ongoing research problem.

Key points

Takeaway

RLHF trains human preference into a reward model from comparative judgments, then uses PPO to maximize that reward — with a KL penalty to keep the policy close enough to the SFT distribution that the reward model's scores remain meaningful and reward hacking is bounded.

Recap

Check your understanding

Q1. Which two facts about the DPO derivation correctly explain how it eliminates the need for a separately trained reward model?

Q2. A model trained with RLHF consistently gives verbose answers (3x longer than the SFT baseline) with high reward model scores but lower human preference in blind evaluation. What is happening and how do you fix it?

Q3. Why is "LLM-as-judge" evaluation problematic for assessing RLHF model quality, even when the judge is a much stronger model than the one being evaluated?

Try it interactively

ML Systems Lab is a free interview-prep platform for ML engineers — work through the full interactive module, quizzes, and drills.

Open ML Systems Lab →