PreprintCited by 301Topic ModelingNatural Language Processing TechniquesSpeech Recognition and Synthesis

Generalization through Memorization: Nearest Neighbor Language Models

Open access
Khandelwal, Urvashi, Levy, Omer, Jurafsky, Dan, Zettlemoyer, Luke, Lewis, Mike·2019·arXiv

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.

The claims and statistics of this paper haven’t been checked yet.

Run the check — free, no account needed. It reads the open-access text and checks the sources it cites.

A few free checks a day · papers already verified open instantly · results are public

Integrity signals

Registry

DataCite · 10.48550/arxiv.1911.00172

Cites

24 of 24 references verified0 citation errors · 0 not checkable

Statistics

Claims the paper makes

The claims and statistics of this paper haven’t been checked yet.

Run the check — free, no account needed. It reads the open-access text and checks the sources it cites.

A few free checks a day · papers already verified open instantly · results are public

Claims other papers make about this one

Each is checked against this paper’s own text: does it say what the citing paper says it does?

  • L2 distance was shown to be more effective than other alternatives for kNN-LM.

    “d ( · , · ) is a distance function between the two vectors, and L 2 was shown to be more effective than other alternatives (Khandelwal et al., 2019).”

    From Efficient Nearest Neighbor Language Models (2021) · cites this paper as Khandelwal et al., 2019

    The Implementation passage (Section 2, p. 2) says preliminary experiments found better kNN-LM performance with L2 distance than with inner product distance. That supports the comparison with inner product, but not the broader suggestion that L2 was tested against multiple other alternatives. (LLM, conf=0.83)

    Experimental — accuracy not yet measured
  • The kNN-LM outperforms the previous best parametric LMs by a large margin in standard language modeling benchmarks, domain adaptation settings, and conditional generation tasks such as machine translation.

    “This model is particularly notable for its large improvements in performance it outperforms the previous best parametric LMs by a large margin in standard language modeling benchmarks, in domain adaptation settings, and on other conditional generation tasks such as machine translation (Khandelwal et al., 2020).”

    From Efficient Nearest Neighbor Language Models (2021) · cites this paper as Khandelwal et al., 2019

    Table 1 (p. 4) shows that kNN-LM substantially improves WIKITEXT-103 perplexity, and Section 4.3 (p. 6) reports a large improvement over an out-of-domain LM on BOOKS. The paper does not report kNN-LM outperforming parametric LMs on conditional generation or machine translation; Section 7 (p. 9) discusses translation as related work by others. In domain adaptation, the reported kNN-LM result also remains worse than the in-domain LM. (LLM, conf=0.89)

    Experimental — accuracy not yet measured
  • Non-parametric LMs model text distributions by referencing both the parameters of the underlying model and examples from an external datastore.

    “Non-parametric neural language models (NLMs) learn predictive distributions of text utilizing an external datastore, which allows them to learn through explicitly memorizing the training datapoints.”

    From Efficient Nearest Neighbor Language Models (2021) · cites this paper as Khandelwal et al., 2019

  • The kNN-LM computes the probability of the next token by interpolating a parametric LM with a distribution calculated from the k nearest context-token pairs in the datastore.

    “The k NN-LMcomputes the probability of the next token by interpolating a parametric LM with a distribution calculated from the k nearest context-token pairs in the datastore, as demonstrated in Figure 2.”

    From Efficient Nearest Neighbor Language Models (2021) · cites this paper as Khandelwal et al., 2019

  • The dataset used to construct the datastore may differ from the training data that trains the parametric NLM, enabling applications such as training-free domain adaptation or gradient-free use of extra training data.

    “Note that the dataset to contruct the datastore may not necessarily be the training data that trains the parametric NLM in Eq. 1 - a separate dataset may be used for the datastore construction which would lead to potential applications such as training-free domain adaptation or a gradient-free way to utilize extra training data (Khandelwal et al., 2019).”

    From Efficient Nearest Neighbor Language Models (2021) · cites this paper as Khandelwal et al., 2019

Self-check

Percentages, sums and reported differences re-computed from the paper’s own numbers.

The self-check needs the paper’s full text.

Cites

Flagged first, then by citations

4 of the 28 references couldn’t be matched to a known paper.

Research works printed but not linked: 5

  1. Yoshua Bengio, R´ ejean Ducharme, Pascal Vincent, and Christian Jauvin. A neural probabilistic language model. Journal of machine learning research , 3(Feb):1137-1155, 2003.
  2. Edouard Grave, Moustapha M Cisse, and Armand Joulin. Unbounded cache model for online language modeling with open vocabulary. In NIPS , pp. 6042-6052, 2017a.
  3. Kelvin Guu, Tatsunori B Hashimoto, Yonatan Oren, and Percy Liang. Generating sentences by editing prototypes. Transactions of the Association for Computational Linguistics , 6:437-450, 2018.
  4. Rico Sennrich, Barry Haddow, and Alexandra Birch. Neural machine translation of rare words with subword units. arXiv preprint arXiv:1508.07909 , 2015. · arXiv
  5. Rowan Zellers, Ari Holtzman, Hannah Rashkin, Ali Farhadi, Franziska Roesner, and Yejin Choi. Defending against neural fake news. In NeurIPS , 2019.

Cited by

Sorted by citations

Authors
Khandelwal, U., Levy, O., Jurafsky, D., Zettlemoyer, L., & Lewis, M.
Affiliations
  • Meta (United States) (US)
  • Meta (United Kingdom) (GB)
Venue
arXiv
Publisher
arXiv
Published
2019
ISSN
2331-8422 (ISSN-L)
OpenAlex
W2988841832
Cited by
285
References
28
Citations by year
2026: 1 · 2025: 34 · 2024: 34 · 2023: 111 · 2022: 52 · 2021: 39 · 2020: 13 · 2019: 1
Type
posted content
Language
en
Open access
Locations
  • arXiv (Cornell University) (submittedVersion)
  • arXiv (Cornell University)
Funders
Styrelsen för Internationellt Utvecklingssamarbete
Topics
  • Physical Sciences › Computer Science › Artificial Intelligence › Topic Modeling
  • Physical Sciences › Computer Science › Artificial Intelligence › Natural Language Processing Techniques
  • Physical Sciences › Computer Science › Artificial Intelligence › Speech Recognition and Synthesis
Keywords
linear interpolation, pre-trained language models, embedding space, perplexity reduction, WikiText-103, domain adaptation, factual knowledge, next-word prediction, sequence similarity

About these checks

Registry, retraction, Cites and statistics results are computed, not judged, with one exception: a printed reference that no index lists is read once by a model before it counts as a citation error. Claims are extracted by a model and kept only when their quote appears verbatim in the text; each cited source is then checked, with a model’s help, for whether it says what the claim relies on. Those verdicts can be wrong — read the claim’s quote and the cited source before relying on one.

Statistics and arithmetic are recomputed, not judged.

Confidence bands are shown only for fields calibrated on our annotated test set. None is calibrated yet, so no band is shown.

What counts as a claim ›How we measure confidence ›How we check this ›

Are you an author, or do you see a problem with this page? Request a review