arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2409.10559cs.LGcs.AIcs.CLmath.OCstat.ML
收藏

揭示归纳头:Transformer中可证明的训练动力学与特征学习

Unveiling Induction Heads: Provable Training Dynamics and Feature Learning in Transformers

Yale University(耶鲁大学);Toyota Technological Institute at Chicago(芝加哥丰田理工学院)

Siyu Chen, Heejune Sheen, Tianhao Wang, Zhuoran Yang

AI总结:

该研究针对Transformer各模块对上下文学习的贡献不明确的问题,通过分析含相对位置嵌入等的两层注意力Transformer在n-gram马尔可夫链数据上的训练,证明梯度流收敛到由各模块协同实现的广义归纳头极限模型,并经实验验证。

摘要:

上下文学习(ICL)是大语言模型(LLM)功能的基石,但由于Transformer架构的复杂性,其理论基础仍不明确。具体而言,现有大多数工作仅从理论上解释了注意力机制在特定数据模型下如何促进ICL,目前尚不清楚Transformer的其他构建模块对ICL有何贡献。为解决这一问题,我们研究了两层注意力Transformer如何被训练以在$n$-gram马尔可夫链数据上执行ICL,该马尔可夫链中的每个标记在统计上依赖于前$n$个标记。我们分析了一个包含相对位置嵌入、多头softmax注意力和带归一化前馈层的复杂Transformer模型。我们证明,针对交叉熵ICL损失的梯度流会收敛到一个极限模型,该模型执行带有学习特征的广义归纳头机制,这一结果由所有构建模块协同贡献而成。在该极限模型中,第一层注意力充当“复制器”,将给定窗口内的过去标记复制到每个位置;带归一化的前馈网络充当“选择器”,仅通过查看窗口中信息相关的父节点来生成特征向量。最后,第二层注意力是“分类器”,将这些特征与输出位置的特征进行比较,并利用所得相似度分数生成期望输出。我们的理论进一步通过实验得到了验证。

英文摘要:

In-context learning (ICL) is a cornerstone of large language model (LLM) functionality, yet its theoretical foundations remain elusive due to the complexity of transformer architectures. In particular, most existing work only theoretically explains how the attention mechanism facilitates ICL under certain data models. It remains unclear how the other building blocks of the transformer contribute to ICL. To address this question, we study how a two-attention-layer transformer is trained to perform ICL on $n$-gram Markov chain data, where each token in the Markov chain statistically depends on the previous $n$ tokens. We analyze a sophisticated transformer model featuring relative positional embedding, multi-head softmax attention, and a feed-forward layer with normalization. We prove that the gradient flow with respect to a cross-entropy ICL loss converges to a limiting model that performs a generalized version of the induction head mechanism with a learned feature, resulting from the congruous contribution of all the building blocks. In the limiting model, the first attention layer acts as a $\mathit{copier}$, copying past tokens within a given window to each position, and the feed-forward network with normalization acts as a $\mathit{selector}$ that generates a feature vector by only looking at informationally relevant parents from the window. Finally, the second attention layer is a $\mathit{classifier}$ that compares these features with the feature at the output position, and uses the resulting similarity scores to generate the desired output. Our theory is further validated by experiments.

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

↑