mlsanityData to 24 Nov 2026

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

arXiv 2610.16798 ↗Submitted 12 Oct 2026cs.LG stat.MLcited by 0

On the map: LLM reasoning → Prompting and chain-of-thought reasoning also fits: Test-time compute and efficient thinking

Abstract (arXiv)

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 K-nearest-neighbor (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 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 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 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.

Key facts. No citing papers in the map yet (data through 24 Nov 2026). Placed in Prompting and chain-of-thought reasoning, one of 17 directions in LLM reasoning. Builds on 14 of its 57 references that are in the map. Submitted 12 Oct 2026.

Builds on

14 of 57 references.

Closest ancestors · 4

Same direction, newest first

  1. 2025Lower Bounds for Chain-of-Thought Reasoning in Hard-Attention Transformers4 Feb
  2. 2024Unveiling the Statistical Foundations of Chain-of-Thought Prompting Methods25 Aug
  3. 2023The Expressive Power of Transformers with Chain of Thought11 Oct
  4. 2022Least-to-Most Prompting Enables Complex Reasoning in Large Language Models21 May

Other references · 10

  1. 2023GPT-4 Technical Reportcited by 19,416
  2. 2023LLaMA: Open and Efficient Foundation Language Modelscited by 14,771
  3. 2023Llama 2: Open Foundation and Fine-Tuned Chat Modelscited by 13,661
  4. 2025OpenAI GPT-5 System Cardcited by 1,090
  5. 2024Sora: A Review on Background, Technology, Limitations, and Opportunities of Large Vision Modelscited by 502
  6. 2024Evaluation of OpenAI o1: Opportunities and Challenges of AGIcited by 135
  7. 2023Toward Understanding Why Adam Converges Faster Than SGD for Transformerscited by 64
  8. 2023Positional Description Matters for Transformers Arithmeticcited by 63
  9. 2024In-Context Learning of a Linear Transformer Block: Benefits of the MLP Component and One-Step GD Initializationcited by 35
  10. 2026Looped Transformers with Layer Normalization Provably Learn the Power Methodcited by 4

Built on by

Not cited yet.

Similar, not cited

Close in wording, no citation either way

  1. 2024Transformers Provably Solve Parity Efficiently with Chain of Thought
  2. 2026Transformers Provably Learn to Internalize Chain-of-Thought
  3. 2024Training Nonlinear Transformers for Chain-of-Thought Inference: A Theoretical Generalization Analysis
  4. 2025Transformers Provably Learn Chain-of-Thought Reasoning with Length Generalization
  5. 2024From Sparse Dependence to Sparse Attention: Unveiling How Chain-of-Thought Enhances Transformer Sample Efficiency
  6. 2025Transformers Learn to Implement Multi-step Gradient Descent with Chain of Thought
  7. 2023Dissecting Chain-of-Thought: Compositionality through In-Context Filtering and Learning
  8. 2025Latent Chain-of-Thought? Decoding the Depth-Recurrent Transformer