arXiv:2609.01311cs.LGSep 2026

Manuscript Offprint

arXiv:2609.01311

One-Layer Transformer Provably Learns Multiclass One-Nearest Neighbor in Context

Skanda Athreya, Yutong Wang

Abstract

We extend recent work establishing an equivalence between one-layer transformers and nearest-neighbor classifiers in the binary setting to the multiclass case. By leveraging the simplex encoding, we show that one-layer transformers with an argmax classification head behave identically to a one-nearest-neighbor classifier in the multiclass setting. This closes a gap left by prior work, whose multiclass result relied on a non-standard rounding-based approach rather than the typical argmax head used in practice.

Code: https://github.com/skandaka/onenn-multiclass

1 Introduction

Transformers have become the dominant architecture in large language models and other applications such as computer vision. Understanding the theoretical properties of transformers is therefore of considerable importance. A growing body of work studies theoretical properties of transformers, e.g., in the framework of in-context learning (Bai et al., 2023), and their connection to classical machine learning models such as nearest neighbors (Li et al., 2024).

Li et al. (2024) showed that one-layer transformers, under appropriate conditions, behave identically to a one-nearest-neighbor classifier. Their work is, however, limited to the binary classification setting. While they do provide a result with respect to a task resembling multiclass classification (Li et al., 2024, Corollary 1), the result is for a rounding-based approach that departs from the more standard argmax classification head used in practice.

In this work, we close this gap by leveraging the simplex encoding (Mroueh et al., 2012). We show that one-layer transformers with an argmax head are equivalent to one-nearest-neighbor classifiers in the multiclass setting. This is a natural and important extension, since the primary application of transformers (i.e., next-token prediction) is inherently a multiclass classification problem, and the argmax head is the standard mechanism for producing predictions.

References (31)