liveBook · Manning

Reinforcement learning with human feedback

As explained in Deep Learning with Python, Third Edition

A training setup that uses human preference feedback to build a reward signal for improving a model’s outputs.

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

How Deep Learning with Python, Third Edition covers it

How deep it goes
Explains data collection, reward-model construction, and tuning, but stops short of detailed reinforcement-learning mechanics.
Examples
Uses ranked candidate responses and pseudocode that filters generated outputs by reward before fitting the model.
What it assumes
Builds from supervised fine-tuning and assumes familiarity with language-model training while deliberately minimizing reinforcement-learning theory.
What you can do after
Apply a basic RLHF pipeline by collecting rankings, training a reward model, and using scores to guide further tuning.
How it connects
Connects supervised fine-tuning, reward models, human preferences, reinforcement learning, and Transformer language models.

Also explained in

Compare how 14 books explain reinforcement learning with human feedback →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Deep Learning with Python, Third Edition. The section links point to the parts of the book it draws on.