liveBook · Manning

Temporal-difference error

As explained in Reinforcement Learning from Human Feedback

A temporal-difference residual is the difference between an observed immediate reward plus a bootstrapped next-state value and the current value prediction.

Temporal-difference (TD) error measures the mismatch between a value prediction and a one-step target: δₜ = rₜ + γV(sₜ₊₁) − V(sₜ). The target combines the immediate reward with a bootstrapped estimate of the next state, so the residual indicates whether the current value estimate was too low or too high. section 6.2.1 section 6.4.1

The residual connects value estimation to policy optimization in several ways:

  • It provides a one-step advantage estimate: A(sₜ,aₜ) = Q(sₜ,aₜ) − V(sₜ) = rₜ + γV(sₜ₊₁) − V(sₜ). section 6.2.1
  • It trades bias against variance: single-step TD has lower variance but greater bias than estimates using longer returns. section 6.4.1
  • Generalized advantage estimation combines future TD errors with exponentially decaying weights, producing Âₜ = Σₗ₌₀∞(γλ)ˡδₜ₊ₗᵛ. section 6.4.1

Token-level GAE update

For each token position, compute delta = reward + gamma × not_done × next_value − value, then accumulate gae = delta + gamma × lambda × not_done × gae while iterating backward. Terminal masks stop bootstrapping and reset accumulation; the resulting advantages can become value-regression targets after adding the current values. section 6.4.1

Equation 6.55
\[\label{eq:TD_RESIDUAL} \delta_t^V = r_t + \gamma V(s_{t+1}) - V(s_t).\]

Inspect the formal one-step TD-residual equation and its placement within multistep advantage estimation. section 6.4.1

How Reinforcement Learning from Human Feedback covers it

How deep it goes
Defines the residual mathematically and derives its role in GAE, including backward accumulation, terminal masking, and value targets.
Examples
Uses the TD residual in token-level GAE code with rewards, value predictions, gamma, lambda, and terminal done masks.
What it assumes
Builds on rewards, discounted returns, value functions, action-value functions, and advantage estimates.
What you can do after
Apply it via token-level GAE to compute policy advantages and value-regression targets from rewards and value predictions.
How it connects
Connects value functions, advantage functions, policy gradients, generalized advantage estimation, and the bias-variance trade-off.

Also explained in

Compare how 2 books explain temporal-difference error →

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.