Playing Atari with Deep Reinforcement Learning (DQN)
Read first: Reinforcement Learning: An Introduction, Ch. 5–6 — Monte Carlo, Temporal-Difference Learning and Q-learning
TL;DR. DQN is Q-learning (from the MC, TD and Q-learning page) with a convolutional network instead of a table. The network takes the last four 84×84 frames and outputs one Q-value per joystick action. It is trained on the Q-learning target, using experience replay to break up correlated data. With the same network and hyperparameters on seven Atari games, it beat all previous methods on six and a human expert on three.
Key idea
Section titled “Key idea”For a transition the loss is the squared TD error against a bootstrapped target:
with when is terminal. The gradient flows only through ; the target is treated as a constant. In plain words: the target is “the reward plus the best value I think I can get next”, which is the Bellman optimality equation with one sample in place of the expectation.
Three ingredients make it work at scale. Experience replay stores the last one million transitions and trains on random minibatches of 32, so each sample is reused many times and consecutive, highly correlated frames are not trained on together. ε-greedy exploration acts randomly with probability ε, annealed from 1 to 0.1 over the first million frames. Because replayed data comes from older policies, the max-based (off-policy) target is what makes reuse valid. Reward clipping to −1, 0, +1 lets one learning rate work across games.
What the 2013 paper does not have. The 2013 text defines the target with the previous iteration’s parameters, but its algorithm uses the current network for the target. The separate target network , copied from only every C steps, was introduced in the 2015 Nature version (Human-level control through deep reinforcement learning). Many tutorials present both as “DQN”.
On the search-or-answer MDP. Encode s_Q and s_E as two inputs and give the network two outputs (answer, search). If it currently predicts Q(E, answer) = 0.5 and Q(E, search) = 0.3, the transition (Q, search, −0.1, E) has target −0.1 + 0.9 × 0.5 = 0.35. A transition (E, answer, 1, end) has target 1, and its expected target is 0.8, the true q(E, answer). Because the two states share weights, nudging Q(Q, search) also moves Q(E, ·), and therefore the next target: this is why a frozen copy helps.
Results
Section titled “Results”On seven Atari 2600 games (Table 1), DQN outperformed all previous approaches on six games, using the same architecture and hyperparameters everywhere. It beat a human expert on Breakout (168 vs 31), Enduro (470 vs 368) and Pong (20 vs −3), and remained far below human performance on Q*bert (1952 vs 18900), Seaquest (1705 vs 28010) and Space Invaders (581 vs 3690). The average predicted max-Q on a fixed set of held-out states rose much more smoothly during training than the average episode reward, making it a more stable progress signal.
Connections
Section titled “Connections”- Prerequisites: Monte Carlo, TD and Q-learning (tabular Q-learning on the same toy) · Value functions and Bellman equations (the optimality equation behind the target).
- The other branch: REINFORCE and the policy gradient → Actor–critic → PPO. LLM RL mostly follows this branch.
- Value-based critics for LLM agents: ArCHer trains an off-policy utterance-level critic for a token-level policy.
- Why the state includes history: MDPs and returns (DQN’s state is a stack of recent frames, like an LLM’s prefix).
Questions to think through
These questions have no single right answer. Write or say your answer before you open the hints. Mark a question once you could defend your answer in a reading group.
- Mechanism
Write the DQN loss for one transition and explain, at the level of the gradient, why naive online Q-learning with a neural network is unstable, and how experience replay and (in the 2015 Nature version) a periodically copied target network each address part of the problem. Use the search-or-answer MDP: a network with Q(E, answer) = 0.5 and Q(E, search) = 0.3 sees the transition (Q, search, −0.1, E).
What a strong answer covers
- Target y = r + γ·max over a′ of Q(s′, a′; θ⁻) = −0.1 + 0.9·0.5 = 0.35; loss (y − Q(Q, search; θ))²; the gradient is taken only through Q(s, a; θ), with the target treated as a constant (semi-gradient).
- With shared weights, the update that moves Q(Q, search) toward 0.35 also changes Q(E, ·), so the target moves with every step; combined with bootstrapping and off-policy data this can oscillate or diverge (the deadly triad).
- Experience replay samples old transitions uniformly from a large buffer, breaking the correlation between consecutive samples and averaging the behaviour distribution, so updates are less driven by the most recent states.
- The 2013 paper defines the target with the previous iteration's parameters but has no separate target network; Nature 2015 copies θ into θ⁻ only every C steps, so the target stays fixed between copies.
- Derive / compute
Show that the DQN target is a sample of the Bellman optimality backup, explain why this makes DQN off-policy (and why replay requires that), and say what changes in the target if a transition is the last one of an episode.
What a strong answer covers
- Bellman optimality: q*(s, a) = E[r + γ·max over a′ of q*(s′, a′)]; with one sampled (r, s′) the bracketed quantity is a one-sample estimate, so y is a stochastic version of the backup with q* replaced by the current network.
- The max picks the greedy action at s′ regardless of which action the behaviour policy took next, so the target evaluates the greedy policy from any behaviour data.
- Replay data was generated by older, ε-greedy policies; only an off-policy target like this is valid on it. An on-policy target (SARSA, or the policy gradient) would need correction.
- Terminal transition: y = r (no bootstrap). In the toy, (E, answer, reward 1) has target 1, and the expected target for Q(E, answer) is 0.8.
- Design
You want a value-based critic for a search agent that chooses among a small set of tool actions per turn (search, read top result, answer). Design a DQN-style learner: what the state and Q-head are, what the buffer stores, how you handle the fact that turns are long text and the action set changes by context, and when you would prefer a policy-gradient method instead.
What a strong answer covers
- State: an encoding of the transcript so far (question, queries, retrieved snippets). Q-head: one output per discrete tool action, like DQN's one output per Atari action, so one forward pass scores all actions.
- Buffer: (transcript, action, tool cost or final reward, next transcript, done). Targets: r + γ·max over valid next actions of the target network's Q; mask invalid actions in the max.
- Off-policy replay lets you reuse logged agent trajectories and old rollouts, which is the main advantage over on-policy PPO, as ArCHer does with an utterance-level off-policy critic.
- Prefer policy gradient when the action is free-form text (query wording, the answer itself): the max over a huge or open-ended action space has no direct form, and the overestimation bias of the max grows with the number of actions.