RLHF

How a text predictor is tuned into an assistant: people compare answers, a second model learns their preferences, and its scores steer the first model. Six steps, one worked example.

Intermediate6 steps~6 min
Model — the language model being tuned (the policy)
Rater — a person who picks the better answer
Reward model — learns the raters’ taste, gives scores
Answer — one piece of text the model wrote
// THE SHORT VERSION

In 30 seconds

RLHF means reinforcement learning from human feedback. It starts with a language model that can write many plausible answers but has no idea which ones people find helpful.

People are shown pairs of answers and pick the better one. A second network, the reward model, learns from those choices to give any answer a score.

The language model is then adjusted so that high-scoring answers become more likely. Its behaviour drifts towards what the raters preferred, which is why the method shapes how assistants respond, flaws of the raters and the scorer included.

RLHF, step by step

STEPS01 / 06

Toy numbers: one prompt, two possible answers, one plain policy-gradient step with learning rate 1. Published systems use methods such as PPO and add a penalty for drifting far from the starting model.

STEP 01 / 06 A model that predicts text
THE MATH
pretrained model: prompt → likely next words likely ≠ helpful
  1. Step 1: A model that predicts text. RLHF starts from a language model already trained to continue text. Ask it a question and it can produce many plausible continuations. Some answer the question, some wander off, some are curt. Its training rewarded predicting likely text, not being useful to the person asking.
  2. Step 2: People compare answers. The model writes two answers to the same prompt and a person picks the better one. That choice is stored with the prompt and both answers. Collected many thousands of times, these comparisons are the preference data: the human feedback in the name.
  3. Step 3: Train a reward model. A second network, the reward model, reads an answer and outputs one number. The gap between two scores is turned into the chance that people prefer the first answer. Training adjusts the scores until that chance matches what raters chose: here answer A rises to 1.8 and B falls to −0.2, so A is predicted to win 88% of the time.
  4. Step 4: The scorer stands in. Once trained, the reward model can score answers no person has ever compared. A fresh, useful answer gets a high number; a dismissive one gets a low number. People could never read millions of drafts, but this stand-in can, and that makes the next step possible.
  5. Step 5: Update the policy. The model’s policy is its habit of choosing one answer over another. Reinforcement learning treats each answer as an action and the score as its reward: the weights are nudged so answers that scored above average become more likely. Here one update lifts answer A from a 50% chance to 73%.
  6. Step 6: Why it shapes behaviour. Run the loop many times and the model drifts towards whatever raters tended to pick: clear, on-topic, polite, careful. That is how an assistant’s manner is shaped. But the reward model is a stand-in for human judgement, so the policy can learn answers that score well without being better, and raters’ blind spots are copied too.
VALUES SO FAR
starttext predictormodel
data····human
r(A)····score
r(B)····score
P(A>B)····predicted
r(C)····unseen
P(A)····policy
caveat····limit
// AFTER

Learn next

Nothing builds on this one yet. See every ai & machine learning concept.

Spotted a mistake on this page?