scimeatlas

Research map / Architectures and efficiency / Attention and transformers

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

Lyumin Wu, Yuan Cao

NeurIPS 2026Architectures and efficiency › Attention and transformersapproach: Transformer expressivity and learnabilityopen problems in this approach0 citations (OpenAlex)

The University of Hong Kong

Read the paperPlace an idea next to itCheck your own paper ↗

In one sentence

Shows a one-layer softmax transformer cannot solve odd-K nearest-neighbor by direct inference but can via chain-of-thought with iterative token selection and masking, and that gradient descent from zero init recovers this construction.

AI-extracted summary. Written by AI from the paper's full text. Numbers and claims can be wrong or missing context, so check the paper before you cite or build on it.

Problem

Whether one-layer transformers can learn in-context K-nearest-neighbor prediction (K>1), which direct inference cannot do for odd K, and how chain-of-thought enables it and training recovers it.

Approach

Reformulates K-NN as a sequential procedure: each CoT step softmax-attends to the next unretrieved nearest neighbor, using positional encodings to penalize previously selected tokens (via a sharp-attention limit), and proves gradient descent from zero initialization converges to this sharp-attention parameter pattern.

Key results

Surprising findings

  • Direct inference by a one-layer softmax transformer provably fails for odd K>1 even on well-separated instances, while the same architecture succeeds with CoT.

Limitations

  • Frozen value matrix V and simplified merged-key-query one-layer architecture in training analysis
  • Population-loss training with one-step state supervision and synthetic data; not finite-sample
  • Experiments use random initialization and SGD, deviating from the theorem setup

Open problems this paper states

Open problems in Transformer expressivity and learnability

Do theorems about transformer expressivity and learning still hold for deep, softmax, trained models?

All 3 open problems and what was already tried →

Experimental setup

Datasets: synthetic K-NN data on unit sphere with Rademacher labels

Benchmarks: synthetic well-separated K-NN test set (size 1000, margin 0.1)

Metrics: test accuracy training loss

Baselines: direct-inference one-layer transformer (K=3, K=5) Li et al. 2024a 1-NN construction

Builds on: Li et al. 2024a in-context 1-NN with one-layer transformer Wang et al. 2024 sparse token selection with stochastic positional encodings Huang et al. 2025a CoT linear regression Yang et al. 2025 CoT path finding

Closest papers by meaning

Writing a paper in this area? scime draft is a free LaTeX editor with AI included, real-time co-authors and a check of your references and venue rules before you submit. It also imports OpenAI Prism projects.

Open scime draft

Get the next scime Dispatch and a monthly field update

Free. We send a confirmation link first; every email has a one-click unsubscribe. Privacy