arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2212.07677cs.LGcs.AIcs.CL
收藏

Transformer通过梯度下降进行上下文学习

Transformers learn in-context by gradient descent

ETH Zürich(苏黎世联邦理工学院);Google Research(谷歌研究院)

Johannes von Oswald, Eyvind Niklasson, Ettore Randazzo, João Sacramento, Alexander Mordvintsev, Andrey Zhmoginov, Max Vladymyrov

AI总结:

本文证明Transformer的自注意力层与回归损失上的梯度下降在数据变换上等价,并通过实验表明训练后的Transformer在前向传播中成为mesa-optimizer,从而从机制上解释了上下文学习,还揭示了其超越普通梯度下降的原因及与induction-head机制的联系。

摘要:

目前,Transformer中上下文学习的机制尚未被充分理解,且大多停留在直觉层面。本文提出,在自回归目标上训练Transformer与基于梯度的元学习形式密切相关。我们首先给出一种简单的权重构造,证明由1)单个线性自注意力层和2)回归损失上的梯度下降(GD)所诱导的数据变换是等价的。受该构造启发,我们通过实验表明,当在简单回归任务上训练仅含自注意力的Transformer时,梯度下降学到的模型与Transformer学到的模型表现出高度相似性,或者更显著的是,优化得到的权重与构造相匹配。由此我们展示了训练后的Transformer如何成为mesa-optimizers,即在其前向传播中通过梯度下降来学习模型。这使我们至少在回归问题领域内能够从机制上理解优化后的Transformer中上下文学习的内部工作原理。基于这一认识,我们进一步识别出Transformer如何通过学习迭代曲率校正来超越普通梯度下降的性能,并在深度数据表示上学习线性模型以解决非线性回归任务。最后,我们讨论了与一种被认为对上下文学习至关重要的机制——induction-head(Olsson et al., 2022)——之间有趣的相似之处,并展示如何将其理解为Transformer内部通过梯度下降进行上下文学习的一个特例。复现实验的代码可在https://github.com/google-research/self-organising-systems/tree/master/transformers_learn_icl_by_gd找到。

英文摘要:

At present, the mechanisms of in-context learning in Transformers are not well understood and remain mostly an intuition. In this paper, we suggest that training Transformers on auto-regressive objectives is closely related to gradient-based meta-learning formulations. We start by providing a simple weight construction that shows the equivalence of data transformations induced by 1) a single linear self-attention layer and by 2) gradient-descent (GD) on a regression loss. Motivated by that construction, we show empirically that when training self-attention-only Transformers on simple regression tasks either the models learned by GD and Transformers show great similarity or, remarkably, the weights found by optimization match the construction. Thus we show how trained Transformers become mesa-optimizers i.e. learn models by gradient descent in their forward pass. This allows us, at least in the domain of regression problems, to mechanistically understand the inner workings of in-context learning in optimized Transformers. Building on this insight, we furthermore identify how Transformers surpass the performance of plain gradient descent by learning an iterative curvature correction and learn linear models on deep data representations to solve non-linear regression tasks. Finally, we discuss intriguing parallels to a mechanism identified to be crucial for in-context learning termed induction-head (Olsson et al., 2022) and show how it could be understood as a specific case of in-context learning by gradient descent learning within Transformers. Code to reproduce the experiments can be found at https://github.com/google-research/self-organising-systems/tree/master/transformers_learn_icl_by_gd .

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