All Lessons

Policy Gradients Without the Mystery

Connect action probabilities and advantages to a practical learning direction.

AI Narration Press play to listen
0  / 6 paragraphs
Click any paragraph to jump · Scroll freely without breaking narration

Policy learning follows a direct rule: make helpful sampled actions more likely and harmful sampled actions less likely. The advantage supplies helpful versus harmful, and the action's log probability connects that signal to neural-network gradients.

For every recorded step, multiply the gradient of the chosen action's log probability by its advantage. Averaging these terms produces a policy-gradient estimate. Positive advantages reinforce an action in its situation; negative advantages suppress it.

Log probabilities are convenient because they turn products of trajectory probabilities into sums. In code, obtain log probability from the distribution object that sampled the action. Recomputing it incorrectly can detach the gradient or use the wrong action shape.

Suppose an action had probability sixty percent and then produced a positive advantage. The update tends to raise that probability. The same action in another observation can have a negative advantage, so the policy learns context-dependent behavior rather than a global favorite action.

Policy-gradient data is on-policy: it came from the policy being improved. Once the policy changes substantially, old trajectories describe a different action distribution. PPO records old log probabilities so it can measure and limit this mismatch.

Before adding clipping, verify finite log probabilities, mixed advantage signs, changing parameters, and sensible action shapes. Track return, policy entropy, and gradient norm. No change often means a detached tensor; violent change often means rewards or advantages are badly scaled.