Title: COMPRESSIVE TRANSFORMERS FOR LONG-RANGE SEQUENCE MODELLING

Abstract: We present the Compressive Transformer, an attentive sequence model which compresses past memories for long-range sequence learning. We find the Compressive Transformer obtains state-of-the-art language modelling results in the WikiText-103 and Enwik8 benchmarks, achieving 17.1 ppl and 0.97 bpc respectively. We also find it can model high-frequency speech effectively and can be used as a memory mechanism for RL, demonstrated on an object matching task. To promote the domain of long-range sequence learning, we propose a new openvocabulary language modelling benchmark derived from books, PG-19.

1. INTRODUCTION:

Humans have a remarkable ability to remember information over long time horizons. When reading a book, we build up a compressed representation of the past narrative, such as the characters and events that have built up the story so far. We can do this even if they are separated by thousands of words from the current text, or long stretches of time between readings. During daily life, we make use of memories at varying time-scales: from locating the car keys, placed in the morning, to recalling the name of an old friend from decades ago. These feats of memorisation are not achieved by storing every sensory glimpse throughout one's lifetime, but via lossy compression. We aggressively select, filter, or integrate input stimuli based on factors of surprise, perceived danger, or repetition -amongst other signals (Richards and Frankland, 2017) .

Memory systems in artificial neural networks began with very compact representations of the past. Recurrent neural networks (RNNs, Rumelhart et al. (1986) ) learn to represent the history of observations in a compressed state vector. The state is compressed because it uses far less space than the history of observations -the model only preserving information that is pertinent to the optimization of the loss. The LSTM (Hochreiter and Schmidhuber, 1997) is perhaps the most ubiquitous RNN variant; it uses learned gates on its state vector to determine what information is stored or forgotten from memory.

However since the LSTM, there has been great benefit discovered in not bottlenecking all historical information in the state, but instead in keeping past activations around in an external memory and attending to them. The Transformer (Vaswani et al., 2017 ) is a sequence model which stores the hidden activation of every time-step, and integrates this information using an attention operator (Bahdanau et al., 2014) . The Transformer will thus represent the past with a tensor (depth × memory size × dimension) of past observations that is, in practice, an order of magnitude larger than an LSTM's hidden state. With this granular memory, the Transformer has brought about a step-change in state-of-the-art performance, within machine translation (Vaswani et al., 2017) , language modelling (Dai et al., 2019; Shoeybi et al., 2019) , video captioning (Zhou et al., 2018) , and a multitude of language understanding benchmarks (Devlin et al., 2018; Yang et al., 2019) amongst others.

One drawback in storing everything is the computational cost of attending to every time-step and the storage cost of preserving this large memory. Several works have focused on reducing the computational cost of attention with sparse access mechanisms (Rae et al., 2016; Child et al., 2019; Sukhbaatar et al., 2019; Lample et al., 2019) . However sparse attention does not solve the storage problem, and often requires custom sparse kernels for efficient implementation. Instead we look back to the notion of compactly representing the past. We show this can be built with simple dense linear-algebra components, such as convolutions, and can reduce both the space and compute cost of our models.

We propose the Compressive Transformer, a simple extension to the Transformer which maps past hidden activations (memories) to a smaller set of compressed representations (compressed memories). The Compressive Transformer uses the same attention mechanism over its set of memories and compressed memories, learning to query both its short-term granular memory and longer-term coarse memory. We observe this improves the modelling of text, achieving state-of-the-art results in character-based language modelling -0.97 bpc on Enwik8 from the Hutter Prize (Hutter, 2012) -and word-level language modelling -17.1 perplexity on WikiText-103 (Merity et al., 2016) . Specifically, we see the Compressive Transformer improves the modelling of rare words.

We show the Compressive Transformer works not only for language, but can also model the waveform of high-frequency speech with a trend of lower likelihood than the TransformerXL and Wavenet (Oord et al., 2016) when trained over 400,000 steps. We also show the Compressive Transformer can be used as a memory component within an RL agent, IMPALA (Espeholt et al., 2018) , and can successfully compress and make use of past observations. Furthermore we present a new book-level language-modelling benchmark PG-19, extracted from texts in Project Gutenberg1 , to further promote the direction of long-context sequence modelling. This is over double the size of existing LM benchmarks and contains text with much longer contexts.

2. RELATED WORK:

There have been a variety of recent attempts to extend the range of attention, particularly in the Transformer, or to replace the attention operation with something less expensive. Wu et al. (2019) show that a convolution-like operator that runs in linear time can actually exceed the performance of the quadratic-time self-attention layer in the Transformer at sentence-to-sentence translation and sentence-level language modelling. However such a mechanism inhibits the flow of information across a large number of time-steps for a given layer, and has not shown to be beneficial for longrange sequence modelling. Dai et al. (2019) propose the TransformerXL, which keeps past activations around in memory. They also propose a novel relative positional embedding scheme which they see outperforms the Transformer's original absolute positional system. Our model incorporates both of these ideas, the use of a memory to preserve prior activations and their relative positional embedding scheme.

