liveBook · Manning

Gradient

As explained in Reinforcement Learning from Human Feedback

A gradient is a vector of derivatives indicating how a scalar function changes with respect to its parameters.

A gradient is a vector of derivatives indicating how a scalar function changes with respect to its parameters. In model optimization, it supplies the direction and magnitude for changing parameters to improve an objective. In RLHF, policy-gradient methods use gradients of expected reward to translate reward-model scores into policy behavior. section 6.6 section 8.1.2

Gradient estimates take different forms depending on the optimization setting:

  • REINFORCE uses Monte Carlo returns with a batch-level baseline, while RLOO uses leave-one-out comparisons across multiple completions; neither requires a learned value function. section 6.6
  • PPO estimates per-token advantages with a learned value function and GAE, whereas GRPO normalizes advantages relative to groups of completions. section 6.6
  • DPO differentiates a sigmoid preference objective built from chosen and rejected completion log-probability ratios relative to a reference policy. section 8.1.2
  • Each token can receive a different gradient magnitude and direction according to its contribution to the preference margin. section 8.4

From preference signal to update

A policy generates several completions, a reward model scores them, and a policy-gradient estimate updates the model toward higher-reward behavior. Baselines and advantage functions reduce estimate variance; clipping, aggregation, and truncated-generation handling affect stability. section 6.6

Equation 8.5
\[\label{eq:rlhf_opt_eq_repeat} \max_{\pi} \mathbb{E}_{x \sim \mathcal{D}}\mathbb{E}_{y \sim \pi(y|x)} \left[r_\theta(x, y)\right] - \beta \mathcal{D}_{\text{KL}}\left(\pi(y|x) \| \pi_{\text{ref}}(y|x)\right).\]

The RLHF objective shows the scalar target whose gradient balances expected reward against divergence from a reference policy. section 6.6

How Reinforcement Learning from Human Feedback covers it

How deep it goes
Derives the DPO gradient through sigmoid and logarithm identities, then compares policy-gradient estimators and stability choices.
Examples
Uses generated completions, reward scores, chosen-versus-rejected pairs, token-level margins, and clipped policy objectives.
What it assumes
Assumes familiarity with model parameters, scalar objectives, policy probabilities, rewards, and preference data.
What you can do after
Apply it via policy-gradient and DPO objectives to update models toward higher reward or stronger preference margins.
How it connects
Connects gradients to policy gradients, reward models, baselines, advantage functions, PPO, GRPO, REINFORCE, RLOO, and DPO.

Also explained in

Compare how 20 books explain gradient →

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.