This paper was converted on www.awesomepapers.org from LaTeX by an anonymous user.
Want to know more? Visit the Converter page.

On-The-Fly Information Retrieval Augmentation for Language Models

Hai Wang    David McAllester
Toyota Technological Institute at Chicago, Chicago, IL, USA
{haiwang,mcallester}@ttic.edu
Abstract

Here we experiment with the use of information retrieval as an augmentation for pre-trained language models. The text corpus used in information retrieval can be viewed as form of episodic memory which grows over time. By augmenting GPT 2.0 with information retrieval we achieve a zero shot 15% relative reduction in perplexity on Gigaword corpus without any re-training. We also validate our IR augmentation on an event co-reference task.

1 Introduction

We are interested in exploring the value of long term episodic memory in language modeling. For example, a language model can be used in January to assign a probability distribution over the statements that will appear in the newspaper in March. But one month later, in February, the distribution over the predictions for March should be updated to take into account factual developments since the previous prediction. Long term episodic memory should be taken into account when assigning a probability to a statement.

Here we take a simple approach in which a pre-trained GPT language model Radford et al. (2018a, 2019) is zero-shot augmented with an episodic memory consisting simply of a corpus of past news articles. Conceptually the past news articles are viewed as additional training data which can be legitimately accessed when evaluating on future text. In our most basic experiment we calculate the probability of a future article by first calculating the probability of its first kk sentences using the pre-trained GPT model. We then use the first kk sentences as a query in an information retrieval system to extract a relevant past article. We then insert the past article following the first kk sentences when calculating the probability of the remainder of the future article using the same pre-trained GPT model. This is a zero-shot augmentation in the sense that there is no additional training or fine tuning of the pre-trained model. Our results show that this augmentation significantly reduces perplexity. We also present various other experiments including results on fine-tuning the model in the presence of the memory and the effect of this memory on event co-reference.

2 Related Work

Various language models have utilized external knowledge or long contexts  Paperno et al. (2016); Yang and Mitchell (2017); Peng et al. (2019); Khandelwal et al. (2018); Ghosh et al. (2016); Lau et al. (2017); Grave et al. (2016); Parthasarathi and Pineau (2018). But these papers do not address the question of whether additional context or external knowledge is useful as a zero-shot augmentation of large scale pre-trained NLP models.

The value of external knowledge has previously been demonstrated for NLP tasks such as natural language inference Chen et al. (2018); Yang et al. (2019), language generation Parthasarathi and Pineau (2018), knowledge base completion Toutanova et al. (2015); Das et al. (2017) and question answering Sun et al. (2019, 2018); Dhingra et al. (2017). However, all those prior works assume the model is small and trained from scratch.

As large scale pre-trained models have become more powerful it is not immediately clear whether external resources can still add value. The only work we know of on using external resources in modern large scale models is Yang et al. (2019) where a human curated external lexical resource is used to improve BERT.

Our approach bears some resemblance to neural cache models Grave et al. (2016). However, neural cache models store past hidden states as memory and accesses them through a dot product with the current hidden states. This is different from retrieving knowledge from a corpus-sized memory.

Our approach is also somewhat related to memory networks Weston et al. (2014). Memory networks have a memory module which can be learnt jointly with other components. It has shown success in applications such as machine reading comprehension Kumar et al. (2016a, b); Shi et al. (2016) and visual question answering Na et al. (2017); Ma et al. (2018); Su et al. (2018). Significant progress in memory networks has been achieved in both architecture  Chandar et al. (2016); Miller et al. (2016); Gulcehre et al. (2017) and model scale Rae et al. (2016); Lample et al. (2019).

Several papers have formulated, and experimented with, scalable memory networks — memory networks that employ some method of efficiently reading and writing to very large neural memories. This is done with approximate nearest neighbor methods in Rae et al. (2016) and with product keys in Lample et al. (2019). These large memories are used to provide additional model capacity where the memory contents are trained over a large data set using gradient descent training, just as one would train the parameters of a very large network. It is shown in Lample et al. (2019) that it is possible to insert a large memory as a layer in a transformer architecture resulting a model where the same number of parameters and the same performance can be achieved with half the layers and with much faster training time than a standard transformer architecture. Here, however, we are proposing zero-shot augmentation with an external data source used as an episodic memory.

The use of key-value memories in Miller et al. (2016) is particularly similar to our model. Key-value memories were used there in treating a corpus of Wikipedia movie pages as a memory for answering questions about movies. As in our system, articles were extracted using word based information retrieval. Each article was encoded as a vector which was then given to a question answering architecture. This was shown to improve on automated knowledge base extraction from the same corpus but was still not competitive with human curated knowledge graphs for movies. Here we give the text of the retrieved article directly to the language model architecture and focus on augmenting large scale language models.

3 Model

