Not All Memories are Created Equal: Learning to Forget by Expiring

Sainbayar Sukhbaatar, Da Ju, Spencer Poff, Stephen Roller, Arthur Szlam, Jason Weston, Angela Fan

Introduction

Standard Transformers face a fundamental bottleneck when processing extremely long sequences: the self-attention mechanism attempts to retain every past token, leading to quadratic computational and memory costs. This paper introduces Expire-Span, a novel approach that mimics human memory by learning to permanently forget irrelevant information. By assigning expiration dates to hidden states, Expire-Span enables Transformers to process contexts of tens of thousands of tokens more efficiently than existing long-context models.

The Challenge of Long-Context Attention

The $O(T^2)$ scaling of standard self-attention makes processing long documents or high-resolution video computationally prohibitive. While previous research has explored sparse attention or memory compression (e.g., Compressive Transformers), these methods often treat all historical data with equal importance. In contrast, human cognition prioritizes salient information and discards mundane details. Expire-Span addresses this by teaching the model to identify and delete useless information, freeing up capacity for much longer temporal horizons.

The Expire-Span Mechanism

The core of the proposed method is an operation added to the Transformer's self-attention layers that determines the lifespan of each memory.

The Expire-Span mechanism predicts an expiration date for each hidden state, determining its lifespan in the attention cache.
  1. Expire-Span Predictor: For every hidden state $h_i$ at timestep $i$, a linear layer predicts a scalar $e_i$. This value defines how many future timesteps the memory remains accessible.
  2. Differentiable Forgetting: To allow end-to-end training, the authors use a soft masking function. This function smoothly reduces a memory's attention weight to zero as it nears its expiration, at which point it is purged from the cache.
  3. L1 Regularization: An L1 penalty is applied to the predicted spans, incentivizing the model to minimize its memory footprint and retain only essential data.
  4. Structured Dropout: To prevent overfitting to specific sequence lengths, the memory span is randomly truncated during training, forcing the model to develop robust retrieval strategies.

Experimental Evaluation

The authors tested Expire-Span across several demanding benchmarks:

  • Reinforcement Learning: Gridworld and text-adventure tasks requiring agents to remember specific instructions across thousands of distractor steps.
  • Algorithmic Tasks: A Copy Task requiring spans up to 128k tokens.
  • Language Modeling: Character-level (Enwik8) and word-level (Wikitext-103, PG-19) benchmarks.
  • Object Collision: A video task requiring the model to recall specific collision events from thousands of frames prior.

Key Results and Insights

Expire-Span demonstrates that "forgetting improves searching." By aggressively expiring irrelevant tokens, the model reduces the search space for the attention mechanism, making it easier to locate critical information.

Performance comparison across various tasks showing Expire-Span achieving higher accuracy/return with significantly smaller memory footprints compared to Transformer-XL.
  • State-of-the-Art Performance: On Enwik8, a 24-layer model achieved a new SOTA of 0.95 bits-per-byte (bpb), surpassing the Compressive Transformer (0.97 bpb) with fewer parameters.
  • Context Scaling: In the Object Collision task, Expire-Span successfully managed a 64k attention span with a 26.7% error rate, significantly outperforming the Compressive Transformer's 63.8% error rate at an 8k span.
  • Efficiency Gains: On Enwik8, Expire-Span reduced GPU memory usage from 27 GB (Transformer-XL) to 15 GB and improved processing speed from 649 ms/batch to 408 ms/batch.
  • Layer Specialization: Analysis shows that lower layers tend to preserve structural tokens (newlines, spaces), while higher layers retain rare words and named entities, quickly discarding generic vocabulary.

Conclusion and Future Work

Expire-Span proves that selective forgetting is a viable and efficient strategy for scaling Transformers to massive contexts. While the authors noted some training instabilities and overfitting risks—mitigated by block-parallel loss computation and structured dropout—the results suggest a path forward for models that must parse days or weeks of continuous, noisy data. Future work may extend these principles to even more complex, human-like reasoning tasks where information expiration is a necessity rather than an option.

Summary updated

BibTeX
@inproceedings{sukhbaatar2021not,
  author = {Sainbayar Sukhbaatar and Da Ju and Spencer Poff and Stephen Roller and Arthur Szlam and Jason Weston and Angela Fan},
  title = {{Not All Memories are Created Equal: Learning to Forget by Expiring}},
  booktitle = {International Conference on Machine Learning},
  year = {2021},
}
Figure