Why pre-training is not enough
After pre-training, an LLM can produce fluent, grammatical text. But fluency is not the same as usefulness. A model trained on the internet might give rude, biased, incorrect, or unsafe answers because those patterns exist in the data.
We need a second stage that teaches the model what humans actually want. That stage is RLHF: Reinforcement Learning from Human Feedback.
Key idea: RLHF aligns the model with human values: helpful, harmless, and honest.
Preference data
RLHF starts with humans comparing pairs of answers. For one prompt, a human labeler sees two responses and picks the better one. These preference pairs are the training signal.
It is easier for humans to say "A is better than B" than to write a perfect answer from scratch. Comparisons also create a ranking that a model can learn from.
Reward model
First, a reward model is trained on the human comparisons. It learns to predict how much a human will like a response. The reward model takes a prompt and a candidate response, and outputs a single number: the reward.
High reward = human probably likes this answer. Low reward = human probably does not.
The reward model is usually a smaller copy of the LLM with an extra layer that outputs a score.
Reinforcement learning
Next, the LLM is treated like a game-playing agent. It generates an answer, the reward model scores it, and the LLM updates its weights to get higher rewards next time.
Researchers often use an algorithm called PPO (Proximal Policy Optimization). It explores different answers, keeps the ones that earn more reward, and avoids changing the model too drastically in one step.
Challenge: reward models can be gamed. If the reward model thinks longer answers are better, the LLM might ramble. RLHF systems add safeguards to prevent reward hacking.
Rank the answers
Below is a prompt and four candidate responses. Drag the answers into the order you think a human labeler would prefer, from best (1) to worst (4). Then see how a simple reward model scores them.
Try this: the best answer should be clear, safe, and step-by-step. The worst should be short, unhelpful, or risky. How does your ranking compare to the reward model?
A tiny reward model in Python
A reward model does not have to be a giant neural network. The idea is the same at any scale: combine measurable features with learned weights and output a single score. This script scores the same four answers the interactive demo uses.
In a real LLM the features are not hand-labeled; they are learned from millions of comparison examples. The principle is the same: take a response, combine its qualities using learned weights, and produce a score that human labelers would agree with.
Check yourself
Why is it useful to train a separate reward model instead of asking humans to score every answer directly?
Your answer:
Sample answer: Humans are slow and expensive. Once a reward model is trained on human comparisons, it can score millions of responses automatically. That makes reinforcement learning at scale possible.
Quick quiz
1. What does RLHF stand for?
2. What is the job of the reward model?
3. Which of these is a common goal of RLHF?
Keep learning about LLMs
From data to chatbot, the full pipeline is almost complete. Next, put embeddings, pre-training, transformers, and RLHF together.
Part of the “LLMs Under the Hood” tutorial series.