The Sparse Transformer (Child et al., 2019) uses fixed sparse attention masks to attend to roughly √ n locations in memory. This approach still requires keeping all memories around during training, however with careful re-materialization of activations and custom kernels, the authors are able to train the model with a reasonable budget of memory and compute. When run on Enwik8, the much larger attention window of 8, 000 improves model performance, but overall it does not significantly outperform a simpler TransformerXL with a much smaller attention window.

The use of dynamic attention spans is explored in Sukhbaatar et al. (2019) . Different attention heads can learn to have shorter or longer spans of attention -and they observe this achieves state-ofthe-art in character-based language modelling. This idea could easily be combined with our contribution -a compressive memory. However an efficient implementation is not possible on current dense-linear-algebra accelerators, such as Google's TPUs, due to the need for dynamic and sparse computation. Our approach builds on simple dense linear algebra components, such as convolutions.

3. MODEL:

We present the Compressive Transformer, a long-range sequence model which compacts past activations into a compressed memory2 . The Compressive Transformer is a variant of the Transformer

Compressed Memory Memory Sequence f c (3) t f c (2) f c (1)

Figure 1 : The Compressive Transformer keeps a fine-grained memory of past activations, which are then compressed into coarser compressed memories. The above model has three layers, a sequence length n s = 3, memory size n m = 6, compressed memory size n cm = 6. The highlighted memories are compacted, with a compression function f c per layer, to a single compressed memory -instead of being discarded at the next sequence. In this example, the rate of compression c = 3. (Vaswani et al., 2017) , a deep residual network which only uses attention to propagate information over time (namely multi-head attention). We build on the ideas of the TransformerXL (Dai et al., 2019) which maintains a memory of past activations at each layer to preserve a longer history of context. The TransformerXL discards past activations when they become sufficiently old (controlled by the size of the memory). The key principle of the Compressive Transformer is to compress these old memories, instead of discarding them, and store them in an additional compressed memory.

3.1. DESCRIPTION:

We define n m and n cm to be the number of respective memory and compressive memory slots in the model per layer. The overall input sequence S = x 1 , x 2 , . . . , x |s| represents input observations (e.g. tokens from a book). These are split into fixed-size windows of size n s for the model to process in parallel. The model observes x = x t , . . . , x t+ns at time t, which we refer to as the sequence (e.g. in Figure 1 ). As the model moves to the next sequence, its n s hidden activations are pushed into a fixed-sized FIFO memory (like the TransformerXL) of size n m . The oldest n s activations in memory are evicted, but unlike the TransformerXL we do not discard them. Instead we apply a compression operation, f c : R ns×d → R ns c ×d , mapping the n s oldest memories to ns c compressed memories which we then store in a secondary FIFO compressed memory of size n cm . d denotes the hidden size of activations and c refers to the compression rate, a higher value indicates more coarse-grained compressed memories. The overall temporal range of the model becomes l × (n s + n m + c * n cm ), where l is the number of layers -as discussed in Supplementary Section A. The full architecture is described in Algorithm 1. 

EQUATION

m (i) t+1 ← concat(m (i) t , h (i) )[-n m :] // Update memory (n m × d) 11: cm (i) t ← concat(cm (i) t , new cm (i) )[-n cm :] // Update compressed memory (n cm × d) 12: h (i+1) ← layer norm(mlp (i) (a (i) ) + a (i) ) // Mixing MLP (n s × d)

Algorithm 2 Attention-Reconstruction Loss 1: L attn ← 0 2: for layer i = 1, 2, . . . , l do 3:

h (i) ← stop gradient(h (i) )

// Stop compression grads from passing...

4::

old mem (i) ← stop gradient(old mem (i) ) // ...into transformer network.

5::

Q, K, V ← stop gradient(attention params at layer i) // Re-use attention weight matrices.

6:

def attn(h, m) ← σ((hQ) (mK))(mV) // Use content-based attention (no relative).

7:

new cm (i) ← f (i) c (old mem (i) )

// Compression network (to be optimized).

8::

L attn ← L attn + ||attn(h (i) , old mem (i) )attn(h (i) , new cm (i) )|| 2

3.2. COMPRESSION FUNCTIONS AND LOSSES:

For choices of compression functions f c we consider (1) max/mean pooling, where the kernel and stride is set to the compression rate c;

(2) 1D convolution also with kernel & stride set to c;

(3) dilated convolutions; (4) most-used where the memories are sorted by their average attention (usage) and the most-used are preserved. The pooling is used as a fast and simple baseline. The mostused compression scheme is inspired from the garbage collection mechanism in the Differentiable Neural Computer (Graves et al., 2016) where low-usage memories are erased. The convolutional compression functions contain parameters which require training.

One can train the compression network using gradients from the loss; however for very old memories this requires backpropagating-through-time (BPTT) over long unrolls. As such we also consider some local auxiliary compression losses. We consider an auto-encoding loss where we reconstruct the original memories from the compressed memories

L ae = ||old mem (i) -g(new cm (i) )|| 2 ,

