Learning Cognitive Maps from Transformer Representations for Efficient Planning in Partially Observed Environments

Antoine Dedieu, Wolfgang Lehrach, Guangyao Zhou, Dileep George, Miguel Lazaro-Gredilla

Abstract

Transformers excel at sequence prediction but struggle with planning in partially observed environments (POEs) due to perceptual aliasing. We present the Transformer with Discrete Bottleneck (TDB), which compresses history into discrete latent codes to extract explicit "cognitive maps." These maps enable external graph solvers to find optimal paths efficiently. Experiments across 2D, 3D, and textual domains demonstrate that TDB achieves optimal planning performance where vanilla transformers fail, while maintaining high predictive accuracy.

Introduction

While Large Language Models (LLMs) are world-class predictors, they are notoriously bad at planning and navigation. A major reason is that they lack an explicit "world model" that can be queried. This becomes a nightmare in Partially Observed Environments (POEs) characterized by perceptual aliasing—situations where different physical locations yield identical observations. To navigate such spaces, an agent must integrate its entire history of actions and observations to disambiguate its current state.

A vanilla transformer can predict the "next view" perfectly, but to find a path to a distant goal, it must perform "forward rollouts," simulating every possible sequence of future actions. In aliased spaces, these rollouts branch out exponentially, making it nearly impossible for the model to find an optimal path or even know when it has reached its goal.

The Transformer with Discrete Bottleneck (TDB)

To address these limitations, we introduce the Transformer with Discrete Bottleneck (TDB). The architecture starts with a standard causal transformer but introduces a Vector Quantizer (VQ) bottleneck. Instead of passing high-dimensional continuous representations to the output, the model is forced to compress the complex history into a single discrete latent code (an index).

To ensure these latent codes capture the underlying structure of the environment, we employ two key training objectives:

  1. Multi-step Prediction: The model must predict the next S observations, forcing the bottleneck to retain information relevant for long-term dynamics.
  2. Teacher-Student Training: A student network predicts the quantized representations of a teacher network (an exponential moving average of the student), stabilizing the latent space.

Once trained, the active bottleneck indices are treated as nodes in an action-augmented transition graph. By counting transitions between these indices during random walks, we can extract a "cognitive map." At test time, the system identifies its current and target nodes on this map and uses a classic graph solver (e.g., Dijkstra’s algorithm) to find the shortest path instantly.

Experimental Results

We evaluated TDB across several challenging domains, including 2D aliased grids, non-Euclidean "Aliased Cubes," and visually rich 3D simulated environments.

Planning Efficiency

In 2D aliased rooms, vanilla transformers and LSTMs often failed to find valid paths or produced paths significantly longer than the optimum. In contrast, TDB consistently identified the optimal shortest path, achieving a RatioSP (Ratio of Shortest Path) of 1.0.

TDB finds the optimal shortest path (red dots) compared to the inefficient paths found by standard sequence models (pink arrows) in an aliased grid environment.

Emergent In-Context Learning

A striking finding is that TDB develops the ability to build maps of entirely new environments "in-context." After just a few observations in a novel room, the model can extract a functional map without further weight updates. This suggests that the discrete bottleneck acts as a robust state-discovery mechanism.

Conclusion

TDB bridges the gap between next-token prediction and spatial planning. By forcing a transformer to discretize its internal representations, we can extract human-readable cognitive maps that allow for exponentially faster and more accurate planning in complex, aliased environments. Future work will focus on scaling this approach to high-dimensional continuous observations and reducing redundancy in multi-bottleneck configurations.

Summary updated

BibTeX
@inproceedings{dedieu2024learning,
  author = {Antoine Dedieu and Wolfgang Lehrach and Guangyao Zhou and Dileep George and Miguel Lazaro-Gredilla},
  title = {{Learning Cognitive Maps from Transformer Representations for Efficient Planning in Partially Observed Environments}},
  booktitle = {International Conference on Machine Learning},
  year = {2024},
  url = {https://openreview.net/forum?id=JUa5XNXuoT},
}
Figure