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.
Center for Foundation Models and Generative AI & Department of Computer Science, Northwestern University, USA(基础模型与生成人工智能中心及计算机科学系,西北大学,美国);School of Mathematical Sciences, Fudan University(复旦大学数学科学学院);University of California, Berkeley, USA(加州大学伯克利分校,美国);Center for Foundation Models and Generative AI & Department of Computer Science & Department of Statistics and Data Science, Northwestern University, USA(基础模型与生成人工智能中心及计算机科学系与统计与数据科学系,西北大学,美国)
Pause and Reflect: Conformal Aggregation for Chain-of-Thought Reasoning
Department of Mathematics and Statistics(数学与统计学系);McGill University(麦吉尔大学);Department of Mathematics and Industrial Engineering(数学与工业工程系);Polytechnique de Montréal(蒙特利尔理工学院)
Capabilities and Fundamental Limits of Latent Chain-of-Thought
Department of Mathematics and Statistics, Xi'an Jiaotong University(西安交通大学数学与统计学系);Department of Artificial Intelligence, Gaoling School of Artificial Intelligence, Renmin University of China(中国人民大学人工智能学院)
Google Research(谷歌研究);TReNDS Center, Georgia State University(TReNDS中心,佐治亚州立大学);Maynooth University(迈诺特大学);Georgia State University/Georgia Institute of Technology/Emory University Center for Translational Research in Neuroimaging and Data Science (TReNDS Center)(佐治亚州立大学/佐治亚理工学院/埃默里大学神经影像与数据科学转化研究中心(TReNDS中心));Department of Computer Science, Maynooth University(迈诺特大学计算机科学系)
Make Still Further Progress: Chain of Thoughts for Tabular Data Leaderboard
School of Artificial Intelligence, Nanjing University, China(人工智能学院,南京大学);National Key Laboratory for Novel Software Technology, Nanjing University(新型软件技术国家重点实验室,南京大学)