Sparse Autoencoders Reveal Temporal Difference Learning in Large Language Models

Can Demircan, Tankred Saanum, Akshay Kumar Jagadish, Marcel Binz, Eric Schulz

TL;DR

Researchers have discovered that Large Language Models (LLMs) like Llama 3 70B don't just mimic text; they actually implement internal versions of reinforcement learning (RL) algorithms. By using Sparse Autoencoders (SAEs) to peer into the model's internal representations, the team found specific neural features that track Temporal Difference (TD) errors. This proves that next-token prediction can spontaneously give rise to sophisticated, classical learning mechanisms.

What Problem Does This Paper Address?

We know LLMs are incredible "in-context learners"—they can pick up new rules or tasks just from a few examples in a prompt. However, the mechanistic "how" remains a black box. Specifically, when an LLM is given a prompt describing a game with rewards (like a text-based adventure or a logic puzzle), does it solve it by simple pattern matching, or is it running a latent learning algorithm?

In classical RL and neuroscience, the "gold standard" for learning from trial and error is Temporal Difference (TD) learning. This is the process of updating expectations based on the "error" between predicted and actual outcomes. This paper investigates whether LLMs, despite being trained only to predict the next word, have internally developed the machinery to perform TD learning.

Methods and Experimental Setup

To investigate the model's internal workings, the authors employed a "microscope" for neural networks called Sparse Autoencoders (SAEs). Because standard transformer activations are "polysemantic" (entangled), SAEs decompose these high-dimensional vectors into thousands of sparse, interpretable features.

Overview of the experimental tasks and SAE methodology.

The researchers prompted Llama 3 70B with three distinct RL-style tasks:

  • The Two-Step Task: A classic RL benchmark where choices lead to intermediate states and eventually rewards.
  • Grid World: A navigation task where the model must predict the actions of an agent moving toward a goal.
  • Community Graph Task: A task predicting the next node in a random walk, testing the model's ability to learn world structure without explicit rewards (Successor Representation).

As the model processed these tasks, the team recorded activations in the residual stream. They then ran a standard Q-learning agent on the same tasks to generate "ground truth" TD errors and Q-values, looking for SAE features that correlated with these signals. Finally, they performed causal interventions (lesioning) by manually zeroing out the identified TD-related features to see if it broke the model's ability to learn.

Key Insights and Results

The study reveals that TD-like representations emerge naturally in models trained only for next-token prediction. To predict the next word in a sequence involving rewards, the model internally calculates how "surprising" a reward is.

Performance comparison between Llama 3 70B and 8B, and behavioral fit of Q-learning vs. myopic models.
  • Scale Matters: The authors found that Llama 3 70B could successfully solve these tasks, but the smaller 8B version could not. This suggests that the ability to implement complex internal learning algorithms is an emergent property of model scale.
  • Behavioral Fit: Llama 3’s behavior was better explained by a formal Q-learning model (Negative Log-Likelihood of 2729) than by simpler "look-up" or "myopic" models.
  • High Correlation: SAE features in the middle-to-late layers of Llama 3 (around block 34) showed strong correlations ($r \approx 0.58$ to $0.62$) with ground-truth TD errors.
  • Causal Reality: The identified "TD latents" are functionally necessary. When the researchers suppressed these specific features in the Graph task, next-state prediction accuracy dropped from 24.3% to 18.9%, disrupting the model's internal "beliefs" about the value of different actions.
  • Beyond Rewards: In the Graph task, the model used TD-like signals to learn the geometry of a map, showing that this mechanism is a general-purpose tool for building world models.

Limitations and Future Work

  • Task Specificity: The SAEs used in this study were trained on specific tasks. A "universal" SAE that can find RL features across any arbitrary prompt does not yet exist.
  • The "How" of the "How": While we now know where these features are, the exact "circuit" (which specific attention heads or neurons create them) remains unknown.
  • Imperfect Alignment: LLMs still exhibit some "repetition bias" not explained by pure Q-learning. Future work could integrate these priors into behavioral models.
  • Generalization: It remains to be seen if these mechanisms hold up in much more complex, natural language-heavy RL environments compared to the structured synthetic tasks used here.

Summary updated

BibTeX
@inproceedings{demircan2025sparse,
  author = {Can Demircan and Tankred Saanum and Akshay Kumar Jagadish and Marcel Binz and Eric Schulz},
  title = {{Sparse Autoencoders Reveal Temporal Difference Learning in Large Language Models}},
  booktitle = {International Conference on Learning Representations},
  year = {2025},
  url = {https://openreview.net/forum?id=2tIyA5cri8},
}
Figure