From Memories to Maps: Mechanisms of In-Context Reinforcement Learning in Transformers
On the map: Deep reinforcement learning methods → Deep RL algorithms and representations
Abstract (arXiv)
Humans and animals show remarkable learning efficiency, adapting to new environments with minimal experience. This capability is not well captured by standard reinforcement learning algorithms that rely on incremental value updates. Rapid adaptation likely depends on episodic memory -- the ability to retrieve specific past experiences to guide decisions in novel contexts. Transformers provide a useful setting for studying these questions because of their ability to learn rapidly in-context and because their key-value architecture resembles episodic memory systems in the brain. We train a transformer to in-context reinforcement learn in a distribution of planning tasks inspired by rodent behavior. We then characterize the learning algorithms that emerge in the model. We first find that representation learning is supported by in-context structure learning and cross-context alignment, where representations are aligned across environments with different sensory stimuli. We next demonstrate that the reinforcement learning strategies developed by the model are not interpretable as standard model-free or model-based planning. Instead, we show that in-context reinforcement learning is supported by caching intermediate computations within the model's memory tokens, which are then accessed at decision time. Overall, we find that memory may serve as a computational resource, storing both raw experience and cached computations to support flexible behavior. Furthermore, the representations developed in the model resemble computations associated with the hippocampal-entorhinal system in the brain, suggesting that our findings may be relevant for natural cognition. Taken together, our work offers a mechanistic hypothesis for the rapid adaptation that underlies in-context learning in artificial and natural settings.
Key facts. Cited by 1 paper in the map (data through 14 Oct 2026). Placed in Deep RL algorithms and representations, one of 15 directions in Deep reinforcement learning methods. Builds on 28 of its 61 references that are in the map. First posted on arXiv 24 Jun 2025.
Builds on
28 of 61 references.
References · 28
- 2017Attention Is All You Needcited by 60,361
- 2020Language Models are Few-Shot Learnerscited by 32,419
- 2017Axiomatic Attribution for Deep Networkscited by 3,384
- 2020Transformers are RNNs: Fast Autoregressive Transformers with Linear Attentioncited by 2,022
- 2015Deep Reinforcement Learning with Double Q-learningcited by 1,745
- 2020Transformer Feed-Forward Layers Are Key-Value Memoriescited by 1,336
- 2014Neural Turing Machinescited by 644
- 2016RL2: Fast Reinforcement Learning via Slow Reinforcement Learningcited by 503
- 2020Hopfield Networks is All You Needcited by 475
- 2016Learning to reinforcement learncited by 377
- 2019Measuring Compositional Generalization: A Comprehensive Method on Realistic Datacited by 284
- 2017Meta Networkscited by 269
16 more
- 2016Using Fast Weights to Attend to the Recent Pastcited by 170
- 2023Supervised Pretraining Can Learn In-Context Reinforcement Learningcited by 139
- 2023Human-Timescale Adaptation in an Open-Ended Task Spacecited by 138
- 2020Large Associative Memory Problem in Neurobiology and Machine Learningcited by 112
- 2021Relating transformers to models and neural representations of the hippocampal formationcited by 62
- 2024ICLR: In-Context Learning of Representationscited by 50
- 2024The broader spectrum of in-context learningcited by 35
- 2025(How) Do Language Models Track State?cited by 34
- 2021Attention Approximates Sparse Distributed Memorycited by 29
- 2018Been There, Done That: Meta-Learning with Episodic Recallcited by 26
- 2025Key-value memory in the braincited by 24
- 2020Rapid Task-Solving in Novel Environmentscited by 23
- 2020MEMO: A Deep Network for Flexible Combination of Episodic Memoriescited by 21
- 2021Biological learning in key-value memory networkscited by 18
- 2019Graph Structured Prediction Energy Networkscited by 10
- 2025Flexible Prefrontal Control over Hippocampal Episodic Memory for Goal-Directed Generalizationcited by 4
Built on by
Citing papers per year: 2026: 1.
1 paper.
Similar, not cited
Close in wording, no citation either way
- 2025Memo: Training Memory-Efficient Embodied Agents with Reinforcement Learning
- 2026Reward Structure Shapes the Interaction Between Episodic Exploration and Neural Memory in Reinforcement Learning
- 2026In-Context Reinforcement Learning under Non-Stationarity: A Survey
- 2024Transformers Can Learn Temporal Difference Methods for In-Context Reinforcement Learning
- 2024Spatially-Aware Transformer for Embodied Agents
- 2026Transformers Provably Implement In-Context Reinforcement Learning with Policy Improvement
- 2025Memento 2: Learning by Stateful Reflective Memory
- 2026Artifacts as Memory Beyond the Agent Boundary