Skip to main content
QUICK REVIEW

[Paper Review] Recurrent Memory Transformer

Aydar Bulatov, Yuri Kuratov|arXiv (Cornell University)|Jul 14, 2022
Topic ModelingComputer Science25 citations
TL;DR

This paper proposes the Recurrent Memory Transformer (RMT), a memory-augmented, segment-level recurrent Transformer that enhances long-sequence modeling by injecting dedicated memory tokens into the input and enabling recurrence across segments. RMT outperforms Transformer-XL on long-context tasks like copy, reverse, and associative retrieval, while achieving comparable language modeling performance with up to 10× smaller memory size, demonstrating superior memory efficiency and long-term dependency learning without architectural changes to the Transformer.

ABSTRACT

Transformer-based models show their effectiveness across multiple domains and tasks. The self-attention allows to combine information from all sequence elements into context-aware representations. However, global and local information has to be stored mostly in the same element-wise representations. Moreover, the length of an input sequence is limited by quadratic computational complexity of self-attention. In this work, we propose and study a memory-augmented segment-level recurrent Transformer (RMT). Memory allows to store and process local and global information as well as to pass information between segments of the long sequence with the help of recurrence. We implement a memory mechanism with no changes to Transformer model by adding special memory tokens to the input or output sequence. Then the model is trained to control both memory operations and sequence representations processing. Results of experiments show that RMT performs on par with the Transformer-XL on language modeling for smaller memory sizes and outperforms it for tasks that require longer sequence processing. We show that adding memory tokens to Tr-XL is able to improve its performance. This makes Recurrent Memory Transformer a promising architecture for applications that require learning of long-term dependencies and general purpose in memory processing, such as algorithmic tasks and reasoning.

Motivation & Objective

  • To address the limitations of standard Transformers in handling long sequences due to quadratic self-attention complexity and blurred global information representation.
  • To improve the modeling of long-term dependencies and global context in sequence processing tasks without modifying the Transformer architecture.
  • To explore the effectiveness of dedicated memory tokens and segment-level recurrence in enhancing memory efficiency and performance on long-context tasks.
  • To evaluate whether memory-augmented Transformers can outperform or match state-of-the-art models like Transformer-XL in both algorithmic reasoning and language modeling.
  • To analyze how attention mechanisms in RMT learn to use memory, particularly through interpretable read/write patterns.

Proposed method

  • RMT augments the input sequence with special memory tokens that serve as dedicated storage for global and local information, decoupling it from input token representations.
  • The model processes sequences in segments, with hidden states from the previous segment's memory passed to the current segment, enabling recurrence and long-context modeling.
  • Memory operations—read, write, and rewrite—are learned end-to-end via attention mechanisms, with gradients flowing back through memory states during training.
  • The method requires no architectural changes to the Transformer; modifications are applied only at input and output sequence levels.
  • RMT is trained to control both memory operations and sequence representation processing, enabling compact, context-aware representations.
  • The approach is compatible with existing models: RMT can be combined with Transformer-XL’s cache to further improve performance.

Experimental results

Research questions

  • RQ1Can a memory-augmented, recurrent Transformer architecture improve long-sequence modeling beyond standard Transformers and Transformer-XL?
  • RQ2Does the use of dedicated memory tokens reduce information mixing between input tokens and global context, leading to better performance on algorithmic tasks?
  • RQ3To what extent can RMT achieve comparable language modeling performance to Transformer-XL with significantly reduced memory size?
  • RQ4How do attention patterns in RMT differ from those in Transformer-XL, particularly in memory access and information flow?
  • RQ5Can RMT be effectively combined with existing caching mechanisms like those in Transformer-XL to further enhance performance?

Key findings

  • RMT outperforms Transformer-XL on long-context algorithmic tasks such as copy, reverse, and associative retrieval when sequence length exceeds a threshold, especially with more than 2 segments.
  • For language modeling, RMT achieves performance on par with Transformer-XL but requires up to 10× less memory size, demonstrating superior memory efficiency.
  • Visualizations of attention maps show that RMT learns to compress entire segments into memory tokens, avoiding the mixing of representations seen in Transformer-XL.
  • In tasks with 4 segments, Transformer-XL with memory size 6 achieves only 0.8 mean accuracy on the reverse task due to representation mixing, while RMT achieves 1.0 accuracy by isolating memory storage.
  • RMT’s ability to rewrite from read memory to write memory enables longer retention of recent segment information, improving performance on multi-segment sequences.
  • Combining RMT with Transformer-XL’s cache leads to improved performance on language modeling, indicating complementary strengths between the two approaches.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.