Adding Recurrence to Pretrained Transformers

Davis Yoshida, Allyson Ettinger, Kevin Gimpel

TL;DR

This paper introduces a novel method to augment pretrained transformer models with a small recurrence module. This allows them to process longer contexts more efficiently, reducing memory requirements during both training and inference, while also improving perplexity on challenging datasets.

What Problem Does This Paper Address?

Large pretrained transformer models, like BERT and GPT-2, have revolutionized NLP. However, they come with significant computational costs, particularly a memory footprint that scales quadratically with the input sequence length. This makes them expensive to train and deploy, especially for tasks requiring long contexts. Furthermore, these models have a fixed, limited context window (e.g., 512 or 1024 tokens), which can lead to suboptimal performance when documents are simply chunked, as tokens at window boundaries lack full contextual information. While some architectural innovations exist to address these issues, they often require training models from scratch, which is computationally prohibitive for many researchers and practitioners. This paper aims to provide a more efficient and flexible way to use existing pretrained models, especially for longer sequences.

Methods

The core idea is to add a "small recurrence module" to pretrained transformer language models. Instead of processing a very long sequence in one go, the input is divided into fixed-size windows (e.g., 100 tokens). The first window is processed by the transformer as usual. For subsequent windows, a fixed-size representation (a "summary") is generated from the hidden states of the previous window. This summary is then fed into a specific layer of the transformer as an additional embedding (used as a key and value, not a query, to maintain a fixed number of embeddings). This "recurrent" connection allows information from previous windows to influence the processing of the current window, effectively extending the context.

This approach offers a trade-off between computation and perplexity. Shrinking the window size reduces memory footprint, and the recurrence helps mitigate the performance drop typically associated with smaller windows. The entire model is trained end-to-end using backpropagation through time. The authors also note that this method can be combined with gradient checkpointing for further memory savings during training.

Datasets

The paper evaluates their method on two standard NLP datasets:

  • WikiText-103: A large corpus for word-level language modeling, comprising about 103 million words from English Wikipedia.
  • PG-19: A dataset consisting of books from the Project Gutenberg corpus, used to test performance on much longer contexts (average book length of 69K words). A subset of 1250 books was used for training due to computational constraints.

Key Insights and Ideas

  • Bridging the gap between research and practice: The paper highlights a mismatch between how language models are typically evaluated (requiring full context for every prediction, leading to high computational cost) and how they are used in applications (often with shorter contexts or in generative settings where full context is not always feasible). Their method aims to improve performance in more practical, shorter-context scenarios.
  • Recurrence as a lightweight context extender: The addition of a small recurrence module, rather than a complete architectural overhaul, is a key insight. This makes the method applicable to a wide range of existing pretrained models without requiring them to be retrained from scratch.
  • Controllable trade-off: The method allows for a controllable trade-off between computational cost (via window size) and performance (perplexity). Smaller windows mean less computation but potentially lower perplexity, which the recurrence module helps to mitigate.
  • Overlapping windows and training: A crucial detail is that the overlap used during testing must also be used during training for the recurrent models. This is because the recurrent embedding is trained to represent information up to a certain point in the previous window, and changing the overlap at test time would break this learned alignment.

Key Results

  • Improved Perplexity: On both WikiText-103 and PG-19, the recurrent models achieved better perplexity than unmodified GPT-2 models when evaluated with the same window size and overlap. For instance, on PG-19, the recurrent model with a 5-token overlap achieved a perplexity lower than the baseline with a 50 or even 75-token overlap.
  • Efficiency Gains: The method allows for applying models to longer contexts with significantly less computational cost. For example, using a 50-token overlap with their recurrent model was less than half as costly as using a non-recurrent model with a 200-token overlap.
  • Window Size Robustness: The recurrent models showed better performance retention as window sizes decreased compared to the baseline models, demonstrating the benefit of the extended context.
  • Qualitative Analysis: Sample continuations from PG-19 showed that the recurrent module could pass high-level topical information and maintain correct pronoun usage across windows, though some discontinuities were observed, suggesting limitations in the recurrence module's capacity.

Limitations and Future Work

  • Recurrence Module Capacity: The authors acknowledge that the recurrence module acts as a bottleneck and might not convey all fine-grained information. They suggest that increasing the capacity of this module could further improve performance.
  • Applicability to Other Models: While the method is demonstrated on GPT-2, its applicability to other transformer architectures, particularly BERT-family models for tasks beyond language modeling, is a promising avenue for future work.
  • Longer Contexts: The paper suggests exploring mechanisms that can pass more fine-grained information forward between windows, potentially enabling even more effective handling of very long contexts.

Summary updated

BibTeX
@misc{yoshida2020adding,
  author = {Davis Yoshida and Allyson Ettinger and Kevin Gimpel},
  title = {{Adding Recurrence to Pretrained Transformers}},
  year = {2020},
  eprint = {2008.07027},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2008.07027},
}
Figure