Adaptive Semiparametric Language Models

Dani Yogatama, Cyprien de Masson d'Autume, Lingpeng Kong

Introduction: The Parametric Bottleneck

Modern language models, such as the GPT series, are primarily "parametric," meaning they store all their knowledge—from grammatical rules to obscure historical facts—within their neural weights. While powerful, this approach faces two significant challenges: a fixed context window that limits long-range dependencies and an inherent inflexibility that makes updating knowledge difficult without full retraining. Furthermore, these models apply the same computational effort to predict common functional words (e.g., "the") as they do for rare entities (e.g., "Elizabeth Warren").

Previous research introduced $k$NN-LMs to augment models with external memory, but these typically used a fixed interpolation factor to mix parametric and non-parametric predictions. Adaptive Semiparametric Language Models (SPALM) address this by introducing a learned gating mechanism that decides, on a per-token basis, whether to rely on internal logic or external retrieval.

The SPALM Architecture

SPALM treats language modeling as a modular process, drawing inspiration from human memory systems. It consists of three primary components:

  1. Short-Term Memory: Utilizing a Transformer-XL backbone, the model caches hidden states from the immediate past to maintain local coherence.
  2. Long-Term Memory: A non-parametric episodic memory module implemented as a massive key-value database. "Keys" are vector representations of text snippets from the training corpus, and "values" are the subsequent tokens.
  3. Adaptive Gating: The core innovation of SPALM. A context-dependent gate ($g_t$) calculates a weight at every timestep, determining the optimal mixture of the Transformer’s internal representation and the information retrieved from long-term memory.
The SPALM architecture integrates a Transformer with a key-value long-term memory via an adaptive gating mechanism.

To ensure scalability, SPALM employs Scalable Nearest Neighbors (ScANN) for efficient maximum inner product search across millions of memory entries.

Adaptive Gating and Modular Intelligence

A key insight from this research is that the model naturally learns to "open" the gate for rare entities and specific factual information while keeping it "closed" for common syntax. For instance, in predicting a name like "Elizabeth Warren," the model might rely on its internal weights for the first name but switch to long-term memory to retrieve the surname with high confidence once the context is established.

By separating computation (the Transformer) from storage (the $k$NN database), SPALM achieves a form of modular intelligence. The Transformer is freed from the burden of memorizing every fact, allowing it to focus on modeling language structure and logic.

Experimental Results

The model was evaluated on WikiText-103, WMT-2019, and enwik8. SPALM consistently outperformed strong baselines, including standard Transformer-XL and fixed-interpolation $k$NN-LM models.

Performance comparison on WikiText-103. SPALM achieves superior perplexity, particularly when ensembled with kNN and using larger memory sizes (M).

On the WMT-2019 dataset, SPALM reached a perplexity of 14.0, a significant improvement over Transformer-XL's 15.5. In character-level modeling (enwik8), it achieved 1.00 Bits Per Character (BPC), surpassing specialized long-context models like the Longformer. These results suggest that the benefits of SPALM scale effectively with the size of the available memory bank.

Conclusion and Future Directions

SPALM demonstrates that adaptive retrieval is a powerful tool for enhancing language model performance and efficiency. However, challenges remain regarding retrieval latency during inference and the static nature of the current memory database. Future work may explore end-to-end training of the key-generator and the development of dynamic memory systems that can grow as the model encounters new information.

Summary updated

BibTeX
@article{yogatama2021adaptive,
  author = {Dani Yogatama and Cyprien de Masson d'Autume and Lingpeng Kong},
  title = {{Adaptive Semiparametric Language Models}},
  journal = {Trans. Assoc. Comput. Linguistics},
  year = {2021},
  doi = {10.1162/tacl\_a\_00371},
}
Figure