We use the pre-trained transformer GPT 2.0 Radford et al. (2019). Let WwW_{w} and WpW_{p} be the subword and position embeddings respectively. Let MM denote the total number of layers, for a token at time step tt, the mm-th layer’s hidden state htmh_{t}^{m} is given by:

htm={Ww+Wpif m=0TB(htm1)if 1mMh_{t}^{m}=\begin{cases}W_{w}+W_{p}&\text{if $m=0$}\\ \text{TB}(h_{t}^{m-1})&\text{if $1\leq m\leq M$}\end{cases}

where TB stands for Transformer Block. We use last layer’s hidden state htMh_{t}^{M} as the presentation HtH_{t} for the token at time step tt. We augment GPT 2.0 with a large episodic memory component, and the overall architecture is shown in Figure 1.

Refer to caption
Figure 1: GPT with large episodic memory component

For a sequence SS with TT tokens, let S1S_{1}, \ldots, SpS_{p} be the tokens of the first kk sentences. Let CC be a sequence (article) retrieved from memory using the first kk sentences as the query, the vector HtH_{t} is:

Ht={GPT(S1,,St),if tpGPT(S1,,Sp,C,,St),otherwiseH_{t}=\begin{cases}\text{GPT}(S_{1},\dots,S_{t}),\text{if $t\leq p$}&\\ \text{GPT}(S_{1},\dots,S_{p},C,\ldots,S_{t}),\text{otherwise}&\end{cases}

That’s to say, for the first kk sentences, we directly feed them to GPT to obtain their representations. For remaining sentences, their representations are conditioned on both the first kk sentences and the retrieved context CC. Table 1 compares features of our simple memory augmentation with those of other memory models.

Model episodic search memory size
DMN yes exact \sim1K words
SAM: no approx \sim100K slots
KVM: yes exact \leq 1M slots
LMN: no exact \sim1M slots
Ours: yes approx \sim10M documents
Table 1: Comparison between different models. DMN: Dynamic Memory Network Kumar et al. (2016b); SAM: Sparse Access Memory Rae et al. (2016); KVM: Key Value Memory Miller et al. (2016); LMN: Large Memory Network Lample et al. (2019). Memory size is measured in their own words.

4 Experiments

We focus on two tasks: document level language modelling and event co-retrieved . In both tasks we take a document as input and use first kk sentences to query the memory. To calculate the perplexity of a document, we compute the log-probability of a document by multiplying byte level probability, then divide the log-probability by the actual word count in the query document.

We use Gigaword Parker et al. (2011) as both our language modeling test set and as our external memory. Gigaword contains news from different sources such as NY Times and XinHua News etc. For language modelling we use the NY Times portion because it is written by native English speakers. Since GPT 2.0 is trained on Common Crawl which contains news collections started from 2008. To avoid testing on GPT-2 training data, we use Gigaword articles collected prior to 2008. For the pre-trained language model we use GPT 2.0 Radford et al. (2019) 111https://github.com/huggingface/pytorch-transformers. It contains three pre-trained models: GPT Small, Medium and Large.

For information retrieval we use Lucene due to its simplicity. Given a query document we first do sentence and word tokenization and then use the first kk sentences to retrieve top 20 retrieved documents with the default TF-IDF distance metric provided by Lucene. Since too distant document pairs are uninformative and too related document pairs tends to be duplicates of the test article, we further filter those top ranked documents by time stamp, news source and cosine similarity. More specifically, we choose the highest ranked retrieved document that simultaneously satisfies the following three conditions: it comes from a different news source; it appears earlier but within two weeks time window of the test document, and the bag of word cosine similarity between the test and the retrieved cannot be larger than 0.6α0.6\alpha where α\alpha is the largest bag of word cosine similarity between the test article and any retrieved articles. To support fine-tuning experiments we constructed a corpus of pairs of a query article and a cached retrieved document. We split the dataset into train/dev/test by query document’s time stamp. The train/dev/test size is: 79622,16927,8045. For zero-shot experiments we use the test set of 8045 articles. We do experiments with k{1,2,5}k\in\{1,2,5\}.

To check the quality of query-retrieved pairs, we randomly sample 100 pairs from dev set and compute the bag of word cosine similarity between the two documents. The mean cosine similarity is 0.15. We also manually inspect them: we ask two NLP researchers to annotate the query-retrieved pair as “BAD” or “OK” independently, i.e., if two documents are almost duplicates or totally unrelated, then it’s “BAD”, otherwise, it’s “OK”. Among 100 pairs, 83 pairs are “OK”, 17 pairs are “BAD” due to irrelevance. The Cohen’s kappa coefficient between two annotations is 0.94.

4.1 Language modelling

For language modeling we try zero-shot memory augmentation, fine-tuned memory augmentation, and training a small memory-augmented network from scratch. When training, we use the Adam optimizer from GPT 1.0 Radford et al. (2018b). The learning rate is 0.001, weight decay parameter is 0.01, the warm up proportion is 0.1. For other parameters, we use the default values from GPT 2.0. The fine-tuning on Gigaword takes less than one day with a single GPU.

Zero-shot and fine-tuning results

Following  Radford et al. (2019), we first evaluate our model on Gigaword with zero-shot setting and then fine-tune the model. The results are given in Table 2.

Model Size woc k=1 k=2 k=5
GPT-Small 35.15 29.29 30.54 32.38
GPT-Medium 22.78 19.84 20.54 21.48
GPT-Large 19.90 17.41 18.00 18.80
GPT-Small 23.03 21.01 21.89 22.66
Table 2: Perplexity for zero-shot (top 3 rows) and fine-tuning (last row) settings when use different kk to retrieve the context. woc: without retrieved context.

From Table 2, we see that with additional context retrieved from episodic memory, for all different GPT models, we obtain significantly lower perplexity than using original GPT 2.0. When fine tuning the model with context, we can further reduce the overall perplexity. We only fine tune GPT small due to our GPU memory constraints. Preliminary analysis indicates that most of the perplexity reduction comes at content words and semantically rich words where predictions require broader context. This is consistent with the phenomena found in Khandelwal et al. (2018). We further find that smaller kk leads to slightly worse retrieval quality, however, more continued sentences will benefit from the retrieved context. Since Gigaword contains newswire, the first several sentences usually are importation summarizations, thus overall, smaller kk will result in lower perplexity.

Train from scratch

We also investigate training this form of memory-augmented model from scratch on our query-retrieved pairs. For these experiments we train smaller transformers and the results are given in Table 3. From Table 3, we see that additional context still helps and we can get decent perplexity even with quite small models.

Model Config woc k=1 k=2 k=5
E=384,H=6,L=6 35.62 31.94 33.18 35.26
E=384,H=8,L=8 33.67 29.62 30.76 32.73
E=576,H=8,L=8 31.32 27.38 28.54 30.63
Table 3: Perplexity when train from scratch. E: hidden states dimensionality; H: # of head; L: # of layer. GPT-Small has the configuration: E=764, H=12, L=12.

When context is irrelevant

We also evaluate our method on Wikitext-2/103, in which the retrieved context is irrelevant due to domain difference between Wikipedia and Gigaword. In this case, we use the most top ranked document from Gigaword as reference. Table 4 shows that irrelevant contexts have very little impact on perplexity.

Dataset woc k=1 k=2 k=5
Wikitext-2 28.67 28.96 28.95 28.70
Wikitext-103 25.38 25.68 25.56 25.39
Table 4: Zero-shot perplexity using GPT-Small

4.2 Event Co-reference

Intuitively episodic memory is useful because it contains information about the particular events mentioned in the test document. With this in mind we evaluate our approach on the event co-reference dataset ECB+ Cybulska and Vossen (2014). ECB+ contains 982 documents clustered into 43 topics, and has two evaluation settings: coreferring mentions occurring within a single document (within document) or across a document collection (cross document). For the event co-reference pipeline, we follow the joint modeling method of Barhom et al. (2019) where they jointly represented entity and event mentions with various features and learned a pairwise mention/entity scorer for coreference classification. We augment their mention features with the mention’s vector representations extracted from either GPT 2.0 or our zero-shot augmented GPT 2.0. For event co-reference, we use the whole test document to retrieve the context from Gigaword. From Table 5, we see that the context can help boost the CONLL F1 score.

System MUC B3\text{B}^{3} CONLL
Within Document
KCP 63.0 92.0 81.0
JM 70.9 93.5 85.1
JM+GPT 80.1 93.5 85.2
JM+GPT+CTX\text{JM+GPT+CTX}^{\clubsuit} 80.2 93.9 85.4
Combined Within and Cross Document
CV 73.0 74.0 73.0
KCP 69.0 69.0 69.0
JM 80.9 80.3 79.5
JM+GPT 81.2 80.2 79.6
JM+GPT+CTX\text{JM+GPT+CTX}^{\clubsuit} 81.3 80.5 79.8
Table 5: F1 score on ECB+ dataset. KCP: Kenyon-Dean et al. (2018) where they add a clustering-oriented regularization term; CV: Cybulska and Vossen (2015) where they add the feature calculated from “event template”; JM: Barhom et al. (2019). \clubsuit: we also feed the retrieved context to GPT to get the representation.

5 Conclusion

In this paper we propose a method to augment a pre-trained NLP model with a large episodic memory. Unlike previous work, we use information retrieval to handle a large external corpus of text and feed retrieved documents directly to language models. Evaluation results on language modelling and event co-reference show the promise of our method. To the best of our knowledge, this is the first work that augments pre-trained NLP models with large episodic memory. In principle, the memory-augmented GPT-2 can be used as a variant of GPT-2 for any downstream tasks, such as GLUE tasks Wang et al. (2018), although we have not experimented with that here.

References