atlas

Research map / Architectures and efficiency / Attention and transformers

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

NeurIPS 2026 · Architectures and efficiency › Attention and transformers · approach: Transformer expressivity and learnability

Read the paperCheck your idea against 108,967 papers

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.

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.

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

Limitations

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