liveBook · Manning

Implicit reward

As explained in Reinforcement Learning from Human Feedback

An implicit reward is a reward value inferred from a preference-optimization objective rather than predicted by a separately trained reward model.

In DPO, an implicit reward replaces a separately trained reward model. For a completion y given prompt x, it is β times the policy’s log-probability relative to the reference model: completions the policy raises in probability relative to the reference receive higher implicit reward. section 8.1.1

Equation 8.3
\[\label{eq:dpo_reward} r(x, y) = \beta \log \frac{\pi_r(y \mid x)}{\pi_{\text{ref}}(y \mid x)},\]

The reward is defined by the policy-to-reference log-probability ratio, scaled by β. section 8.1.1

DPO compares this relative shift for a chosen completion with the shift for a rejected one. Its loss favors a larger shift for the chosen response. In implementation, the policy and frozen reference model provide log-probabilities for both completions; the resulting implicit rewards can be detached from the gradient graph for logging. section 8.1.1 section 8.3

pi_logratios = policy_chosen_logps - policy_rejected_logps   1
ref_logratios = reference_chosen_logps - reference_rejected_logps2

logits = pi_logratios - ref_logratios3

losses = -F.logsigmoid(beta * logits)4

chosen_rewards = (
    beta * (policy_chosen_logps - reference_chosen_logps).detach()
)5

rejected_rewards = (
    beta * (policy_rejected_logps - reference_rejected_logps).detach()
)

This implementation computes chosen and rejected rewards from policy and reference log-probabilities, then detaches them for logging. section 8.3

How Reinforcement Learning from Human Feedback covers it

How deep it goes
Defines the reward as a scaled log-probability ratio and shows its use in the DPO loss and implementation.
Examples
Uses chosen and rejected completions, their policy and reference log-probabilities, and detached rewards for logging.
What it assumes
Assumes prompt-completion preference pairs and policy and reference-model log-probabilities; does not require a separately trained reward model.
What you can do after
Apply DPO by computing implicit rewards from policy and reference log-probabilities for chosen and rejected completions.
How it connects
Connects DPO with reference models, preference data, and reward modeling.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Reinforcement Learning from Human Feedback. The section links point to the parts of the book it draws on.