Generalization through Memorization: Nearest Neighbor Language Models

Urvashi Khandelwal, Omer Levy, Dan Jurafsky, Luke Zettlemoyer, Mike Lewis
11/1/2019
cs.CL

Official code: urvashik/knnlm (332 stars, MIT, last commit 2021-06-07).

Abstract

We introduce $k$NN-LMs, which extend a pre-trained neural language model (LM) by linearly interpolating it with a $k$-nearest neighbors ($k$NN) model. The nearest neighbors are computed according to distance in the pre-trained LM embedding space, and can be drawn from any text collection, including the original LM training data. Applying this augmentation to a strong Wikitext-103 LM, with neighbors drawn from the original training set, our $k$NN-LM achieves a new state-of-the-art perplexity of 15.79 - a 2.9 point improvement with no additional training. We also show that this approach has implications for efficiently scaling up to larger training sets and allows for effective domain adaptation, by simply varying the nearest neighbor datastore, again without further training. Qualitatively, the model is particularly helpful in predicting rare patterns, such as factual knowledge. Together, these results strongly suggest that learning similarity between sequences of text is easier than predicting the next word, and that nearest neighbor search is an effective approach for language modeling in the long tail.

View on arXivView PDF

Code Implementations(1)

urvashik/knnlmOfficial100%
MIT
33247C++, LuaFeb 11, 20205 years agoMIT

Similar Papers

Cite this paper

@article{khandelwal2019generalization,
  title  = {Generalization through Memorization: Nearest Neighbor Language Models},
  author = {Urvashi Khandelwal and Omer Levy and Dan Jurafsky and Luke Zettlemoyer and Mike Lewis},
  year   = {2019},
  eprint = {1911.00172},
  archivePrefix = {arXiv},
  url    = {https://arxiv.org/abs/1911.00172}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/1911.00172.svg)](https://codeofpaper.com/paper/1911.00172)

Discussion