where g : R ns c ×d → R ns×d is learned. This is a lossless compression objective -it attempts to retain all information in memory. We also consider an attention-reconstruction loss described in Algorithm 2 which reconstructs the content-based attention over memory, with content-based attention over the compressed memories. This is a lossy objective, as information that is no longer attended to can be discarded, and we found this worked best. We stop compression loss gradients from passing into the main network as this prevents learning. Instead the Transformer optimizes the task objective and the compression network optimizes the compression objective conditioned on task-relevant representations; there is no need to mix the losses with a tuning constant.

4. PG-19 BENCHMARK:

As models begin to incorporate longer-range memories, it is important to train and benchmark them on data containing larger contexts. Natural language in the form of text provides us with a vast repository of data containing long-range dependencies, that is easily accessible. We propose a new language modelling benchmark, PG-19, using text from books extracted from Project Gutenberg3 . We select Project Gutenberg books which were published over 100 years old, i.e. before 1919 (hence the name PG-19) to avoid complications with international copyright, and remove short texts. The dataset contains 28, 752 books, or 11GB of text -which makes it over double the size of BookCorpus and Billion Word Benchmark.

4.1. RELATED DATASETS:

The two most benchmarked word-level language modelling datasets either stress the modelling of stand-alone sentences (Billion Word Benchmark from Chelba et al. (2013)) or the modelling of a small selection of short news articles (Penn Treebank processed by Mikolov et al. (2010) ). Merity et al. (2016) proposed the WikiText-103 dataset, which contains text from a high quality subset of English-language wikipedia articles. These articles are on average 3, 600 words long. This dataset has been a popular recent LM benchmark due to the potential to exploit longer-range dependencies (Grave et al., 2016; Rae et al., 2018; Bai et al., 2018b) . However recent Transformer models, such as the TransformerXL (Dai et al., 2019) appear to be able to exploit temporal dependencies on the order of several thousand words. This motivates a larger dataset with longer contexts.

Books are a natural choice of long-form text, and provide us with stylistically rich and varied natural language. Texts extracted from books have been used for prior NLP benchmarks; such as the Children's Book Test (Hill et al., 2015) and LAMBADA (Paperno et al., 2016) . These benchmarks use text from Project Gutenberg, an online repository of books with expired US copyright, and Book-Corpus (Zhu et al., 2015) , a prior dataset of 11K unpublished (at time of authorship) books. CBT and LAMBADA contain extracts from books, with a specific task of predicting held-out words. In the case of LAMBADA the held-out word is specifically designed to be predictable for humans with access to the full textual context -but difficult to guess with only a local context.

CBT and LAMBADA are useful for probing the linguistic intelligence of models, but are not ideal for training long-range language models from scratch as they truncate text extracts to at most a couple of paragraphs, and discard a lot of the books' text. There has been prior work on training models on book data using BookCorpus directly (e.g. BERT from Devlin et al. ( 2018)) however BookCorpus is no longer distributed due to licensing issues, and the source of data is dynamically changing -which makes exact benchmarking difficult over time.

The NarrativeQA Book Comprehension Task (Kočiskỳ et al., 2018) uses Project Gutenberg texts paired with Wikipedia articles, which can be used as summaries. Due to the requirement of needing a corresponding summary, NarrativeQA contains a smaller selection of books: 1,527 versus the 28,752 books in PG-19. However it is reasonable that PG-19 may be useful for pre-training book summarisation models.

4.2. STATISTICS:

A brief comparison of PG-19 to other LM datasets can be found in Table 1 . We intentionally do not limit the vocabulary by unk-ing rare words, and release the dataset as an open-vocabulary benchmark. To compare models we propose to continue measuring the word-level perplexity. This can still be computed for any chosen character-based, byte-based or subword-based scheme. To do this, one calculates the total cross-entropy loss L =t log(p t |p <t ) over the given validation or test subset using a chosen tokenization scheme, and then one normalizes this value by the number of words: L/n words where n words is the total number of words in the given subset, taken from Table 2 . The word-level perplexity is thus e L/n words . For sake of model comparisons, it is important to use the exact number of words computed in Table 2 as the normalisation constant.

Alongside quantitative analyses, we build an LDA topic model (Blei et al., 2003) for a qualitative inspection of the text. We present key words for several topics in the Supplementary Table 10 . These topics include art, education, naval exploration, geographical description, war, ancient civilisations, and more poetic topics concerning the human condition -love, society, religion, virtue etc. This contrasts to the more objective domains of Wikipedia and news corpora.

5. EXPERIMENTS:

We optimised all models with Adam (Kingma and Ba, 2014) . We used a learning rate schedule with a linear warmup from 1e-6 to 3e-4 and a cosine decay back down to 1e-n6. For characterbased LM we used 4, 000 warmup steps with 100, 000 decay steps, and for word-based LM we used 16, 000 warmup steps with 500, 000 decay steps. We found that decreasing the optimisation update frequency helped (see Section 5.5.1), namely we only applied parameter updates every 4 steps after 60, 000 iterations. However we found the models would optimise well for a range of warmup/warm- 

