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.
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
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 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.
- 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.
- 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.
- 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.
- 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%.
- 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.
Try it yourself
Learn this first
- Reinforcement learningAn agent on a small grid learns by trial and error which moves earn the most reward. Beginner
- Pre-training vs fine-tuningTrain once on a mountain of raw text, then briefly on a small labelled set for one job. Beginner
- Neural networksFollow numbers through one tiny network by hand, and see why the bend matters. Beginner
Spotted a mistake on this page?