arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2610.16798cs.LGstat.ML
收藏

单层Transformer可通过思维链(Chain-of-Thought, CoT)证明性地学习上下文K近邻(K-Nearest Neighbor, K-NN)预测

One-Layer Transformers Provably Learn In-Context K-Nearest Neighbor Prediction with Chain-of-Thought

School of Computing & Data Science, The University of Hong Kong(香港大学计算机与数据科学学院)

Lyumin Wu, Yuan Cao

AI总结:

本研究针对单层Transformer,从理论上证明其可通过思维链(CoT)学习上下文K近邻(K-NN)预测,明确了softmax注意力在K>1时的局限,且梯度下降可训练出能解决K-NN的模型,拓展了Transformer的任务解决能力。

摘要:

思维链(CoT)使Transformer能够通过生成中间推理步骤解决复杂推理任务。尽管在经验上取得了显著成功,但这种推理能力在训练过程中如何产生的机制,尤其是从理论角度来看,仍知之甚少。在本研究中,我们在一个风格化但完全可分析的设定下研究该问题:使用单层Transformer进行上下文K近邻(K-NN)预测。早期研究(Li等人,2024a)表明,单层Transformer可在不使用CoT的情况下被训练执行1-NN任务,其原理是softmax注意力机制会关注上下文中的最近邻。然而,这一1-NN的结果无法扩展到K>1的K-NN任务,因为softmax注意力机制并不太适合关注第2到第K近邻。我们首先给出一个严格的负面结果,表明对于奇数K>1,这种限制在一类分离良好的二分类任务中已经存在。随后,我们给出单层Transformer的显式构造,并证明它可通过CoT推理解决K-NN问题。我们进一步证明,在风格化训练设定下,梯度下降可恢复该构造,从而表明Transformer可通过训练获得解决K-NN的能力。此外,我们还表明,得到的训练模型适用于比训练分析中所假设的更广泛的测试类别。我们的结果阐明了CoT如何扩展Transformer学习和解决原本难以解决的任务的能力。

英文摘要:

Chain-of-Thought (CoT) enables transformers to solve complex reasoning tasks by generating intermediate reasoning steps. Despite strong empirical success, the mechanisms by which such reasoning abilities emerge during training remain poorly understood, particularly from a theoretical perspective. In this work, we study this question in a stylized yet fully analyzable setting: in-context $\mathrm{K}$-nearest-neighbor ($\mathrm{K}$-NN) prediction with a one-layer transformer. Earlier work has demonstrated that one-layer transformers can be trained to perform $1$-NN without CoT (Li et al., 2024a) by having the softmax attention attend to the nearest neighbor in context. However, this result on $1$-NN cannot be extended to $\mathrm{K}$-NN for $K>1$, as softmax attention is much less naturally suited to attending to the 2nd through $K$-th nearest neighbors. We first give a rigorous negative result showing that this limitation already appears on a well-separated class of binary classification tasks for odd $K>1$. We then give an explicit construction of a one-layer transformer, and show that it can solve $\mathrm{K}$-NN via CoT reasoning. We further prove that, under a stylized training setup, gradient descent can recover this construction, thereby showing that transformers can acquire the capability to solve $\mathrm{K}$-NN through training. In addition, we show that the resulting trained model applies to a broader test class than that assumed in the training analysis. Our results shed light on how CoT expands the ability of transformers to learn and solve tasks that are otherwise hard to solve.

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

↑