Model BPC:

7L LSTM (Graves, 2013) 1.67 LN HyperNetworks Ha et al. (2016) 1.34 LN HM-LSTM Chung et al. (2016) 1.32 ByteNet (Kalchbrenner et al., 2016) 1.31 RHN Zilly et al. (2017) 1.27 mLSTM Krause et al. (2016) 1.24 64L Transf. Al-Rfou et al. (2019) 1.06 24L TXL (Dai et al., 2019) 0.99 Sparse Transf. (Child et al., 2019) 0.991 Adaptive Transf. (Sukhbaatar et al., 2019) 0.98 down values. We clipped the gradients to have a norm of at most 0.1, which was crucial to successful optimisation.

24L

5.1. PG-19:

We benchmark the Compressive Transformer against the TransformerXL on the newly proposed PG-19 books dataset. Because it is open-vocabulary, we train a subword vocabulary of size 32000 with SubwordTextEncoder from the tfds package in TensorFlow and use the dataset statistics to compute word-level perplexity, as described in Section 4.2. We train a 36 layer Compressive Transformer with a window size of 512, both memory and compressed memory size of 512, and compression rate C = 2. We compare this to a 36 layer TransformerXL trained with window size 512 and attention window 1024. The model was trained on 256 TPUv3 cores with a total batch size of 512 and converged after processing around 100 billion subword tokens. We display the results in Table 3 where we see the Compressive Transformer obtains a test perplexity of 33.6 versus the TransformerXL's 36.3. Despite the dataset size, it is clearly a challenging domain. This can suit as a first baseline on the proposed long-range language modelling benchmark. We show samples from this model in Supplementary Section F. The model is able to generate long-form narrative of varying styles: from character dialogue, first person diary entries, to descriptive third-person text.

5.2. ENWIK8:

We compare the TransformerXL and the Compressive Transformer on the standard character-level language modelling benchmark Enwiki8 taken from the Hutter Prize (Hutter, 2012) , which contains 100M bytes of unprocessed Wikipedia text. We select the first 90MB for training, 5MB for validation, and the latter 5MB for testing -as per convention. We train 24-layer models with a sequence window size of 768. During training, we set the TransformerXL's memory size to 2304, and for the Compressive Transformer we use memory of size 768 and compressed memory of size 1152 with compression rate C = 3. During evaluation, we increased the TransformerXL memory size to 4096 and the compressed memory in our model to 3072 (after sweeping over the validation set), obtaining the numbers reported in Table 4 . We show the effect of scaling the compressed memory size and evaluation performance in Supplementary Section C. The proposed model achieves the new state-of-the-art on this dataset with 0.97 bits-per-character.

We compare compression functions and the use of auxiliary losses in Table 5 . We sweep over compression rates of 2, 3, and 4 and report results with the best performing value for each row. BPTT signifies that no auxiliary compression loss was used to train the network other than the overall training loss. To feed gradients into the compression function we unrolled the model over double the sequence length and halved the batch size to fit the larger unroll into memory.

5.3. WIKITEXT-103:

We train an eighteen-layered Compressive Transformer on the closed-vocabulary word-level language modelling benchmark WikiText-103, which contains articles from Wikipedia. We train the model with a compressed memory size, memory size, and a sequence window size all equal to 512.

We trained the model over 64 Tensor Processing Units (TPU) v3 with a batch size of 2 per coremaking for a total batch size of 128. The model converged in a little over 12 hours. We found the single-layer convolution worked best, with a compression rate of c = 4. This model obtained 17.6 perplexity on the test set. By tuning the memory size over the validation set -setting the memory size to 500, and compressed memory size to 1, 500 -we obtain 17.1 perplexity. This is 1.2 perplexity points over prior state of the art, and means the model places a ≈ 5% higher probability on the correct word over the prior SotA TransformerXL. We break perplexity down by word frequency in Table 7 and see the Compressive Transformer makes only a small modelling improvement for frequent words (2.6% over the Trans-formerXL baseline) but obtains a much larger improvement of ≈ 20% for infrequent words. Furthermore, we see 10X improvement in modelling rare words over the prior state-of-the-art LSTM language model published in 2018 -which demonstrates the rate of progress in this area.

It is worth noting that in:



5.4. COMPRESSIBILITY OF LAYERS:

We can use compression to better understand the model's mode of operation. We inspect how compressible Transformer's activations are as they progress through higher layers in the network. One may expect representations to become more difficult to compress at higher layers, if more semantic information is represented there. We monitor the compression loss at each layer of our best-performing Compressive Transformer models trained on Enwik8 and WikiText-103 and display these in Supplementary Section B Figure 6 . We note that the compression loss is about one order of magnitude higher for word-level language modelling (WikiText-103) over character-level langauge modelling (Enwik8). Furthermore the first layer of the Transformer is highly compressible. However there is not a clear trend of compression cost increasing with layer depth.

5.5. ATTENTION:

