Meta-Learning Fast Weight Language Models

Kevin Clark, Kelvin Guu, Ming-Wei Chang, Panupong Pasupat, Geoffrey E. Hinton, Mohammad Norouzi

Introduction

Standard Transformer language models (LMs) are typically static after training; their weights remain frozen during inference. While attention mechanisms allow these models to reference previous tokens, they cannot adapt their internal parameters to the specific patterns of a new document. Researchers at Google have introduced Fast Weight Layers (FWLs), a novel neural component that enables on-the-fly parameter adaptation. By mathematically reframing gradient-based updates as a form of linear attention, FWLs provide the performance boost of "dynamic evaluation" with significantly lower computational overhead.

The Limitations of Dynamic Evaluation

Dynamic evaluation is a technique that updates a model's weights at test-time based on the tokens it has just processed. Although it effectively lowers perplexity, it is rarely used in production due to three major issues:

  1. Inference Speed: It requires additional forward and backward passes, making inference roughly 3x slower.
  2. Lack of Parallelization: Updates are sequential, preventing the model from processing text chunks in parallel.
  3. Training Gap: Because of its computational cost, dynamic evaluation is usually omitted during training, preventing the model from learning how to best utilize rapid weight changes.

Fast Weight Layers (FWLs)

The authors propose adding FWLs on top of standard Transformer stacks. This architecture maintains two distinct sets of weights:

  • Slow Weights ($\theta$): Standard parameters learned during training that remain fixed at test-time.
  • Fast Weights ($\theta'$): Parameters that change dynamically based on the loss gradients of previous tokens.
Comparison of traditional Dynamic Evaluation (left) and the proposed Fast Weight Layer architecture (right).

The "secret sauce" of this approach is the observation that a gradient update for a weight matrix is a rank-one matrix. Leveraging this property, the authors demonstrate that applying a fast-weight update is mathematically equivalent to linear attention (attention without a softmax). This allows the model to compute updates in parallel using prefix sums (cumsums) and to "meta-learn" during the primary training phase. The model essentially learns to produce gradients that are most beneficial for its own future predictions, similar to Model-Agnostic Meta-Learning (MAML).

Experimental Results

The approach was evaluated on the WikiText-103 benchmark using Sparse Transformer and Transformer-XL base architectures.

Performance and Efficiency

  • Perplexity Gains: Adding FWLs to Transformer-XL improved perplexity from 18.1 to 16.6, a result comparable to full dynamic evaluation.
  • Speed: FWLs are approximately 3x faster than traditional dynamic evaluation. While dynamic evaluation reduces inference speed to 510 tokens/sec, FWLs maintain a rate of 1340 tokens/sec (compared to the baseline's 1575).
  • Adaptation Strengths: The model showed the most significant improvements on long documents and rare or repeated tokens, effectively using the fast weights as a high-capacity memory to adapt to specific document contexts.

Conclusion

Fast Weight Layers bridge the gap between static Transformers and slow test-time optimization. By treating gradients as a memory storage mechanism and utilizing the efficiency of linear attention, FWLs enable models to adapt to new information in real-time. This work opens new avenues for efficient, document-aware language modeling and meta-learning in large-scale architectures.

Summary updated

BibTeX
@inproceedings{clark2022meta,
  author = {Kevin Clark and Kelvin Guu and Ming-Wei Chang and Panupong Pasupat and Geoffrey E. Hinton and Mohammad Norouzi},
  title = {{Meta-Learning Fast Weight Language Models}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2022},
  url = {https://openreview.net/forum?id=Kzow-RdHSM},
}
Figure