NOT ALL MEMORIES ARE CREATED EQUAL: LEARNING TO EXPIRE

Abstract

Attention mechanisms have shown promising results in sequence modeling tasks that require long-term memory. Recent work has investigated mechanisms to reduce the computational cost of preserving and storing the memories (Rae et al., 2020). However, not all content in the past is equally important to remember. We propose Expire-Span, a method that learns to retain the most important information and expire the irrelevant information. This enables Transformers to scale to attend to tens of thousands of previous timesteps efficiently, as not all hidden states from previous timesteps are preserved. We demonstrate that Expire-Span can help models identify and retain critical information and show it can achieve state of the art results on long-context language modeling, reinforcement learning, and algorithmic tasks. Finally, we show that Expire-Span can scale to memories that are tens of thousands in size, which is helpful on incredibly long context tasks such as character-level PG-19 and a frame-by-frame moving objects task.

1. INTRODUCTION

Transformer architectures (Vaswani et al., 2017) have demonstrated strong performance across a variety of tasks (Devlin et al., 2019; Roller et al., 2020; Brown et al., 2020) , including those that require learning long term relationships (Zhang et al., 2018; Fan et al., 2019a; Izacard & Grave, 2020) . Recent work has focused on scaling attention mechanisms efficiently to longer memory sizes, enabling large improvements on long context tasks (Dai et al., 2019; Sukhbaatar et al., 2019a) . However, a critical component of human memory is not just the ability to remember, but also forgetting irrelevant information to focus on the salient, relevant bits. Most studies of long-term memory in humans indicate that not everything is remembered (Murre & Dros, 2015) -instead, only vivid, remarkable memories are retained from the far past (Wixted, 2004) . Standard Transformer architectures lack the ability to search over extremely large memories, as the self-attention mechanism is computationally intensive and the storage cost of preserving the large memory grows quickly. Recent work (Child et al., 2019; Rae et al., 2020) has proposed learning how to extend to greater context through sparse mechanisms or through compression, to more compactly represent the past. However, there exists a fundamental problem with large memories beyond strict computational concerns: as the amount of information stored increases, deciding which information is relevant becomes more challenging. Other work (Lample et al., 2019) approaches this by considering how to efficiently search large memories. We will focus on learning what to forget, and thereby reducing the computational burden of the model easing the challenges of the search problem. We propose EXPIRE-SPAN, a straightforward extension to attention mechanisms, that learns when to expire unneeded memories. By expiring memories that are no longer useful, EXPIRE-SPAN enables scaling to memories tens of thousands of timesteps long. This learnable mechanism allows the model to adjust the span size as needed, selecting which information is critical to retain and forgetting the rest. More concretely, we augment the self-attention with a simple predictor that outputs an expiration value for each hidden state that determines how long a memory should be retained and accessible to the model. After the EXPIRE-SPAN runs out, the memory will be forgotten, but in a gradually differentiable way to retain end-to-end training with backpropagation. This process is done independently for each layer, allowing different layers to specialize in different time-scales. We demonstrate that EXPIRE-SPAN can distinguish between critical and irrelevant information on several illustrative tasks in natural language processing and reinforcement learning. We then show For every memory h i , we compute an EXPIRE-SPAN e i that determines how long it should stay in memory. Here, memories h 2 , h 5 are already expired at time t, so the query q t can only access {h 1 , h 3 , h 4 } in self-attention. on long-context language modeling benchmarks and a frame-by-frame colliding objects task that EXPIRE-SPAN can scale to memories in the tens of thousands -by expiring irrelevant information, capacity is freed to have even larger memory. Finally, we analyze the information retained and expired by EXPIRE-SPAN models, to understand the importance of long context memory.

2. RELATED WORK

Memory is crucial for many tasks and has been studied in recurrent networks (Elman, 1990; Hochreiter & Schmidhuber, 1997; Mikolov et al., 2010) for a long time. The development of memory augmented networks (Graves et al., 2014; Sukhbaatar et al., 2015b) made it possible to store large quantities of information and selectively access them using attention (Bahdanau et al., 2015) . The Transformer (Vaswani et al., 2017) took full advantage of this approach. Processing long sequences with Transformers is an active area with applications in language understanding (Brown et al., 2020 ), reinforcement learning (Parisotto et al., 2019 ), video processing (Wu et al., 2019) , and protein folding (Rives et al., 2019) . However, extending the memory span is computationally expensive due to the quadratic time and space complexity of self-attention. Various work has focused on reducing this complexity and increasing memory capacity. Dynamic attention spans, such as Adaptive-Span (Sukhbaatar et al., 2019a) and Adaptively Sparse Transformer (Correia et al., 2019) , focus on learning which heads can have shorter spans of attention, but can only extend to spans of a few thousand. Other work sparsifies attention by computing fewer tokens (Fan et al., 2019c) , often by using fixed attention masks (Child et al., 2019) or sliding windows and dilation (Beltagy et al., 2020) . The BP Transformer (Ye et al., 2019) structures tokens as a binary tree, so some tokens have coarse attention. These works focus on learning what to attend to, but searching larger and larger memories is very difficult. In contrast, we focus on learning to expire what is irrelevant. Compressive Transformer (Rae et al., 2020) reduces the number of memories by replacing every few memories with a single compressed one. A disadvantage of this is that all memories have the same compression ratio, so relevant memories are equally compressed. Another line of work investigates linear-time attention mechanisms. Wu et al. ( 2018) replace selfattention with convolutions that run in linear time, but the scalability to long context tasks remains limited. Wang et al. (2020) propose linear time attention by decomposing attention into multiple smaller attentions, that recombine to form a low-rank factorization of the original attention. Those methods, however, focus on making attention more efficient without actually reducing the number of memories. Further, as our goal is to reduce the number of memories that feed to self-attention by learning to expire, EXPIRE-SPAN can be easily combined with these efficiency improvements. For a review of further recent Transformer variants, see Tay et al. (2020) .

3. BACKGROUND

Transformer architectures have been widely used as decoder-only auto-regressive models for sequential tasks. Each Transformer decoder is made of a stack of identical layers, composed of a multi-head self-attention sublayer followed by a feedforward sublayer. The output of each timestep



Figure1: EXPIRE-SPAN. For every memory h i , we compute an EXPIRE-SPAN e i that determines how long it should stay in memory. Here, memories h 2 , h 5 are already expired at time t, so the query q t can only access {h 1 , h 3 , h 4 } in self-attention.

