Memory Transformer

Mikhail S. Burtsev, Grigory V. SapunovarXiv 2020

Introduction

Standard Transformer architectures face a significant challenge: the "clutter" problem. In a vanilla Transformer, every token's vector representation must simultaneously encode its local semantic meaning and the global context of the entire sequence. This often leads to "blurring," where global features become difficult to isolate because they are distributed across every individual token. Furthermore, the quadratic scaling ($O(N^2)$) of self-attention makes processing long sequences computationally prohibitive.

The Memory Transformer addresses these issues by introducing dedicated [mem] tokens. These tokens act as a specialized workspace for global information, providing a centralized memory that can decouple local processing from global context management.

Architectural Modifications

The researchers proposed three distinct ways to integrate memory into the Transformer architecture:

  1. MemTransformer: This baseline version prepends $m$ learnable [mem] tokens to the input sequence. These tokens are treated identically to standard tokens, allowing for bidirectional attention between memory and sequence.
  2. MemCtrl Transformer: This variant introduces a dedicated sub-network to control memory updates, separating the logic of memory management from the primary sequence processing logic.
  3. MemBottleneck Transformer: In this most radical configuration, sequence tokens are prohibited from attending to one another directly. Instead, they must "write" to and "read" from the memory tokens. This forces the memory to serve as a true bottleneck for all global information exchange.
Architectural variants of the Memory Transformer, including the MemBottleneck approach which restricts sequence-to-sequence attention.

Crucially, the MemBottleneck approach shifts computational complexity from $O(N^2)$ to $O(NM)$, where $N$ is the sequence length and $M$ is the number of memory tokens. This provides a path toward linear scaling for long-context tasks.

Experimental Evaluation

The models were evaluated across three major benchmarks to test translation, language modeling, and general understanding:

  • WMT-14 DE-EN: Machine translation from German to English.
  • WikiText-103: Large-scale language modeling to test long-term dependencies.
  • GLUE Benchmark: A suite of diverse natural language understanding tasks.

Key Results

  • Machine Translation: The MemTransformer (with 20 memory tokens) achieved a 25.58 BLEU score on WMT-14, significantly outperforming the vanilla Transformer baseline of 24.65.
  • Language Modeling: On WikiText-103, a memory-augmented Transformer XL reached a perplexity of 23.95, an improvement over the 24.09 baseline.
  • Efficiency: The MemBottleneck model proved that effective translation is possible even without direct sequence-to-sequence attention, validating the memory tokens' ability to capture and redistribute global context.

Analysis of Memory Dynamics

By visualizing attention maps, the authors identified a "Read-Process-Store" pipeline that emerges naturally during training. Early layers tend to "write" sequence information into memory, middle layers perform memory-to-memory attention to "process" that information, and late layers "read" from memory to generate the final output.

Attention maps demonstrating the model's ability to write to, store, and read from the dedicated memory tokens across different layers.

Further analysis revealed that memory size is a critical factor; increasing the number of memory tokens generally correlates with better performance, as it allows for more nuanced global representations. While the model shows some sensitivity to changes in memory size between training and inference, it demonstrates a degree of flexibility in how it utilizes the available memory slots.

Conclusion and Future Work

The Memory Transformer demonstrates that a dedicated, centralized memory can alleviate the "clutter" of standard self-attention while offering superior scaling properties. While the MemBottleneck model is currently more difficult to train than standard architectures, its ability to manage global information with linear complexity is a significant step forward for long-sequence modeling. Future research may focus on making the memory controller more robust to varying memory sizes and exploring the use of these tokens for complex, multi-hop reasoning tasks.

Summary updated

BibTeX
@misc{burtsev2020memory,
  author = {Mikhail S. Burtsev and Grigory V. Sapunov},
  title = {{Memory Transformer}},
  year = {2020},
  eprint = {2006.11527},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2006.11527},
}
Figure