We inspect where the network is attending to on average, to determine whether it is using its compressed memory. We average the attention weight over a sample of 20, 000 sequences from a trained model on Enwik8. We aggregate the attention into eighteen buckets, six for each of the compressed memory, memory, and sequence respectively. We set the size of the sequence, memory and compressed memory all to be 768. We plot this average attention weight per bucket in Figure 2 with a 1σ standard error. We see most of the attention is placed on the current sequence; with a greater weight placed on earlier elements of the sequence due to the causal self-attention mechanism which masks future attention weights. We also observe there is an increase in attention from the oldest activations stored in the regular memory, to the activations stored in the compressed memory. This goes against the trend of older memories being accessed less frequently -and gives evidence that the network is learning to preserve salient information.

5.5.1. OPTIMISATION SCHEDULE:

We make an observation about an interesting but undesirable meta-learning phenomenon during long-context training. When the learning rate is tuned to be much smaller (or set to zero) during training, performance degrades drastically both for the TransformerXL and the Compressive Transformer. This is displayed in Figure 3 .

Usually we consider distributional shift from the training data to the test data, but we can also observe a shift in the model when transferring from a training to evaluation mode (even when the model is evaluated on the training data). In this case, this is due to the online updating of parameters whilst processing long contiguous articles. We would like the model to generalise well to scenarios where it is not continuously optimised. Updating the parameters only at article boundaries (and then resetting the state) could be one solution for long-range memory models, but this would slow down learning significantly.

Instead, we propose reducing the frequency of optimisation updates during training. We find this allows for the best of both worlds -fast initial learning with frequent updates, and better generalisation near the end of training with less frequent updates (e.g. every 4 steps). Reducing the optimisation frequency increases the effective batch size, which has also been shown to be preferable to learning rate decay in image modelling (Smith et al., 2018) . We observed a final performance improvement in our TransformerXL baseline on Enwik8, from 0.995 -which approximately replicates the published result -to 0.984 -which matches the most recent SotA architecture. We note, the additional space and compute cost of gradients is negligible across iterations, so there was no performance regression in using this scheme.

5.6. SPEECH:

We train the Compressive Transformer on the waveform of speech to assess its performance on different modalities. Speech is interesting because it is sampled at an incredibly high frequency, but we know it contains a lot of information on the level of phonemes and entire phrases.

To encourage long-term reasoning, we refrain from conditioning the model on speaker identity or text features, but focus on unconditional speech modelling. We train the model on 24.6 hours of 24kHz North American speech data. We chunk the sequences into windows of size 3840, roughly 80ms of audio, and compare a 20-layer Compressive Transformer to a 20-layer TransformerXL and a 30-layer WaveNet model (Oord et al., 2016) -a state-of-the-art audio generative model used to serve production speech synthesis applications at Google (Oord et al., 2018) . All networks have approximately 40M parameters, as WaveNet is more parameter-efficient per layer. We train each network with 32 V100 GPUs, and a batch size of 1 per core (total batch size of 32) using synchronous training.

WaveNet processes an entire chunk in parallel, however the TransformerXL and Compressive Transformer are trained with a window size of 768 and a total memory size of 1, 568 (for the Compressive Transformer we use 768 memory + 768 compressed). We thus unroll the model over the sequence. Despite this sequential unroll, the attention-based models train at only half the speed of WaveNet. We see the test-set negative-log-likelihood in Figure 4 , and observe that a Compressive Transformer with a compression rate of 4 is able to outperform the TransformerXL and maintain a slim advantage over WaveNet. However we only trained models for at most one week (with 32GPUs) and it would be advantageous to continue training until full convergence -before definitive conclusions are made.

5.7. REINFORCEMENT LEARNING:

Compression is a good fit for video input sequences because subsequent frames have high mutual information. Here we do not test out the Compressive Transformer on video, but progress straight to a reinforcement learning agent task that receives a video stream of visual observations -but must ultimately learn to use its memory to reason over a policy.

We test the Compressive Transformer as a drop-in replacement to an LSTM in the IMPALA setup (Espeholt et al., 2018) . Otherwise, we use the same training framework and agent architecture as described in the original work with a fixed learning rate of 1.5e-5 and entropy cost coefficient of 2e-3. We test the Compressive Transformer on a challenging memory task within the DMLab-30 (Beattie et al., 2016) domain, rooms select nonmatching object. This requires the agent to explore a room in a visually rich 3D environment and remember the object present. The agent can then advance to a second room where it must select the object not present in the original room. This necessitates that the agent both remember events far in the past, and also learn to efficiently reason about them.

We fix both the memory and compressed memory sizes to 64. In Figure 5 , we present results for a range of compression rates, averaged over 3 seeds. We see that the best performing agents endowed with the Compressive Transformer are able to solve the task to human-level. We note that the model with compression rate 1 is unable to learn the task to the same proficiency. The speed of learning and stability seem to increase proportionally with higher rates of compression (up to a limit) -i.e. the effective memory window of the agent -and we find compression rate 4 to once again be the best performing. We see this as a promising sign that the architecture is able to efficiently learn, and suitably use, compressed representations of its visual input and hope to test this more widely in future work.

