Towards mental time travel: a hierarchical memory for reinforcement learning agents

Andrew K. Lampinen, Stephanie C. Y. Chan, Andrea Banino, Felix Hill

Reinforcement Learning (RL) agents often struggle with "long-term" memory. While architectures like LSTMs and Transformers exist, they have significant flaws in RL contexts. LSTMs compress the entire past into a single fixed-size vector, which inevitably loses fine-grained detail over time. Transformers, on the other hand, use attention to look at the past, but attending to every previous timestep is computationally expensive and introduces "noise" from irrelevant intervening events (distractors).

Researchers at DeepMind have developed Hierarchical Chunk Attention Memory (HCAM), a novel architecture that allows RL agents to "mentally time-travel." By organizing memories into chunks and using a two-tier attention mechanism, agents can recall specific past details across long delays and distracting tasks, significantly outperforming standard Transformers and LSTMs in complex environments.

The Need for Mental Time Travel

Agents need to be able to recall a temporally structured event (like a sequence of movements) in detail, even if that event happened minutes ago and was followed by completely unrelated tasks. The authors call this ability "mental time travel"—the capacity to jump back to a specific moment and "re-live" it without being distracted by everything that happened in between.

Hierarchical Chunk Attention Memory (HCAM)

The core innovation is HCAM. Instead of a flat memory buffer, HCAM uses a two-step retrieval process:

HCAM Architecture
  1. Chunking: The agent’s experience is divided into fixed-length "chunks" (sequences of timesteps).
  2. Summarization: For each chunk, the agent creates a "summary key" by average-pooling the activations.
  3. Hierarchical Attention:
    • Level 1 (Coarse): The agent performs attention over the high-level chunk summaries to identify which chunks are relevant to the current goal.
  4. Level 2 (Detailed): The agent then performs detailed, timestep-by-timestep attention only within the top-$k$ most relevant chunks.

This approach is both sparse (it ignores irrelevant chunks) and detailed (it recovers full information from the chosen chunks). To ensure the memory actually stores useful features, the authors use an auxiliary reconstruction loss, forcing the agent to be able to "rebuild" the original visual and linguistic inputs from its memory.

Evaluation and Datasets

The authors evaluated HCAM across a diverse battery of challenging memory tasks:

Visual Match Task
  • Object Permanence & Visual Match: 3D Unity environments where objects jump out of boxes and hide, or where agents must match visual cues across long delays.
  • Remembering the Ballet: A 2D task where an agent watches several "dancers" perform unique 16-step sequences and must later identify a specific dancer based on their moves.
  • Rapid Word Learning: A meta-learning task where agents must bind novel names to objects after a single exposure and retain that knowledge through multiple "distractor" phases.
  • One-Shot StreetLearn: A complex navigation task using Google StreetView images where the agent must plan paths in a new neighborhood based on a single exploration.

Key Insights and Results

  • Sparsity as a Filter: By only attending to the top-$k$ chunks, HCAM effectively "shuts out" the noise of distractor tasks. In word-learning tasks, HCAM generalized to 20 distractor phases after being trained on only 2—a 10x extrapolation.
  • Superior Scaling: In the Ballet task with 8 dancers and long delays, HCAM maintained near-perfect accuracy, while Gated TransformerXL (TrXL) performance degraded significantly, even though the entire task fit within TrXL's attention window.
  • Computational Efficiency: Standard attention scales as $O(N \times C)$ (where $N$ is the number of chunks and $C$ is chunk size). HCAM scales as $O(N + kC)$. This makes it significantly faster and more memory-efficient for long sequences.
  • Zero-Shot Generalization: Surprisingly, HCAM agents trained on single episodes were able to maintain knowledge across episodes. They could recall a word learned four episodes ago, even though they were never explicitly trained to keep memory across episode boundaries.
  • Beating Specialized Models: HCAM achieved near-optimal performance on the StreetLearn navigation task, matching the performance of the Episodic Planning Network (EPN), a model specifically engineered for that task.

Limitations and Future Work

Currently, HCAM uses arbitrary, fixed-length chunks. Human memory uses "event segmentation"—dividing the past based on meaningful changes in the environment. Implementing dynamic chunking is a clear next step. Furthermore, while HCAM is computationally efficient in terms of FLOPs, it still requires keeping all past activations in hardware memory. Scaling this to millions of timesteps would require more advanced hierarchical layers or efficient $k$-Nearest Neighbor (kNN) lookups. Finally, the current model uses simple average-pooling for chunk summaries; more sophisticated compression could further improve the "coarse" level of the hierarchy.

Summary updated

BibTeX
@inproceedings{lampinen2021towards,
  author = {Andrew K. Lampinen and Stephanie C. Y. Chan and Andrea Banino and Felix Hill},
  title = {{Towards mental time travel: a hierarchical memory for reinforcement learning agents}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2021},
  url = {https://openreview.net/forum?id=E8khKdhSsQ},
}
Figure