Short-term memory in neural language models

Kristijan Armeni, Christopher Honey, Tal LinzenICLR 2022

TL;DR

This paper investigates how well neural language models can remember specific words and their order from past text. They found that transformer models excel at this, acting like a high-resolution working memory, while LSTMs only retain a general "gist" of the past, especially for earlier words. This has implications for understanding how LMs learn and their potential for complex cognitive tasks.

What Problem Does This Paper Address?

Language models (LMs) are trained to predict the next word in a sequence, which requires them to understand and remember context from earlier parts of the text. While we know LMs can capture complex linguistic dependencies (like subject-verb agreement across many words), it's unclear how they store this information. Do they remember individual words verbatim, or do they just form a general semantic understanding (a "gist")? This paper aims to characterize the nature of this "short-term memory" in LMs, specifically whether they can retrieve exact words and their order from past context, and how this ability is affected by factors like intervening text and training data.

Methods

The researchers devised a novel paradigm to test verbatim memory retrieval. They presented LMs with text containing a list of nouns that appeared twice. The key idea was to measure the reduction in surprisal (a measure of how unexpected a word is) for the second instance of the noun list compared to the first. A larger reduction in surprisal indicates better retrieval. They manipulated several factors:

  • Set Size: The number of nouns in the list (3, 5, 7, or 10).
  • Second List Structure: Whether the second list was an exact repeat of the first, a permutation of the first, or a list of entirely new nouns.
  • Intervening Text: The length and content of the text between the first and second noun lists (ranging from short to long, and intact, scrambled, or semantically incongruent).

They applied this paradigm to two prominent LM architectures: attention-based transformers (like GPT-2) and Long Short-Term Memory (LSTM) networks.

Datasets

  • Training: The models were trained on the Wikitext-103 corpus. One transformer model was also evaluated that was pretrained on WebText.
  • Evaluation: The experiment used custom-generated vignettes containing lists of nouns. These lists were either arbitrary (randomly sampled nouns) or semantically coherent (nouns from the same category, e.g., birds). The paper provides detailed lists of these nouns in Tables 1 and 2.

Key Insights and Ideas

  • Transformers as High-Resolution Memory: Transformers demonstrated a remarkable ability to retrieve not just the identity of nouns but also their original order, even across significant intervening text. This suggests they learn a detailed, token-level memory.
  • LSTM as a "Gist" Retriever: LSTMs showed much weaker retrieval, primarily retaining a semantic "gist" of the list, and were more sensitive to the order of words and the semantic coherence of the list. Their memory also decayed rapidly with intervening text.
  • Learning is Crucial: A randomly initialized transformer model showed no ability to retrieve words, highlighting that this memory capability is learned through training, not an inherent architectural feature.
  • Attention is Key: Shuffling the attention weights in a transformer significantly degraded its verbatim retrieval ability, underscoring the role of learned attention mechanisms in accessing specific past tokens.
  • Larger Models, Better Memory: Transformer retrieval improved with increased model depth and training data size, suggesting that scale plays a significant role in developing robust short-term memory.

Key Results

  • Transformer Retrieval: For transformers, repeat surprisal (surprisal on the second list relative to the first) was very low (e.g., 2-5% for GPT-2 with repeated lists), indicating strong verbatim recall. This was relatively robust to set size and intervening text length (up to 435 tokens).
  • LSTM Retrieval: LSTMs showed much higher repeat surprisal (e.g., around 90-95% for arbitrary lists with short intervening text), indicating poor verbatim recall. Their retrieval was limited to list-initial tokens and short intervening texts (around 26 tokens).
  • Order Matters for Transformers: When the second list was a permutation of the first, transformer surprisal increased, showing they remembered the original order. LSTMs did not show this sensitivity to order.
  • Semantic Coherence: While transformers performed well with both arbitrary and coherent lists, LSTMs showed some improvement in retrieval when lists were semantically coherent, especially with short intervening text.
  • Intervening Text Impact: For transformers, even scrambled intervening text didn't completely break retrieval, though it slightly impacted order recall. For LSTMs, longer intervening text severely degraded retrieval.

Limitations and Future Work

  • Autoregressive Models: The study focused on autoregressive (left-to-right) LMs. Future work could explore other architectures like BERT or T5.
  • Attention Ablation: The attention mechanism was ablated uniformly across layers. Future studies could investigate specific attention heads.
  • Generalization: While the study demonstrates verbatim retrieval, it's unclear how this translates to broader in-context learning capabilities or other complex tasks.
  • Potential for Repetitiveness: The paper notes that a highly resilient verbatim memory system could lead to overly repetitive text generation, a known issue in some LMs.
  • LSTM Bottleneck: The LSTM's limited memory might be a bottleneck for complex tasks, but this "gist-like" memory could be more efficient when memory capacity is constrained.

Summary updated

BibTeX
@inproceedings{armeni2022short,
  author = {Kristijan Armeni and Christopher Honey and Tal Linzen},
  title = {{Short-term memory in neural language models}},
  booktitle = {International Conference on Learning Representations},
  year = {2022},
  url = {https://openreview.net/forum?id=QNW1OrjynpT},
}
Figure