Augmenting Language Models with Long-Term Memory

Weizhi Wang, Li Dong, Hao Cheng, Xiaodong Liu, Xifeng Yan, Jianfeng Gao, Furu Wei

Standard Large Language Models (LLMs) are inherently "short-sighted." Due to the quadratic computational cost of self-attention, they can only process a fixed window of text—typically 2k to 4k tokens. When fed a long book or a complex technical manual, they effectively "forget" the beginning by the time they reach the end.

Previous attempts to solve this limitation, such as the Memorizing Transformer, utilized a memory bank to store past activations. However, these architectures faced a major hurdle known as memory staleness. As a model is trained and its weights update, the older representations stored in its memory become stale. The newly updated model no longer aligns with the representations it cached earlier, making the retrieved information less useful or even detrimental.

To address this, researchers have introduced LONGMEM (Language Models Augmented with Long-Term Memory), a novel framework that allows LLMs to overcome fixed input length limits by utilizing a massive, external memory bank without suffering from memory staleness.

Methods: The Decoupled Architecture

The core innovation of LONGMEM is its decoupled network architecture, which separates the memory encoding process from the retrieval and reading process.

LONGMEM Architecture

The system consists of two primary components:

  1. Frozen Backbone LLM: The original LLM acts as a dedicated memory encoder. Because its weights are completely frozen during the memory-augmentation phase, the representations it stores in the Cached Memory Bank remain consistent and valid indefinitely. This entirely eliminates the memory staleness problem.
  2. Residual SideNet: This is a lightweight, trainable Transformer that runs alongside the frozen backbone, acting as the "retriever" and "reader." It takes the current input's hidden states from the backbone and uses a Memory-Augmented Layer (MemAug) to fuse them with relevant keys and values retrieved from the memory bank.

To ensure the SideNet learns effectively from the massive backbone, the architecture employs cross-network residual connections. Instead of passing raw data, the SideNet receives the differences between layers of the backbone. This allows the SideNet—which is roughly one-third the size of the backbone—to tap into the pretrained knowledge efficiently.

Furthermore, LONGMEM utilizes Token-to-Chunk Retrieval. Instead of searching for every single token (which is computationally expensive), the model retrieves chunks of contiguous tokens. This preserves local semantic integrity and significantly speeds up the retrieval process.

Datasets and Evaluation

The researchers evaluated LONGMEM across several demanding scenarios to test its long-context capabilities:

  • The Pile: A massive dataset including books, Wikipedia, and Stack Exchange used for training.
  • PG-22: A newly curated dataset of books published between 2020 and 2022, ensuring the model wasn't just recalling books seen in its original pre-training.
  • ChapterBreak: A challenging benchmark where a model must identify the correct beginning of a chapter given a very long preceding context.
  • NLU Tasks: Standard benchmarks (SST-2, MPQA, SQuAD) were used to test Memory-Augmented In-Context Learning (ICL).

Key Insights and Results

By freezing the backbone, the authors successfully turned a constraint (the computational cost of training) into a feature that solves memory staleness. This allows LONGMEM to load 2,000+ examples into its memory bank, enabling "many-shot" learning that significantly boosts accuracy on downstream tasks compared to the standard "few-shot" limits of traditional LLMs.

Surprisingly, LONGMEM is also more efficient than simply scaling up a standard Transformer's context window. It achieves faster inference and uses less GPU memory than a dense model attempting to handle an 8k context window.

ChapterBreak Benchmark Results

Empirical results highlight LONGMEM's strong performance:

  • ChapterBreak: LONGMEM achieved a state-of-the-art 40.5% accuracy on the most difficult 8k-context split, significantly outperforming GPT-3 (28%) and specialized models like BigBird.
  • Language Modeling: LONGMEM reduced perplexity by 1.38~1.62 points over different lengths of the Gutenberg corpus compared to standard LLMs.
  • In-Context Learning: In 20-shot scenarios, LONGMEM provided a +5.6 average score increase across NLU tasks compared to the baseline GPT-2.
  • Scaling: The model successfully utilized a memory bank of 65k tokens, demonstrating its ability to effectively read and remember long-form documents.

Limitations and Future Work

While LONGMEM represents a major step forward for long-context language modeling, the authors note a few areas for future refinement. Although chunk-based retrieval is fast, it still adds a small latency overhead (approximately 15ms per 1k tokens) compared to a standard model. Additionally, while the architecture is theoretically capable of unlimited memory, practical experiments capped the memory at 65k tokens; the limits of retrieval accuracy at the scale of millions of tokens remain to be tested. Future work will also explore how LONGMEM handles complex reasoning tasks that require jumping back and forth between many different parts of a massive document, such as long-horizon planning.

Summary updated

BibTeX
@inproceedings{wang2023augmenting,
  author = {Weizhi Wang and Li Dong and Hao Cheng and Xiaodong Liu and Xifeng Yan and Jianfeng Gao and Furu Wei},
  title = {{Augmenting Language Models with Long-Term Memory}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2023},
  url = {https://openreview.net/forum?id=BryMFPQ4L6},
}
Figure