Lesson 4.11advanced4 h⚡ live demo

Reinforcement learning essentials

Learning from rewards: Bellman equations, Q-learning, policy gradients and PPO

Reinforcement learning is how a model learns from consequences instead of labels. It is optional for a vision engineer and mandatory for anyone who wants to understand modern language models: RLHF (8.3 Alignment: RLHF, PPO, DPO, GRPO and Constitutional AI) runs PPO with the LLM as the policy, reasoning models are trained with RL on verifiable rewards (8.6 Reasoning models and test-time compute), and an agent choosing tools in a loop is literally an MDP (10.3 Reasoning and planning for agents). This lesson gives you the vocabulary and the three core derivations — Bellman, Q-learning, the policy-gradient theorem — so those later lessons read as applications rather than magic.

You'll be able to

  • Define an MDP, returns, policies and value functions and write the Bellman expectation and optimality equations
  • Explain dynamic programming, Monte Carlo and TD learning, and perform a Q-learning update by hand
  • Describe DQN's two stabilizing tricks and why they are needed
  • Derive the policy-gradient theorem (log-derivative trick, causality, baselines) and write REINFORCE and actor–critic
  • Explain PPO's clipped objective and how RLHF and GRPO reuse it

Key ideas

  1. An MDP is (S, A, P, R, γ); the return G_t = Σ γᵏ r_{t+k+1}; the goal is a policy maximizing expected return with no labels, only rewards.
  2. Bellman expectation: V^π(s) = Σ_a π(a|s) Σ_{s'} P(s'|s,a)[R + γV^π(s')]; optimality: Q*(s,a) = E[r + γ max_{a'} Q*(s',a')], and π* is greedy in Q*.
  3. TD learning bootstraps with the TD error δ = r + γV(s') − V(s); Q-learning is its off-policy form with a max over next actions.
Show 4 more key ideas
  1. DQN stabilizes neural Q-learning with experience replay and a frozen target network.
  2. Policy-gradient theorem: ∇J = E[Σ_t ∇log π(a_t|s_t) · Â_t], derived with the log-derivative trick; dynamics terms vanish; baselines reduce variance without bias.
  3. Actor–critic uses a learned V as baseline (TD error or GAE as the advantage); REINFORCE uses Monte Carlo returns.
  4. PPO clips the probability ratio to [1−ε, 1+ε] so the policy improves within a trust region; RLHF runs PPO with the LLM as the policy, and GRPO replaces the critic with a group-mean baseline.

Suggested path through this lesson