liveBook · Manning

Reward model

As explained in Deep Learning with Python, Third Edition

A model that scores candidate outputs according to how well they match human preferences.

A reward model turns human preference into a usable training signal. Given a prompt and candidate response, it returns one floating-point score: higher means more preferred. This avoids writing every ideal response by hand. section 16.4.1

From rankings to scores

Collect several responses for each prompt, including handwritten or model-generated answers. Human evaluators rank them from most helpful to least helpful. Train the reward model on these rankings, then use its scores to guide further model tuning. section 16.4.1

A reward model is usually a smaller Transformer that reads a complete sequence and produces a rating rather than predicting the next token. In reinforcement learning, generated responses become actions and reward scores provide feedback. 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 shows the simplest loop: generate responses, score them, retain responses above a cutoff, and fit the model on those results. section 16.4.1

How Deep Learning with Python, Third Edition covers it

How deep it goes
Explains data collection, scoring architecture, and a basic reinforcement-learning loop, but defers deeper reinforcement-learning details.
Examples
Uses ranked prompt responses and pseudocode that filters generated responses by reward cutoff before fitting.
What it assumes
Assumes a supervised-fine-tuned baseline and introduces human ranking data before explaining preference-based optimization.
What you can do after
Apply it via reinforcement learning to score generated responses and guide further language-model tuning.
How it connects
Connects human preferences with supervised fine-tuning, reinforcement learning, Transformers, and language-model generation.

Also explained in

Compare how 5 books explain reward model →

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.