Memorizing Transformers
Yuhuai Wu, Markus Norman Rabe, DeLesley Hutchins, Christian Szegedy
Abstract
Language models typically need to be trained or finetuned in order to acquire new knowledge, which involves updating their weights. We instead envision language models that can simply read and memorize new data at inference time, thus acquiring new knowledge immediately. In this work, we extend language models with the ability to memorize the internal representations of past inputs. We demonstrate that an approximate kNN lookup into a non-differentiable memory of recent (key, value) pairs improves language modeling across various benchmarks and tasks, including generic webtext (C4), math papers (arXiv), books (PG-19), code (Github), as well as formal theorems (Isabelle). We show that the performance steadily improves when we increase the size of memory up to 262K tokens. On benchmarks including code and mathematics, we find that the model is capable of making use of newly defined functions and theorems during test time.
Ask Lune
Know this paper in minutes, not an afternoon.
Lune can read every page of it and the top-tier papers that cite it, and gives you its claims, its evidence and its limits, each one cited to the paper it comes from. No skimming, no AI slop.
104 top-tier papers have cited it since. Know what they found before your reviewers do.
Lune can draw on
the full paper · the top-tier papers that cite it · related work
Free to start. No credit card required.
Lineage
- Learning to Compress Prompts with Gist Tokens cites Language Models are Few-Shot Learners
- Big Bird: Transformers for Longer Sequences cites Reformer: The Efficient Transformer
- Big Bird: Transformers for Longer Sequences cites Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks
- Generating Images with Multimodal Language Models cites Language Models are Few-Shot Learners
- Scaling up Test-Time Compute with Latent Reasoning: A Recurrent Depth Approach cites Confident Adaptive Language Modeling
- Language Models are Few-Shot Learners cites Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks
- Autoformalization with Large Language Models cites Language Models are Few-Shot Learners
- Confident Adaptive Language Modeling cites Language Models are Few-Shot Learners
Cited by top-tier papers104
- Learning to Compress Prompts with Gist TokensJesse Mu, Xiang Li, Noah D. GoodmanNeurIPS 2023 · 488 citations
- Scaling up Test-Time Compute with Latent Reasoning: A Recurrent Depth ApproachJonas Geiping, Sean McLeish, Neel Jain, John Kirchenbauer et al.NeurIPS 2025 · 431 citations
- Generating Images with Multimodal Language ModelsJing Yu Koh, Daniel Fried, Russ SalakhutdinovNeurIPS 2023 · 403 citations
- Confident Adaptive Language ModelingTal Schuster, Adam Fisch, Jai Gupta, Mostafa Dehghani et al.NeurIPS 2022 · 394 citations
- Autoformalization with Large Language ModelsYuhuai Wu, Albert Qiaochu Jiang, Wenda Li, Markus N. Rabe et al.NeurIPS 2022 · 364 citations
Builds on21
- Language Models are Few-Shot LearnersTom B. Brown, Benjamin Mann, Nick Ryder, Melanie Subbiah et al.NeurIPS 2020 · 64,255 citations
- Retrieval-Augmented Generation for Knowledge-Intensive NLP TasksPatrick Lewis, Ethan Perez, Aleksandra Piktus, Fabio Petroni et al.NeurIPS 2020 · 19,162 citations
- Big Bird: Transformers for Longer SequencesManzil Zaheer, Guru Guruganesh, Kumar Avinava Dubey, Joshua Ainslie et al.NeurIPS 2020 · 3,159 citations
- Retrieval Augmented Language Model Pre-TrainingKelvin Guu, Kenton Lee, Zora Tung, Panupong Pasupat et al.ICML 2020 · 2,937 citations
- Reformer: The Efficient TransformerNikita Kitaev, Lukasz Kaiser, Anselm LevskayaICLR 2020 · 2,878 citations
Related papers
- FictionalQA: A Dataset for Studying Memorization and Knowledge AcquisitionJohn Kirchenbauer, Natjanan Mongkolsupawan, Yuxin Wen, Tom Goldstein et al.ICLR 2026 · 1 citation
- Pre-training Limited Memory Language Models with Internal and External KnowledgeLinxi Zhao, Sofian Zalouk, Christian K. Belardi, Justin Lovelace et al.ICLR 2026 · 11 citations
- Why do Nearest Neighbor Language Models Work?Frank F. Xu, Uri Alon, Graham NeubigICML 2023 · 33 citations
- Generalization through Memorization: Nearest Neighbor Language ModelsUrvashi Khandelwal, Omer Levy, Dan Jurafsky, Luke Zettlemoyer et al.ICLR 2020 · 1,038 citations
- Decouple knowledge from paramters for plug-and-play language modelingXin Cheng, Yankai Lin, Xiuying Chen, Dongyan Zhao et al.ACL Findings 2023 · 4 citations
