Lesson 5.3 · 3 of 7 · 4 min read · Reviewed 24 Nov 2026
RLHF
By the end, you can
- Explain reinforcement learning from human feedback.
- See how preferences shape model behaviour.
The steps
1. The model writes several responses to the same prompt.
2. People rank them: A better than B better than C.
3. A reward model learns to predict those rankings.
4. The assistant is trained to produce responses the reward model scores highly.
What it adds
Examples (5.2) show one good answer. Comparisons show which of several is better, which captures subtle qualities:
- Answering the actual question rather than a nearby one
- Admitting uncertainty instead of guessing
- Refusing harmful requests without refusing harmless ones
- A clear, appropriate tone
Known pitfalls
| Pitfall | Example |
|---|---|
| Reward hacking | Long answers score well, so answers grow long |
| Sycophancy | Agreeing with the user gets rated higher |
| Rater inconsistency | Different people prefer different things |
Training teams counter these with careful rating guidelines, varied raters and evaluationEval: A repeatable test that measures how well an AI system performs on a set of cases with defined success criteria..
Feedback from AI
Collecting human comparisons is slow and costly. Anthropic’s Constitutional AIConstitutional AI: Anthropic's training approach in which a model critiques and revises outputs against a written set of principles. approach uses AI feedback guided by written principles for part of this work (5.4).
Post-training today
The four steps above are the classic recipe from 2022. Current models are post-trained in more stages, and RLHF with a separate reward modelReward model: A model trained to score responses the way human raters would, used to guide reinforcement learning. is now one option among several:
| Stage | What it teaches | Where to read more |
|---|---|---|
| Supervised fine-tuning | Format, following instructions, the assistant’s voice | 5.2 |
| Preference tuning | Which of two plausible answers is better. Done with RLHF, or with direct methods such as DPO that learn from chosen and rejected pairs without a reward model | 31.1, 31.2 |
| RL with verifiable rewards | Multi-step reasoning on tasks a program can check: maths answers, passing tests, valid formats. Methods such as GRPO compare several sampled answers per prompt | 31.3 |
| AI feedback | Scaling up judgements with models guided by written principles | 5.4 |
The RL stage on checkable tasks is what produces reasoning models, which think at length before they answer (13.6). The pitfalls in the table above still apply: any reward, human or program, can be gamed.
Key points
- RLHF collects human judgements of which responses are better, trains a reward model on them, then optimises the assistant to score well.
- It teaches preferences that are hard to write as examples: helpfulness, honesty, avoiding harm, good tone.
- It can over-optimise for what raters like, such as long or agreeable answers, which needs care.
- Modern post-training adds direct preference methods such as DPO and reinforcement learning on tasks a program can check, which is what produces reasoning models.
Fit a tiny reward model from rankings
Learn reward weights from pairwise preferences and watch a length bias turn into reward hacking.
You will have: A reward model (three weights) trained by gradient ascent on preference pairs, and the scores it gives three candidate answers.
Steps
- Run the starter: all weights stay at zero, so every answer scores the same.
- Fill in reward(): the dot product of weights and features.
- Fill in the update: for each pair, nudge weights towards the preferred answer by (1 - sigmoid(margin)) times the feature difference.
- Train for 200 rounds and print the weights.
- Score the three candidates and explain why the padded answer wins.
Done when
- All three weights are positive after training.
- The padded answer outscores the short correct one, showing the length bias.
- The script prints 'reward hacking risk: length weight' when length has the largest weight.
Open in the Playground No API key needed.
Starter code (Python)
import math
# Features: [length in 100s of words, cites a source (0/1), admits uncertainty (0/1)]
# Each pair: (features of preferred answer, features of rejected answer), as raters chose.
PAIRS = [
([3.0, 1, 0], [1.0, 1, 0]), ([2.5, 0, 1], [1.0, 0, 1]), ([2.0, 1, 1], [2.0, 0, 1]),
([4.0, 0, 0], [1.5, 1, 0]), ([1.0, 1, 1], [1.0, 1, 0]), ([3.5, 1, 0], [0.8, 1, 1]),
]
CANDIDATES = {"short, correct, cited": [0.8, 1, 0], "padded, no source": [4.0, 0, 0], "medium, cited, hedged": [1.5, 1, 1]}
w = [0.0, 0.0, 0.0]
LR = 0.05
def reward(x):
return 0.0 # TODO: sum of w[i] * x[i]
def sigmoid(z):
return 1 / (1 + math.exp(-z))
for _ in range(200):
for good, bad in PAIRS:
margin = reward(good) - reward(bad)
# TODO: for each i, w[i] += LR * (1 - sigmoid(margin)) * (good[i] - bad[i])
print("weights:", [round(x, 2) for x in w])
for name, x in CANDIDATES.items():
print(f"{name:24} reward={reward(x):.2f}")
Show a solution
import math
PAIRS = [
([3.0, 1, 0], [1.0, 1, 0]), ([2.5, 0, 1], [1.0, 0, 1]), ([2.0, 1, 1], [2.0, 0, 1]),
([4.0, 0, 0], [1.5, 1, 0]), ([1.0, 1, 1], [1.0, 1, 0]), ([3.5, 1, 0], [0.8, 1, 1]),
]
CANDIDATES = {"short, correct, cited": [0.8, 1, 0], "padded, no source": [4.0, 0, 0], "medium, cited, hedged": [1.5, 1, 1]}
NAMES = ["length", "cites source", "admits uncertainty"]
w = [0.0, 0.0, 0.0]
LR = 0.05
def reward(x):
return sum(wi * xi for wi, xi in zip(w, x))
def sigmoid(z):
return 1 / (1 + math.exp(-z))
for _ in range(200):
for good, bad in PAIRS:
margin = reward(good) - reward(bad)
for i in range(3):
w[i] += LR * (1 - sigmoid(margin)) * (good[i] - bad[i])
print("weights:", {n: round(x, 2) for n, x in zip(NAMES, w)})
scores = {name: reward(x) for name, x in CANDIDATES.items()}
for name, s in scores.items():
print(f"{name:24} reward={s:.2f}")
print("top answer:", max(scores, key=scores.get))
if max(range(3), key=lambda i: w[i]) == 0:
print("reward hacking risk: length weight is the largest")