Understanding RLHF
Introduction
Reinforcement Learning from Human Feedback (RLHF) is the technique that transformed large language models from text predictors into helpful, harmless assistants. It is the key ingredient behind ChatGPT, Claude, and other aligned LLMs.
The Three Stages of RLHF
Stage 1: Supervised Fine-Tuning (SFT)
Start with a pre-trained LLM and fine-tune it on high-quality demonstration data:
LSFT=−E(x,y)∼D[logπθ(y∣x)]
where (x,y) are prompt-response pairs curated by human annotators.
Stage 2: Reward Model Training
Train a reward model rϕ(x,y) from human preference data. Given pairs (yw,yl) where yw is preferred over yl:
LRM=−E(x,yw,yl)[logσ(rϕ(x,yw)−rϕ(x,yl))]
This follows the Bradley-Terry model of preferences.
Stage 3: RL Optimization (PPO)
Optimize the policy against the reward model using Proximal Policy Optimization:
LPPO=Ex∼D,y∼πθ[rϕ(x,y)−β⋅DKL(πθ∥πref)]
The KL penalty β⋅DKL prevents the model from deviating too far from the SFT model and exploiting the reward model.
DPO: A Simpler Alternative
Direct Preference Optimization (DPO) eliminates the need for a separate reward model:
LDPO=−E(x,yw,yl)[logσ(βlogπref(yw∣x)πθ(yw∣x)−βlogπref(yl∣x)πθ(yl∣x))]
DPO shows that the optimal policy under the RLHF objective has a closed-form solution, allowing direct optimization from preferences.
Challenges
- Reward hacking: The model may find shortcuts to maximize the reward without being genuinely helpful
- Annotation quality: Human preferences are noisy and inconsistent
- Distribution shift: The policy moves away from the training distribution during RL
- Scalable oversight: As models become more capable, human evaluation becomes harder
Conclusion
RLHF (and its variants like DPO) bridges the gap between raw language modeling capability and aligned, useful AI behavior. It remains an active area of research in AI alignment.
References
- Ouyang et al., "Training language models to follow instructions with human feedback," NeurIPS 2022.
- Rafailov et al., "Direct Preference Optimization," NeurIPS 2023.
- Christiano et al., "Deep RL from Human Preferences," NeurIPS 2017.