6. CONCLUSION:

In this paper we explore the notion of compression as a means of extending the temporal receptive field of Transformer-based sequence models. We see a benefit to this approach in the domain of text, with the Compressive Transformer outperforming existing architectures at long-range language modelling. To continue innovation in this area, we also propose a new book-level LM benchmark, PG-19. This may be used to compare long-range language models, or to pre-train on other longrange reasoning language tasks, such as NarrativeQA (Kočiskỳ et al., 2018) .

We see the idea of compressive memories is applicable not only to the modality of text, but also audio, in the form of modelling the waveform of speech, and vision, within a reinforcement-learning agent trained on a maze-like memory task. In both cases, we compare to very strong baselines (Wavenet (Oord et al., 2016) and IMPALA (Espeholt et al., 2018) ).

The main limitation of this work is additional complexity, if the task one wishes to solve does not contain long-range reasoning then the Compressive Transformer is unlikely to provide additional benefit. However as a means of scaling memory and attention, we do think compression is a simpler approach to dynamic or sparse attention -which often requires custom kernels to make efficient. One can build effective compression modules from simple neural network components, such as convolutions. The compression components are immediately efficient to run on GPUs and TPUs.

Memory systems for neural networks began as compressed state representations within RNNs. The recent wave of progress using attention-based models with deep and granular memories shows us that it is beneficial to refrain from immediately compressing the past. However we hypothesise that more powerful models will contain a mixture of granular recent memories and coarser compressed memories. Future directions could include the investigation of adaptive compression rates by layer, the use of long-range shallow memory layers together with deep short-range memory, and even the use of RNNs as compressors. Compressive memories should not be forgotten about just yet.

SUPPLEMENTARY MATERIALS A TEMPORAL RANGE OF THE COMPRESSIVE TRANSFORMER:

The TransformerXL with a memory of size n has a maximum temporal range of l × n with an attention cost of O(n 2 s + n s n) (see Dai et al. (2019) for a detailed discussion). The Compressive Transformer now has a maximum temporal range of l ×(n s +n m +c * n cm ) with an attention cost of O(n 2 s + n s (n m + n cm )). For example, setting n cm = n m = n/2 and c = 3 we obtain a maximum temporal range that is two times greater than the TransformerXL with an identical attention cost. Thus if we can learn in the c > 1 compressed setting, the temporal range of the model can be significantly increased.

B COMPRESSION ACROSS LAYERS:

We inspect the compression loss broken down by the layer index, to investigate whether there is a trend in network depth with how compressible the representations are. The compression loss here refers to the attention-reconstruction attention loss. We plot this for a 24 layer trained model on Enwik8, and an 18 layer model trained on WikiText-103. The compression loss for characterbased language modelling is about one order of magnitude lower than that of word-level language modelling. The first layer's representations are highly compressible, however from then on there is no fixed trend. Some non-contiguous layers have a very similar compression loss (e.g. 4 & 6, 5 & 7) which suggests information is being routed from these layer pairs via the skip connection. 

C COMPARISON OF COMPRESSED MEMORY SIZES:

We compare the best test perplexity obtained for the Compressive Transformer trained on WikiText-103 and Enwik8 across a range of compressed memory sizes. For both models, the best model used a 1D convolution compression network with a compression rate of 3. The Enwik8 model was trained with an embedding size of 1024, 8 attention heads, 24 layers, an mlp hidden size of 3072, a sequence window size of 768, and a memory size of 768. We see the best compressed memory size is 3, 072 in this sweep, facilitating a total attention window of 3840. The WikiText-103 model was trained with an embedding size of 1024, adaptive inputs using the same parameters as (Sukhbaatar et al., 2019) , 16 attention heads, 18 layers, an mlp hidden size of 4096, a sequence window of size 512 and a memory of size 512. The best compressed memory size is 1536 resulting in a total attention window of c. 2048.

Compressed Memory Size 512 1024 2048 3072 4096:

Enwik8 BPC 1.01 0.99 0.98 0.97 1.00 June 1st. Having taken our leaves of Sir W. Batten and my Lady, who are gone this morning to keep their Whitsuntide, Sir W. Pen and I and Mr. Gauden by water to Woolwich, and there went from ship to ship to give order for and take notice of their forwardness to go forth, and then to Deptford and did the like, having dined at Woolwich with Captain Poole at the tavern there. From Deptford we walked to Redriffe, calling at the half-way house, and there come into a room where there was infinite of new cakes placed that are made against Whitsuntide, and there we were very merry. By water home, and there did businesses of the office. Among others got my Lord's imprest of L1000 and Mr. Creed's of L10,000 against this voyage their bills signed. Having wrote letters into the country and read some things I went to bed.

Compressive Transformer::

So I rose and did some business at the office, and then to dinner, where great abundance of good things of the kitchen I only being partaker in the feast. After dinner I went to look at the yard and found it in a very bad condition, so I went home and there finding no delight in seeing things I should make shift to get in my way and so I will leave off.

