Policy Gradient Methods › Policy Gradient Methods

Michael BrenndoerferDecember 26, 20254 min read
Language AI HandbookAll chapters
Part 37 of 67Alignment and RLHF
Chapter 277Policy Gradient Methods › Policy Gradient Methods
Reading section 1 of 14 · Policy Gradient Methods · 4 minSection 1 of 14 · 4 min

Book contents

Section 1 of 14 · 4 min read

Policy Gradient Methods › Policy Gradient MethodsOne section · Sections in this chapter1 / 14 ↓
Reading tools Definitions & inline links

Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.

Article links

Make inline references clickable

With a trained reward model that captures human preferences, we face a basic challenge: how do we use this reward signal to improve our language model? The reward model tells us whether a complete generated response is good or bad, but our language model makes decisions token by token, one word at a time. We need a way to propagate that final reward signal back through the entire generation process to influence all of the individual token choices that collectively produced the outcome.

This challenge has a name in machine learning: the credit assignment problem. When a student gets a high score on an exam, you want to reinforce the study habits that led to that success, but determining which specific habits mattered most is hard. Language model alignment faces the same difficulty. A response might consist of hundreds of tokens, and only some of those tokens made the response good. The reward model scores the whole response, not individual tokens. We need a principled way to distribute credit across all the decisions that contributed to the outcome.

This is precisely where reinforcement learning enters the picture. Unlike supervised learning, where we have explicit targets for each prediction (we know the correct next token at every position), reinforcement learning can work with sparse feedback that arrives after an entire trajectory rather than at each step. Policy gradient methods provide a mathematically principled framework for optimizing a model's behavior based on exactly this kind of reward signal.

The core idea behind policy gradients is elegant in its simplicity. Think of it as a trial-and-error learning system operating at the level of complete responses. The model generates a response, receives a reward signal, and then adjusts its parameters to make similar responses more (or less) likely in the future depending on whether the reward was positive or negative. Over thousands of such updates, the model learns to generate the kinds of responses that tend to receive high rewards. The mathematical machinery we develop in this chapter makes this intuition precise and computationally tractable.

In this chapter, we develop the theory behind policy gradients from first principles, derive the key mathematical results that make training possible, and implement the REINFORCE algorithm. Along the way, we encounter the variance problem that makes naive REINFORCE impractical at scale, and we develop variance reduction techniques including baselines, advantages, and reward-to-go. This foundation is needed for understanding PPO and the complete RLHF pipeline that follows in subsequent chapters.

Historical Context

Policy gradient methods have a long history in reinforcement learning, predating their application to language models by decades. Ronald Williams introduced the REINFORCE algorithm in 1992, recognizing that the gradient of expected reward could be estimated from Monte Carlo samples. The key mathematical tool he used, the log-derivative trick (also called the likelihood ratio trick), had been known in statistics for years under different names.

Throughout the 1990s and 2000s, policy gradients were applied primarily to robotics and game playing, but their high variance made them impractical for many tasks. Actor-critic methods, which combine policy gradients with value function estimation, helped control variance. Trust region methods like TRPO (2015) and PPO (2017) further tamed the instability by constraining how much the policy could change per update.

The application to language model alignment came much later. InstructGPT (2022) was one of the first published large-scale systems to use PPO for aligning language models with human preferences, building directly on the theoretical foundations Williams established thirty years earlier. The underlying policy gradient theorem is the same; what changed was the scale, the reward model, and the engineering required to make it work with billion-parameter models.