arXiv:2505.15009cs.LGcs.AI2025-05

揭示Transformer在上下文记忆任务中的最优性与泛化能力

How Transformers Learn In-Context Recall Tasks? Optimality, Training Dynamics and Generalization

  • 证明带线性/ReLU/Softmax注意力的Transformer可达到贝叶斯最优
  • 梯度下降下损失以线性速度收敛至贝叶斯风险
  • 发现大模型因参数化不当反而无法实现分布外泛化

我们研究了在上下文记忆任务中训练的Transformer的近似能力、收敛速度及收敛后行为——该任务要求识别上下文中一对标记间的相对位置关系。现有理论仅关注模型经过单步梯度下降后的上下文推理表现,尚未明确梯度下降过程中的收敛行为及其速率,也缺乏对单步上下文推理泛化能力的形式化分析。本文填补这些空白:首先证明具有线性、ReLU或Softmax注意力的一类Transformer在上下文记忆任务中可达到贝叶斯最优;通过有限样本分析表明,使用梯度下降训练时,期望损失以线性速率收敛至贝叶斯风险;此外,训练后的模型表现出分布外(OOD)泛化能力。理论结果得到大量实验验证,显示若参数化不当,即使表达能力强的模型也无法在梯度下降后实现分布外泛化。

原文摘要 · Abstract (English)

We study the approximation capabilities, convergence speeds and on-convergence behaviors of transformers trained on in-context recall tasks -- which requires to recognize the \emph{positional} association between a pair of tokens from in-context examples. Existing theoretical results only focus on the in-context reasoning behavior of transformers after being trained for the \emph{one} gradient descent step. It remains unclear what is the on-convergence behavior of transformers being trained by gradient descent and how fast the convergence rate is. In addition, the generalization of transformers in one-step in-context reasoning has not been formally investigated. This work addresses these gaps. We first show that a class of transformers with either linear, ReLU or softmax attentions, is provably Bayes-optimal for an in-context recall task. When being trained with gradient descent, we show via a finite-sample analysis that the expected loss converges at linear rate to the Bayes risks. Moreover, we show that the trained transformers exhibit out-of-distribution (OOD) generalization, i.e., generalizing to samples outside of the population distribution. Our theoretical findings are further supported by extensive empirical validations, showing that \emph{without} proper parameterization, models with larger expressive power surprisingly \emph{fail} to generalize OOD after being trained by gradient descent.

Transformer泛化能力优化理论

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。