liveBook · Manning

Reinforcement learning with human feedback

As explained in Deep Learning with R, Third Edition

Reinforcement learning with human feedback is a training approach that optimizes a model using human preference judgments converted into reward signals.

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

How Deep Learning with R, Third Edition covers it

How deep it goes
Explains supervised initialization, preference collection, reward modeling, and a simplified optimization loop without detailing the full training algorithm.
Examples
Uses ranked alternative responses and a generate–score–filter–fit pseudocode loop as concrete teaching artifacts.
What it assumes
Builds on supervised fine-tuning with handwritten prompts and responses before introducing preference-based improvement.
What you can do after
Apply it by constructing preference data, training a reward model, and iteratively fitting a language model to high-reward responses.
How it connects
Connects supervised fine-tuning, reward models, human preference data, Transformers, and language-model generation.

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 R, Third Edition. The section links point to the parts of the book it draws on.