So I took leave of my great friend, and the next day being Sunday, my wife and I and a great number of friends went by water to Deptford, and there took the oaths of allegiance and supremacy and promised such obedience to the Lord as should hereafter turn to the advantage of our State. Being come back we found the shops and warehouses in a pitiable condition, so my wife and I and all the rest of the friends went home and there did the like and by Saturday day I being alone in my office I found myself in a very bad situation, for my Lord, and Mr. Creed, and Pett were all standing ready to receive and receive the oaths of allegiance and right to make use of the ten days' licence I had allowed for this purpose by virtue of the law that was such a help to the servant. Having looked at the ships, I told my wife what I had seen and that I was greatly troubled at my situation and, I hope that will mend it.

So that is the end of a long and patient seeking after those things which in my opinion I deserve and may get if I can only by fair means get them.

Context from The Patrol of the Sun Dance Trail by Ralph Connor::

High up on the hillside in the midst of a rugged group of jack pines the Union Jack shook out its folds gallantly in the breeze that swept down the Kicking Horse Pass. That gallant flag marked the headquarters of Superintendent Strong, of the North West Mounted Police, whose special duty it was to preserve law and order along the construction line of the Canadian Pacific Railway Company, now pushed west some scores of miles.

Along the tote-road, which ran parallel to the steel, a man, dark of skin, slight but wiry, came running, his hard panting, his streaming face, his open mouth proclaiming his exhaustion. At a little trail that led to the left he paused, noted its course toward the flaunting flag, turned into it, then struggled up the rocky hillside till he came to the wooden shack, with a deep porch running round it, and surrounded by a rustic fence which enclosed a garden whose neatness illustrated a characteristic of the British soldier. The runner passed in through the gate and up the little gravel walk and began to ascend the steps.

As though by mutual consent, all the three members of the Superintendent Force were standing on the veranda watching his progress, a man came strolling slowly down the path, stopping often to gaze curiously about him, then stopping once more when he saw the four standing on the veranda. His face was dark, his eyes prominent, and the lines that furrowed his forehead showed marks of many woes, yet his step was alert and he began to mount the steps with steady strides.

The man's attention was diverted by the unexpected appearance of the two policemen; a third man came slipping up, grumbling under his breath, and stopped long enough to look doubtfully around him, then slipped away again. In the meantime, the four on the veranda continued to watch the approach of the new arrival. In spite of himself, the Superintendent Force became conscious of a curious feeling-uneasiness that was almost fear-in the presence of that strange man. He would not allow himself to admit the fact, yet he felt it in his bones. But to the watchers, the plain, everyday features of that stranger and his coming, seemed only just what the Seven White Shee owed him-their weight, their hurry, their blast.

Had a chariot been made for the good of the three horses, and had the driver been given orders that he should speed them that he might win, they would have been heartening things in the sight of the veteran and the victor. To you they would have been unintelligible to the root of your understanding. When you gaze up in the faces of those four gray horses, you can see clearly through the clouds of dust that rise from their hoofs, and discern plainly where the banker is and where the hobo. Then you will understand why you shall not press the bitter grapes and why you shall not spurn the generous doctrines. You will understand why you shall not praise the lash or the spur, for you will know where the true would be and where the false would be. Then you will understand why you, a man with reason and heart, need not tear your hair over-bitter and why you need not laugh over the blunders of an ignorant man.

About nine o'clock that morning, two buggies, drawn by powerful horses, crossed the Rubicon and turned the railroad from Sandhurst into the Hollow of the Mountains. And though the charioteers stood at their horses' heads, and their drivers cried at their loudest, there was not a man in the four teams who did not feel that his day was worth all the toil and all the peril that he had undergone. And if there were a man in them who did not know that-who did not feel that the road through the Hollow of the Mountains is made easy by the arrival of travelers and by the coming of government, there was one who did not at that moment care whether his day's work were worth all the toil and all the danger that he had had to endure or whether it were not worth more than all.

:

Project Gutenberg: https://www.gutenberg.org/

A TF implementation can be found in Sonnet: https://github.com/deepmind/sonnet

PG-19 is available at https://github.com/deepmind/pg19

https://www.ofcom.org.uk/__data/assets/pdf_file/0023/91625/ OfcomQRG-AOC.pdf

Figures and Tables:

Figure 3: Learning rate analysis. Reducing the learning rate (e.g. to zero) during training (on Enwik8) harms training performance. Reducing the frequency of optimisation updates (effectively increasing the batch size) is preferable.

Figure 4: Speech Modelling. We see the Compressive Transformer is able to obtain competitive results against the state-of-the-art WaveNet in the modelling of raw speech sampled at 24kHz.

Figure 6: Model analysis. Compression loss broken down by layer.

Comparison to existing popular language modelling benchmarks.

