Reinforcement learning with human feedback (RLHF) improves a language model by turning human preferences between responses into a reward signal. It addresses the bottleneck of writing every desirable answer by hand. section 16.4.1
A practical RLHF pipeline proceeds as follows:
- Start with supervised fine-tuning on handwritten prompts and responses. section 16.4.1
- Collect alternative responses from people, the model, or other chatbot models, then have evaluators rank them by helpfulness. section 16.4.1
- Train a reward model to assign one floating-point score to each prompt–response pair, with higher scores representing stronger preferences. section 16.4.1
- Generate responses, score them, retain responses above a cutoff, and fit the language model toward those responses. section 16.4.1
Listing 16.15 Pseudocode for the simplest possible RLHF algorithm
for (prompts in dataset) {
responses <- model$generate(prompts) #1
rewards <- reward_model |> predict(responses) #2
good_responses <- responses[rewards > cutoff]
model |> fit(good_responses) #3
}
Pseudocode makes the generate–score–select–fit loop explicit. section 16.4.1













