[论文解读] Memorizing Transformers
本文在仅解码的 Transformer 上增添一个大型、非可微分的外部记忆,通过近似 kNN 进行访问,用以记忆并检索过去的输入,在跨多样化长上下文数据集的语言建模中取得改进。
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.
研究动机与目标
- 激励通过在推理时记忆过去输入来让语言模型获得新知识,而不是更新权重。
- 提出一种简单、可扩展的 kNN 增强注意力机制,从外部存储中检索精确记忆。
- 证明内存大小在多个长上下文领域和模型规模上能改善困惑度。
提出的方法
- 增加一个非可微分的外部记忆,对 (key, value) 对进行存储,该记忆会被前一步中模型生成的键/值更新。
- 在一个注意力层中,对每个查询在记忆中执行近似 kNN 查询,并通过学习得到的门控将记忆注意力与局部密集注意力结合。
- 采用 Transformer-XL 风格的缓存来维持持续上下文,以及滑动因果掩码以保持局部上下文。
- 对键和值进行归一化,以减轻训练步骤和记忆内容之间分布偏移导致的陈旧性。
- 使用近似 kNN 实现以平衡检索质量和计算效率,使内存大小达到数万个标记级别。)
实验结果
研究问题
- RQ1通过 kNN 访问的大型外部记忆是否能提升长篇文本和代码数据集的困惑度?
- RQ2内存大小如何影响性能,是否存在收益递减点?
- RQ3预训练模型是否能通过微调有效利用外部记忆,还是需要从头开始训练?
- RQ4模型在从记忆中检索时表现出哪些模式(例如函数名、定义、引理)?
主要发现
- 外部记忆在长篇数据集和架构上持续降低困惑度(例如长网页文本、书籍、代码和形式化证明)。
- 增大内存大小在非常大规模下仍然带来性能提升,特别是在代码和数学任务中。
- 一个门控机制使头部偏好外部记忆,从而在没有可微分记忆梯度的情况下实现有效的远程检索。
- 模型能够利用记忆回忆定义、引理和函数名,展示出用于形式化证明和代码的检索式行为。
- 微调预训练模型以利用记忆可以迅速缩小与记忆化训练制度的差距,表明具有实际应用性。
阅读本论文
在 Nubint 阅读器中打开原文,边读边就任意段落提问。
在 Nubint 中阅读本论文本解读由 AI 根据论文原文生成,引用前请核对原文。