Table content: <table><tr><td/><td colspan="3">Avg. length (words) Train Size Vocab</td><td>Type</td></tr><tr><td>1B Word</td><td>27</td><td>4.15GB</td><td>793K</td><td>News (sentences)</td></tr><tr><td>Penn Treebank</td><td>355</td><td>5.1MB</td><td>10K</td><td>News (articles)</td></tr><tr><td>WikiText-103</td><td>3.6K</td><td>515MB</td><td>267K</td><td>Wikipedia (articles)</td></tr><tr><td>PG-19</td><td>69K</td><td>10.9GB</td><td>(open)</td><td>Books</td></tr></table>

PG-19 statistics split by subsets.

Table content: <table><tr><td/><td>Train</td><td>Valid.</td><td>Test</td></tr><tr><td># books</td><td>28,602</td><td>50</td><td>100</td></tr><tr><td colspan="4"># words 1,973,136,207 3,007,061 6,966,499</td></tr></table>

Eval. perplexities on PG-19.

Table content: <table><tr><td>Valid. Test</td></tr></table>

State-of-the-art results on Enwik8.

Table content: <table/>

Compression approaches on Enwik8.

Table content: <table><tr><td colspan="3">Compression fn Compression loss BPC</td></tr><tr><td>Conv</td><td>BPTT</td><td>0.996</td></tr><tr><td>Max Pooling</td><td>N/A</td><td>0.986</td></tr><tr><td>Conv</td><td>Auto-encoding</td><td>0.984</td></tr><tr><td>Mean Pooling</td><td>N/A</td><td>0.982</td></tr><tr><td>Most-used</td><td>N/A</td><td>0.980</td></tr><tr><td>Dilated conv</td><td>Attention</td><td>0.977</td></tr><tr><td>Conv</td><td>Attention</td><td>0.973</td></tr></table>

Validation and test perplexities on WikiText-103.

Table content: <table><tr><td>Valid. Test</td></tr></table>

WikiText-103 test perplexity broken down by word frequency buckets. The most frequent bucket is words which appear in the training set more than 10, 000 times, displayed on the left. For reference, a uniform model would have perplexity |V | = 2.6e5 for all frequency buckets. *LSTM comparison fromRae et al. (2018)

Table content: <table><tr><td/><td/><td/><td colspan="5">&gt; 10K 1K-10K 100 -1K &lt; 100</td><td>All</td></tr><tr><td/><td/><td>LSTM*</td><td>12.1</td><td colspan="2">219</td><td>1,197</td><td>9,725</td><td>36.4</td></tr><tr><td/><td/><td>TransformerXL (ours)</td><td>7.8</td><td colspan="2">61.2</td><td>188</td><td>1,123</td><td>18.1</td></tr><tr><td/><td/><td>Compressive Transformer</td><td>7.6</td><td colspan="2">55.9</td><td>158</td><td>937</td><td>17.1</td></tr><tr><td/><td/><td>Relative gain over TXL</td><td>2.6%</td><td colspan="2">9.5%</td><td>21%</td><td>19.9% 5.8%</td></tr><tr><td>Average attention weight</td><td>0.00 0.02 0.04 0.06 0.08 0.10 0.12 0.14</td><td colspan="2">1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 Compressed Memory Memory Sequence</td><td>Training BPC</td><td>1.2 0.7 0.8 0.9 1.0 1.1</td><td colspan="2">5000 Learning Rate 10000 Training iterations 15000 Change learning rate 20000 during training 0.0 1e-9 1e-7 3e-4 3e-4 update period=2</td><td>25000</td></tr></table>

Compressed memory size vs test performance for Enwik8Context from The Diary of Samuel Pepys:

Table content: <table/>

Peer review (iclr2020):
This paper proposes a way to compress past hidden states for modeling long sequences. Attention is used to query the compressed representation. The authors introduce several methods for compression such as convolution, pooling etc. The outcome is a versatile model that enables long-range sequence modeling, achieving strong results on not only language model tasks but also RL and speech. For testing and evaluating the modeling of really long context sequence modeling, the authors introduce PG-19, a new benchmark based on Project Gutenberg narratives. The idea is a simple and straightforward one. The choices of compression functions are intuitive and natural. The probably more interesting part of this paper is the training schemes designed to train the memory compression network. Results are very strong and there is a pretty diverse set of experiments. That said, it seems like a huge amount of resources were spent on this work alone. It also seems like these models are not trivial to train (or get them to work). It would be interesting to find out how much resources were spent (in terms of preliminary experiments) to getting these models to start working decently. There are also no reports of parameter counts, which might make the experiments unfair. Achieving SOTA is one thing, which could be attributed to large resource pools and maybe larger parameter sizes of models. Overall, I am voting for a weak accept. While this paper is more incremental and novelty may be slightly lacking, I think the breadth of experiments and competitive results warrants an acceptance. Several issues and questions for the authors: 1) Why are the results on PG-19 not reported in a Table format? Why are there no results of the base Transformer on PG-19? I think this is really necessary and should be reported. 2) The authors mention that this memory compression architecture enables long sequence modeling. However, is there an intended way of use for long-text that is not necessarily framed as a LM problem? For instance, results on NarrativeQA benchmark would be nice. UPDATE: I have read the author response and other reviewer*s comments. I am happy with the efforts made by the authors and I am raising my score to 8 (accept).