Q-learning discovers a policy indirectly — learn a value for every action, then always take the best one. What if a policy could just be a set of parameters, adjusted by gradient ascent, the same way every other model in this course has been?
Back to the three-armed bandit — but instead of a Q-table, there's a preference number for each arm, run through a softmax to get a probability of picking it. Step through five pulls and watch the bars themselves shift: an arm that pays off gets more likely to be picked next time, one that doesn't gets less so.
With preferences and policy , the REINFORCE update after taking action and observing return is:
- — the preference parameter for action , before being run through softmax.
- — the current policy's probability of picking action : softmax of the preferences.
- — the action that was actually taken.
- — equals if is the action actually taken, otherwise.
- — the return observed for that action.
- — the learning rate controlling the update size.
- Same shape as the softmax cross-entropy gradient
is exactly the softmax cross-entropy gradient from Part II, indicator minus predicted probability.
- But scaled by the return, not by 1
Cross-entropy always scales by (the true label is certain), while REINFORCE scales by , whatever return that action happened to earn.
- What that scaling does
A big positive return pushes hard toward that action; a return of exactly zero pushes not at all.
Compare the very first policy to the one after five pulls. Nothing here ever built or consulted a value table — the probabilities shifted directly, one gradient step at a time, purely from the returns each pull happened to produce.
Starting from — a uniform policy — with :
- First pull: arm A, reward 1
before the update. Each preference updates by :
B and C both drop, pushed down even though they weren't pulled, simply for not being the chosen action.
- A reward of exactly zero changes nothing
Pulling arm C next happens to pay . Since the update scales by the return, multiplying by zeroes out every single term — comes out of that step completely unchanged, regardless of which arm was pulled.
- After all five pulls
Pulls 3 and 5 both pay , so (per the previous step) they leave unchanged. Only pulls 2 and 4 (both pulling B, both paying ) move the parameters:
- After pull 2: from , giving
- After pull 4: from that , giving
, clearly ahead of and — the policy now assigns arm B more than half its probability mass, without ever computing a single .
Step forward until the policy gives arm B more than half the probability mass.
Q-learning and policy gradients solve the exact same problem from two different directions: one estimates values and reads a policy off them; the other adjusts a policy directly, using nothing but the returns actions happen to produce. Both are, underneath, still gradient-based learning from a numeric signal — the same idea as every optimizer since Part II, aimed at a different kind of objective. The next chapter applies that same direct-policy idea somewhere it's become extremely consequential: teaching a language model to prefer the answers people actually like.