Reinforcement learning with human feedback (RLHF) improves a language model by turning human preferences into a trainable reward signal. It avoids writing every ideal response by hand, which is slow, expensive, and limited by human performance. section 16.4.1
A practical RLHF workflow is:
- Start with supervised fine-tuning on handwritten prompts and responses to establish a useful baseline. section 16.4.1
- Collect multiple responses for each prompt, then have human evaluators rank them from most helpful to least helpful. section 16.4.1
- Train a reward model to read a prompt-response pair and return one floating-point preference score. section 16.4.1
- Use those rewards in a reinforcement-learning setup to tune the original model beyond its supervised baseline. section 16.4.1
Ranking responses instead of writing every answer
For one prompt, gather several candidate responses, including model- or chatbot-generated answers. Evaluators rank them by helpfulness; the reward model learns that preference and scores later generations. 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 = [] for response, score in zip(responses, rewards): if score > cutoff: good_responses.append(response) model.fit(good_responses) #3
The pseudocode makes the feedback loop concrete: generate responses, score them with the reward model, retain responses above a cutoff, and fit the model on the selected outputs. section 16.4.1













