liveBook · Manning

Reinforcement learning with human feedback

As explained in Transformers in Action

Reinforcement learning from human feedback is a model-optimization technique that uses human preference feedback to define or improve a reward signal.

Reinforcement learning from human feedback (RLHF) aligns language-model behavior with human intent and task-specific goals. Instead of changing the transformer architecture, it changes the model’s response distribution through structured preferences, reward signals, and optimization. Generation becomes sequential decision-making: the model learns to favor outputs such as clear technical summaries or cautious advice over verbose or speculative alternatives. section 5.0 section 5.1

A practical RLHF workflow combines preference or reward data with reinforcement-learning optimization:

  • Define preferences or a reward signal that distinguishes desirable and undesirable generations. section 5.1 section 5.5
  • Frame generation as a sequential decision-making problem using Markov decision process foundations. section 5.1
  • Optimize the model with a reinforcement-learning method such as proximal policy optimization (PPO). section 5.1 section 5.5
  • Evaluate generated responses and iterate on the dataset, reward design, model, or training configuration. section 5.1.2

The implementation can use trlX, which supports predefined reward functions or reward-labeled datasets and trains causal or T5-based models with PPO or implicit language Q-learning. A lightweight demonstration uses GPT-2 and Financial Phrasebank data, computes rewards from response length and word diversity, preprocesses samples, and trains the model with evaluation prompts. This proxy reward illustrates the pipeline but does not itself encode nuanced human preferences. section 5.1.2

Financial-language alignment experiment

Load GPT-2 and Financial Phrasebank sentences, score each sample with a reward function based on length and distinct-word count, train with trlX, and generate text from prompts such as “The market trends indicate,”. Changing the model or dataset supports direct comparisons of resulting behavior. section 5.1.2

Listing 5.4 Training the model with RLHF
default_config = default_ilql_config().to_dict() #1
default_config['train']['tracker'] = None
default_config['train']['batch_size'] = 16
default_config['train']['epochs'] = 20
config = TRLConfig.update(default_config, {})

trainer = trlx.train( #2
    model,
    samples=samples,
    rewards=rewards,
    eval_prompts=[
      "The S&P has shown",
      "The market trends indicate",
      "The economic indicators for the quarter are",
      "According to recent financial reports"
    ] * 20,
    config=config,
)

Inspect the training configuration, PPO-oriented trlX call, reward arrays, and evaluation prompts used to fine-tune and assess the model. section 5.1.2

How Transformers in Action covers it

How deep it goes
Explains MDP foundations, PPO optimization, reward preparation, training, and generation, while stopping short of detailed preference-model internals.
Examples
Uses GPT-2, Financial Phrasebank, length-and-diversity rewards, financial prompts, trlX training, and generated market-language output.
What it assumes
Assumes transformer-based language-model context while introducing Markov decision processes before presenting PPO and RLHF training.
What you can do after
Apply it via trlX by preparing samples and rewards, configuring training, optimizing a model, and generating evaluation outputs.
How it connects
Connects transformer architecture, Markov decision processes, PPO, reward models, direct preference optimization, group-relative policy optimization, and retrieval-augmented 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 Transformers in Action. The section links point to the parts of the book it draws on.