Manuscript Offprint
arXiv:2609.01311One-Layer Transformer Provably Learns Multiclass One-Nearest Neighbor in Context
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.
2.1 Theory for transformers' generalization
In-context learning (ICL) is the ability of a trained transformer to solve a new task from a handful of input/output examples placed in its prompt, without any updates to its weights (Bai et al., 2023).
*athreya1428@students.d211.org
Understanding how and why this behavior emerges from ordinary training is a central open problem in transformer theory, and a growing amount of work has aimed to investigate it in controlled settings.
One influential line of work casts ICL as implicitly running a learning algorithm on the in-context examples: e.g., Zhang et al. (2024) proves that the behavior of a single-layer attention model trained on linear-regression prompts provably converges to a predictor with provable in-distribution and distribution shift guarantees. In a similar vein, the one-nearest neighbor (Li et al., 2024) and our work show that transformers can implicitly act like a one-nearest neighbor algorithm.
2.2 Simplex encoding
Representing classes as vectors is an important algorithmic design choice which decides how to convert a classifier's real-valued output to a discrete decision. The simplex encoding assigns each class a vertex of a regular simplex, so that distinct classes are equidistant and symmetric.
Mroueh et al. (2012) introduced this coding for multiclass learning and analyzed its geometric properties. Later, Pouliot (2018) established equivalences between simplex-based methods and other multi-category support vector machine formulations (Lee et al., 2004). The simplex encoding has also been applied fruitfully in representation learning (Papyan et al., 2020).
2.3 Nearest neighbor algorithms
The nearest-neighbor algorithm is one of the oldest and most well-studied methods in classification. Cover and Hart (1967) established foundational results on its convergence properties, showing that the risk of the one-nearest-neighbor classifier is bounded above by twice the Bayes risk as the number of samples tends to infinity. Subsequent work established consistency and finite-sample rates for the -nearest-neighbor rule under margin and smoothness conditions: Chaudhuri and Dasgupta (2014) gives distribution-dependent, finite-sample rates in metric spaces and shows that under the Tsybakov margin condition the nearest-neighbor rate matches known lower bounds for nonparametric classification, and Efremenko et al. (2020) construct a Bayes-consistent classifier that keeps fast query time while attaining rates comparable to minimax. The margin event that controls our distribution-shift result (Section 4.1) plays a role akin to classical margin conditions, where performance is controlled precisely when queries are unlikely to fall close to a boundary between classes.
A separate line of work connects nearest-neighbor and kernel methods to attention. Tsai et al. (2019) formulate attention as a kernel smoother over the inputs, with the kernel scores given by input similarities. This perspective supports the equivalence between attention and the nearest-neighbor rule that we study.
Beyond its role in classical statistics, the nearest-neighbor rule has re-emerged as an important component of modern language models. Khandelwal et al. (2020) introduced NN-LM which is an “interpolation” of transformers and -nearest neighbor algorithms. Xu et al. (2023) analyzed why the retrieval-like component in NN-LM helps generalization. These results indicate that nearest-neighbor is a fruitful avenue to understanding transformer-based language models.
3 Setup and assumptions
Throughout this work, let be the number of labeled examples in a prompt (the context length) and the number of classes, both integers. Let . Moreover, let be the dimension of the input token.

Figure 1: Convergence (Theorem 1). Training loss (left) decreases and separated-test argmax accuracy (right) approaches 1, faster for smaller context length , matching the predicted dependence on . Bands are standard deviations over 8 seeds. See Section 5 for experimental details.
3.1 Problem Setup
An in-context learning instance consists of a prompt of labeled examples and a query , where each (the unit sphere in ) and each class label . The prompt and the query are known to the learner, while the label of the query is hidden from the learner. The objective is to predict .
Throughout we reserve for the binary label encoding used by Li et al. (2024) and write for a multiclass label in . For the given prompt, we define the index of the nearest neighbor to the query by
Thus, the one-nearest-neighbor (1-NN) predictor for the prompt is .
Simplex encoding. To represent classes as vectors, we use the simplex encoding (Mroueh et al., 2012), implemented as centered one-hot vectors:
where is the -th one-hot vector and is the all-ones vector. The vectors are the vertices of a regular simplex centered at the origin and satisfy:
• (zero mean) ,
• (constant norm) for each , and
• (constant inner product) for .
Consequently, the 's are equidistant with distance
These three properties are the only structural facts about the encoding that the convergence proof uses, and they act as the multiclass counterparts of the label encoding used in the binary case in (Li et al., 2024).

Figure 2: Scaling identity (Lemma 2). The measured ratio , estimated by sampling directly from the expected-version of the loss definitions, matches as a function of K (left) and is constant in (right).
Prompt Embedding. Following (Li et al., 2024), we embed the prompt and query as the following matrix
Note that the second row of , representing the labels, consists of columns that are -dimensional vectors, in contrast to that of (Li et al., 2024, Eq. (2.1)). Denote the columns of by , so that for and . We note that the query's label is since its label is unknown to the learner.
Model. The one-layer softmax attention model has a single weight matrix as parameter. The model takes as input and outputs
where the softmax is applied column-wise. Compared with (Li et al., 2024, Eq. (2.2)), which writes the attention score as with separate key and query matrices before merging them into a single matrix, we parametrize the model directly by the merged matrix , playing the role of : the model depends on the key and query matrices only through this product, and analyzing the merged matrix is the standard reduction in this line of work (Li et al., 2024; Zhang et al., 2024).
As in (Li et al., 2024), the value matrix is frozen to the identity, so each output token is a convex combination of the input tokens. The prediction is the K-dimensional vector obtained by taking the -st to -th rows of the last column of :
(4) where collects the prompt inputs and the query, and the attention weights are
The predicted class is produced by the standard argmax head
3.2 Assumptions on training distribution
Assumption 1 (Training distribution). The inputs are sampled i.i.d. from the uniform distribution on , and the class labels are sampled uniformly from , independently across tokens and of the inputs. We write for the resulting joint law of the instance .
Note that the following hold:
-
,
-
for , and
-
the law of is invariant under .
Expectations. An expectation or probability written without a subscript is always taken with respect to the training distribution of Assumption 1. Every other law carries an explicit subscript, as in (7) and Theorem 2.
Remark 1. Assumption 1 is the multiclass counterpart of the training distribution of (Li et al., 2024, Assumption 1), adopted for the same reasons. Because the labels are independent of the inputs, the prompt contains no parametric relationship between x and c that the model could exploit instead. The only way to reduce the loss is to retrieve the label of the nearest context example.
The task is nonetheless nontrivial: each prompt induces a geometrically complicated partition of the sphere. Moreover, the resulting objective is nonconvex (we show this in Lemma 5). Moreover, the analysis uses Assumption 1 only through properties 1,2, and 3, which decouple the label codes from the attention dynamics and force the off-diagonal gradient blocks to vanish.
Assumption 2 (Initialization). For a parameter , gradient descent is initialized at
that is, every entry vanishes except the final diagonal entry, which equals and suppresses the query's self-attention.
The initialization will be exploited as follows. First, the entry plays the role of the masking used in practical self-attention training, by suppressing the query's attention to its own token, whose label slot is , so that attention concentrates on the labeled context examples. (Li et al., 2024) motivate the same initialization this way, with playing the role of a mask value that is effectively set to infinity in practice.
Second, it is similar to Trockman and Kolter (2023), who observe that in pretrained transformers the merged key-query product has a dominant positive diagonal, approximately a scaled identity, and show that imposing this structure at initialization improves trainability. Gradient descent started at remains on the “diagonal family” with increasing, as shown in the appendix, so the trained key-query block remains a multiple of the identity throughout training.
Training. We train with gradient descent on the expected (population) mean-squared error between the logits and the simplex code of the 1-NN label,
initialized according to Assumption 2.
4 Main results
This section presents our main theoretical results. Omitted proofs are all included in the appendix. The analysis reduces the dynamics to a two-parameter family of weight matrices, which Assumption 2 initializes and which gradient descent provably preserves.
Lemma 1 (Two-parameter reduction). Under Assumptions 1 and 2 there exist real sequences and with for all . Moreover the blocks , which multiply the query's zero label block, have identically vanishing gradient, so the loss does not depend on them at any point of the parameter space.
Write for the loss (7) restricted to this 2-parameter space. Next, we briefly recall the binary case from (Li et al., 2024). Let be the binary objective from (Li et al., 2024, Eq. 2.5), which we recall below.
For the binary case, the prompt and query are the same as in Assumption 1. The simplex codes are however replaced by scalar labels drawn uniformly and independently of the inputs, the logit is a scalar, and the target is , so that
The attention weights are identical in the two models, because by Lemma 1 they depend on the inputs only through their inner products and not on any label.
Now, the two losses are related by the identity:
Lemma 2 (Scaling identity). On the two-parameter family, . Consequently for .
Every increment bound in the convergence analysis is therefore the binary bound scaled by . The factor rescales the growth of but cancels in the ratio that controls the trajectory.
Theorem 1 (Convergence). Suppose Assumptions 1 and 2 hold with and
where . These are the conditions of (Li et al., 2024, Theorem 1), which we inherit unchanged. Then gradient descent on (7) satisfies
so converges to 0 as .
4.1 Behavior Under Distribution Shift and the Argmax Head
For define the event
which captures the set of instances with large margin.
Theorem 2 (Distribution shift). Let be any distribution over instances supported on with labels in . After steps of gradient descent,
Remark 2 (Training vs. test distributions). Here is a distribution over the entire instance . Beyond the stated “supported on ” conditions, no independence is assumed between inputs and labels, or across tokens, and no relation to is assumed. This mirrors (Li et al., 2024, Assumption 3). The label boundedness required there holds automatically here since .
A guarantee under an arbitrary is possible because the underlying estimate is pointwise rather than distributional: training on produces the fixed parameters , and on the event the deviation admits a deterministic bound, decaying in and , which holds for every prompt-query configuration on the sphere (the pointwise bound is derived in the appendix). The test distribution enters only through , the probability that the query falls within of a 1-NN decision boundary.
Corollary 1 (Argmax classification). Under the setting of Theorem 2,
Moreover, if for some , then almost surely once .
(Li et al., 2024, Theorem 1) print the middle term with exponent 1/d. Since , the logarithm is then applied to a negative number. We state the well-posed form with exponent -1/d, which is the quantity their Lemma 12 identifies this condition with, namely up to constants.

Figure 3: Distribution shift (Theorem 2) and argmax classification (Corollary 1). On the separated test distribution the logit MSE (left) and the argmax matches the 1-NN label (right). The uniform-data accuracy is shown for contrast.
5 Experiments
We validate the theory with six experiments. Complete configurations and code to reproduce all experimental results are available at https://github.com/skandaka/onenn-multiclass. Compute environment is listed in Section D.
Protocol. All experiments use the one-layer attention model of (3) with the score , the centered one-hot vector encoding (1), and the loss (7). Training data follows Assumption 1 (inputs i.i.d. uniform on , labels uniform on ), and is initialized as in Assumption 2. We run stochastic gradient descent on minibatch estimates of (7) with analytical gradients, which we verify against finite differences in double precision to relative error . Training runs in PyTorch (Paszke et al., 2019).
The theory analyzes gradient descent on the population objective (7). The minibatch updates are a stochastic approximation of the population gradient. (Li et al., 2024) likewise validate their theory with stochastic gradient descent, in a less restrictive setting still with random initialization whereas we retain the initialization of Assumption 2. Unless stated otherwise, d = 8, N = 16, , learning rate , and batch size 128.
Additionally, we evaluate on a well-separated test distribution, extending the construction of (Li et al., 2024, Appendix B) to classes, which places the query strictly closer to examples of a single class than to all others, so that for a fixed margin , matching the setting of Theorem 2 and Corollary 1.
Scaling identity (Figure 2). We test Lemma 2 directly. The identity is an exact identity between two population expectations that admit no closed form, so we verify it by estimating both sides directly from their definitions. For fixed , we sample prompts and queries from Assumption 1, estimate and on this sample, and plot their ratio.
At the measured ratio traces over (80000 samples per point, left), and it is constant over the grid for (40000 samples per point, right), with deviations within error tolerance confirming Lemma 2.

Figure 4: Convergence holds for every (left), with final separated-test accuracy 1 across (right).

Figure 5: Perturbed initialization. Left: final separated-test argmax accuracy against the noise scale , with the two block-restricted ablations at . Right: distance from the two-parameter family of Lemma 1 over training, for the blocks that enter the attention scores.
Convergence (Figure 1). We train with and context lengths for steps and 8 random seeds. The training loss decreases towards zero at the slow logarithmic rate of Theorem 1, more slowly for larger , consistent with the poly dependence of the bound (left). Argmax accuracy on the separated test distribution rises from the random-guess baseline to 1 (right). Bands show standard deviations over the seeds.
Distribution shift and the argmax head (Figure 3). For we train for steps and 6 random seeds, and evaluate on the separated distribution, which differs from the training distribution but satisfies the margin condition. The logit error decays toward zero (left) and argmax accuracy reaches 1 (right), as Theorem 2 and Corollary 1 predict.
On uniform test data, on the other hand, accuracy plateaus below 1: a constant fraction of queries falls near a 1-NN decision boundary, so does not vanish for any fixed and the second term of the bound in Theorem 2 remains. We note that the plateau is as predicted by the

Figure 6: Loss function. Left: separated-test argmax accuracy over training for and for squentropy. Right: final accuracy on the separated and uniform test distributions across the family.
theory.
Dependence on the number of classes (Figure 4). We vary , training for steps and 4 random seeds. Convergence holds for every : the prefactor shifts the loss curves but leaves the logarithmic rate unchanged (left), and the final separated-test accuracy is 1 for every (right). The guarantees of Theorem 1 and Corollary 1 are therefore uniform in the number of classes.
Dependence on the diagonal initialization (Figure 5). Assumption 2 prescribes an exactly diagonal , which has precedent in the mimetic initialization of (Trockman and Kolter, 2023). We test how far the 1-NN phenomenon depends on it by adding i.i.d. noise to every entry of and sweeping , training for steps and 3 random seeds at each value.
Alongside accuracy we track the distance from the two-parameter family of Lemma 1, that is where projects onto (Figure 5 right).
The separated-test argmax accuracy is 1.000 for every , degrades at ( ) and fails at ( ), so the guarantee survives perturbations up to roughly the scale of the mask entry itself.
We observe first that, wherever the result survives, the distance to the family contracts over training, to about a third of its initial value (1.056 → 0.343 at and 10.558 → 3.449 at ); where it fails, the contraction weakens to 0.79 (31.673 → 25.145 at ). Lemma 1 states that the family is invariant under gradient descent, and this indicates that it is also locally attracting: the trajectory returns to the diagonal structure rather than merely remaining on it. Moreover, failing to return to the diagonal structure seems to imply failing to learn the 1-NN rule.
Second, we observe that the component of the perturbation lying in is unchanged to three decimal places throughout training (5.400 5.400 at ), as the identically zero gradients established in Lemma 1 require. Consistently, noise of magnitude confined to those blocks leaves the accuracy at 1.000, while the same magnitude confined to the remaining blocks reproduces the failure (0.44).
Dependence on the loss function (Figure 6). The analysis thus far (and also in (Li et al., 2024)) is specific to the square loss: Lemma 2 is an identity between coordinatewise expansions of (7) and has no cross-entropy analogue. We test whether the one-nearest-neighbor phenomenon extends to “convex-combination” losses of the form
interpolating from the square loss at to cross entropy at . We also test against the “squentropy” loss of (Hui et al., 2023),
Unlike the convex-combination losses above, the squentropy loss has no tunable parameter. Both families are trained for steps and 3 random seeds, using the same hyperparameters as in the square-loss experiments.
The separated-test argmax accuracy is 1.000 for every and for squentropy, and at , so the recovery of the 1-NN label does not depend on the choice of loss. On uniform test data the accuracy increases mildly and monotonically with , from 0.908 at to 0.924 at , with squentropy at 0.916.
Recall that the square-loss gradient when , whereas the cross-entropy gradient never vanishes. Training under cross entropy therefore continues to boost attention on the nearest neighbor, reducing the near-boundary errors seen in the uniform-data plateau.
Taken together, our result shows that the one-nearest-neighbor phenomenon is robust to changing the loss function. While our theory covers the square loss only, an interesting line of future work will analyze the cross entropy.
6 Discussion, Limitations, and Future Work
We have rigorously shown the equivalence between a one-layer softmax attention model and the one-nearest-neighbor rule, extending the binary setting result by Li et al. (2024). We show that the convergence rate, the conditions on and , and the distribution-shift guarantee all carry over without -dependence.
We discuss several limitations in and future directions of this work. The analysis exploits the one-layer architecture and the special diagonal initialization of Assumption 2. While these restrictions have precedent in the literature (e.g., in (Trockman and Kolter, 2023)) an interesting avenue of future research is to remove these restrictions.
Our experiments show the one-nearest-neighbor phenomenon persists after switching the loss function from square loss to squentropy. It will be interesting to develop a rigorous theory to explain this phenomenon. The scaling identity is specific to the square loss and has no cross-entropy analogue, though the empirical behavior does not depend on that choice.
Finally, the guarantee concerns recovery of the 1-NN rule for a single head. Extending the argument to multiple heads is a natural next step.
References
Yu Bai, Fan Chen, Huan Wang, Caiming Xiong, and Song Mei. Transformers as statisticians: Provable in-context learning with in-context algorithm selection. Advances in neural information processing systems, 36:57125–57211, 2023.
Kamalika Chaudhuri and Sanjoy Dasgupta. Rates of convergence for nearest neighbor classification. In Advances in Neural Information Processing Systems (NeurIPS), volume 27, 2014.
Thomas Cover and Peter Hart. Nearest neighbor pattern classification. IEEE transactions on information theory, 13(1):21–27, 1967.
Klim Efremenko, Aryeh Kontorovich, and Moshe Noivirt. Fast and Bayes-consistent nearest neighbors. In International Conference on Artificial Intelligence and Statistics (AISTATS), pages 1276–1286. PMLR, 2020.
Like Hui, Mikhail Belkin, and Stephen Wright. Cut your losses with squentropy. In Proceedings of the 40th International Conference on Machine Learning, pages 14114–14131. PMLR, 2023.
Urvashi Khandelwal, Omer Levy, Dan Jurafsky, Luke Zettlemoyer, and Mike Lewis. Generalization through memorization: Nearest neighbor language models. In International Conference on Learning Representations (ICLR), 2020.
Yoonkyung Lee, Yi Lin, and Grace Wahba. Multicategory support vector machines: Theory and application to the classification of microarray data and satellite radiance data. Journal of the American Statistical Association, 99(465):67–81, 2004.
Zihao Li, Yuan Cao, Cheng Gao, Yihan He, Han Liu, Jason M. Klusowski, Jianqing Fan, and Mengdi Wang. One-layer transformer provably learns one-nearest neighbor in context. In Advances in Neural Information Processing Systems, volume 37, pages 82166–82204, 2024.
Youssef Mroueh, Tomaso Poggio, Lorenzo Rosasco, and Jean-Jacques Slotine. Multiclass learning with simplex coding. Advances in Neural Information Processing Systems, 25, 2012.
Vardan Papyan, XY Han, and David L Donoho. Prevalence of neural collapse during the terminal phase of deep learning training. Proceedings of the National Academy of Sciences, 117(40):24652–24663, 2020.
Adam Paszke, Sam Gross, Francisco Massa, Adam Lerer, James Bradbury, Gregory Chanan, Trevor Killeen, Zeming Lin, Natalia Gimelshein, Luca Antiga, Alban Desmaison, Andreas Kopf, Edward Yang, Zachary DeVito, Martin Raison, Alykhan Tejani, Sasank Chilamkurthy, Benoit Steiner, Lu Fang, Junjie Bai, and Soumith Chintala. Pytorch: An imperative style, high-performance deep learning library. In Advances in Neural Information Processing Systems, volume 32, 2019.
Guillaume Pouliot. Equivalence of multicategory SVM and simplex cone SVM: Fast computations and statistical theory. In International conference on machine learning, pages 4133–4140. PMLR, 2018.
Asher Trockman and J. Zico Kolter. Mimetic initialization of self-attention layers. In International Conference on Machine Learning (ICML), pages 34456–34468. PMLR, 2023.
Yao-Hung Hubert Tsai, Shaojie Bai, Makoto Yamada, Louis-Philippe Morency, and Ruslan Salakhutdinov. Transformer dissection: An unified understanding for transformer's attention via the lens of kernel. In Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing and the 9th International Joint Conference on Natural Language Processing (EMNLP-IJCNLP), pages 4344–4353, 2019.
Frank F. Xu, Uri Alon, and Graham Neubig. Why do nearest neighbor language models work? In International Conference on Machine Learning (ICML), pages 38325–38341. PMLR, 2023.
Ruiqi Zhang, Spencer Frei, and Peter L. Bartlett. Trained transformers learn linear models in-context. Journal of Machine Learning Research, 25(49):1–55, 2024.
A Proof of the Convergence Theorem
We prove Theorem 1 as follows.
Lemma 3 (Properties of the simplex code). Under Assumption 1, the simplex codes defined in (1) satisfy
Proof. For (i), the labels are independent of the inputs and the classes are equally likely, so . For (ii), and are independent for and both are independent of , so by (i). For (iii), for any class ,
which is independent of c.
A.1 Closed-Form Gradient
Lemma 4 (Closed-form gradient). Under Assumptions 1 and 2, for all ,
for scalar-valued functions of one real variable, and for every block except and .
Proof. We induct on . The form holds at by Assumption 2. Assume it holds at step , so that . Using , the score of (3) reduces to for and to for the query, so the attention weights take the scalar form
for , with in the numerator for . Below we abbreviate . This is the multiclass counterpart of (Li et al., 2024, Eq. (C.9)).
The consequence used repeatedly below is that no label code appears in (11): each is a measurable function of alone. Hence for any function of the labels and any ,
by the tower property: the weights may be taken outside the inner expectation, which is then evaluated by Lemma 3. This step is the only place where the independence of the labels from the inputs in Assumption 1 is used.
Partition conformally with ,
with , , , and for , . Since , the score expands as
We treat the blocks in three groups.
(i) The blocks . These do not occur in (13): they multiply the second block of , which is . Every score, hence every attention weight, hence , is therefore constant in these blocks, and identically — not merely at the initialization. This is the multiclass form of the observation that the label-to-output column does not influence the prediction (Li et al., 2024, Section 2.2).
(ii) The blocks . By (13) these enter every score linearly, so by the chain rule each gradient is an expectation of the form with weights built from the and the residual , and with ; this is the counterpart of (Li et al., 2024, Eqs. (C.4)–(C.6)). Applying (12) and Lemma 3 term by term: a monomial containing a code whose label appears exactly once has conditional expectation by Lemma 3(i); a monomial containing reduces to the constant by Lemma 3(iii), leaving a residual factor that is again linear in a single code and so has zero mean; and a monomial containing two distinct codes has conditional expectation by Lemma 3(ii). Hence .
(iii) The block . By (13) it appears only in the term , that is, only in the query's own score, contributing to the gradient. Under the induction hypothesis the weights are given by (11) and are therefore even in , while is odd; since the input law is invariant under (Assumption 1, property 3), the expectation vanishes. This argument uses no label structure and is identical to the binary case. The indicator block has a partial derivative of 1 with respect to the query's self-attention score, guaranteeing a non-zero update during gradient descent:
(14)
Expanding and using Lemma 3 to discard the label terms leaves (10), in which the inputs enter only through inner products. By (Li et al., 2024, Lemma 7) (rotational invariance of the uniform distribution on ), such a gradient is a scalar multiple of the identity, . With this gives , completing the induction.
A.2 Two-Dimensional Reduction
Proof of Lemma 1. The claim is the diagonal form established in the induction of Lemma 4; it remains to be seen why the label block does not contribute free parameters. At initialization by Assumption 2. By the structural-zero argument above, multiplies the query's (zero) label rows in every score, so at every step; a block that starts at zero and receives a zero gradient stays at zero. Thus, although the ambient dimension grows from to , the trajectory explored by gradient descent is governed by the two scalars and , exactly as in the binary case.
A.3 The Scaling Identity
We now prove Lemma 2.
Proof of Lemma 2. By (7) and (4), expanding the squared norm over coordinates,
with the input-only weights of (11). Expanding the square gives a quadratic term, a cross term, and a constant; we sum each over using Lemma 3. The quadratic term is , since by Lemma 3(iii) while distinct tokens are uncorrelated by Lemma 3(ii). The cross term contributes only through , giving in expectation. The constant term is . Each is exactly times the corresponding term of the binary-analog loss, in which gives and for . Therefore , and differentiating gives the gradient identity.
Lemma 5 (Nonconvexity). The reduced loss is nonconvex.
Proof. By Lemma 2, with . The original binary reduced loss is nonconvex (Li et al., 2024, Appendix E), and a positive scalar multiple of a nonconvex function is nonconvex; this is why is nonconvex, and why the trajectory analysis below is needed.
A.4 Evolution of the Two Parameters
Each bound below is the binary estimate of (Li et al., 2024) multiplied by via Lemma 2. The constants , , , , and are inherited unchanged from the sphere geometry estimates (Li et al., 2024, Lemmas 17–20), which have no labels.
Lemma 6 (Increment bounds for ). For , there exist constants such that
Proof. By Lemma 1 the update is , and from Lemma 2 we have . Applying (Li et al., 2024, Lemma 4) to the binary gradient gives both inequalities.
Lemma 7 (Increment bounds for ). For , there exist constants such that
Proof. The update is , with by Lemma 2, and (Li et al., 2024, Lemma 5) bounds the binary gradient. In particular the parameter updates follow the recurrence relation with , so and . Note that the factor , like the step size , is absorbed into and therefore contributes only an additive to ; since , this offset is bounded uniformly in and does not affect the rate.
Lemma 8 (Combined lower bound). For all ,
Proof. The left-hand side equals by Lemma 2, to which (Li et al., 2024, Lemma 8) applies. The binary estimate uses only and the constant from (Li et al., 2024, Lemma 17), both unchanged by .
Lemma 9 (Sharp upper bound for the increment). For and ,
Proof. Apply Lemma 2 to (Li et al., 2024, Lemma 9); the constant comes from the sphere tail bound (Li et al., 2024, Lemma 19) and is unchanged.
Lemma 10 (Refined lower bound for the increment). For ,
Proof. Combine times Lemma 8 with 2 times the upper bound of Lemma 9; the common factor factors out.
Lemma 11 (Sharp lower bound for the increment). For ,
Proof. The binary proof bounds ; by Lemma 2 the multi-class quantity acquires . The remaining estimates — the concentration bound , which holds with probability at least by (Li et al., 2024, Lemma 19), and — involve only geometry and are unchanged.
A.5 Ratio Bound and Growth Rates
Lemma 12 (Ratio bound). If and for all , then for all .
Proof. By Lemma 9, the increment is nonpositive once
The factor cancels from both sides, so the resulting condition on is exactly the threshold comparison of the binary analysis: no label code enters it, and it involves only the two scalars and the sphere constant . Under the stated bound on , (Li et al., 2024, Lemma 12) shows that the condition is met whenever , so there. Hence cannot grow past ; since does not decrease by Lemma 11, the bound holds for all . Only for some constant is used downstream, in Theorem 1 and Theorem 2.
Lemma 13 (Growth rates). With and as in Theorem 1, , with for all .
Proof. For , Lemmas 7 and 11 bound the increment between two exponentially decaying rates, ; comparison with the corresponding continuous flow gives , the factors and contributing only a bounded additive offset. For , Lemma 10 gives while . This condition holds through an initial phase because is large and increases. During that phase grows logarithmically, and the upper bound of Lemma 9 caps it at . Hence . The bound is Lemma 12.
Proof of Theorem 1. By Lemma 2 applied to the binary loss bound (Li et al., 2024, Lemma 14), the multiclass loss obeys
Substituting the growth rates of Lemma 13, the first term is , and since by Lemma 12 gives , the second term decays as . Both vanish as , which is the bound of Theorem 1.
B Distribution Shift and Argmax Classification
We prove Theorem 2 and Corollary 1. Throughout, and . By the convergence analysis, is diagonal with x-block and indicator entry , so the attention weights depend on the inputs only through inner products:
for .
Proof of Theorem 2. Since the query contributes to (4), we have and . Writing the target as and grouping,
(16) where the terms with cancel because . Taking norms in (16) and using and ,
On the event of (9), every with satisfies . Since on the sphere, this is equivalent to . Hence, from (15) and ,
(18)
For the self-attention weight, , and by the convergence analysis , so and
Combining (17), (18), and (19),
uniformly on . By Lemma 13, , so both terms are .
It remains to take expectations. Splitting on and its complement, and using as a hard uniform bound on (every and ),
Since for every , the first term also carries the factor after absorbing the constants and a further factor of two. Taking the infimum over gives the claim.
Lemma 14 (Argmax margin). For any and any class , if then .
Proof. Because , the hypothesis gives for every coordinate . The code has entry and for , so
Subtracting, for every ,
Thus strictly exceeds every other coordinate, so the argmax is c.
Proof of Corollary 1. Taking the contrapositive of Lemma 14 with ,
By Markov's inequality,
Applying Theorem 2 and noting bounds the right-hand side by , which is the first claim.
For the second claim, suppose . Then (20) holds almost surely, so almost surely. By Lemma 14, the argmax is correct as soon as this bound falls below , i.e. once .
C Auxiliary Sphere-Geometry Results
The convergence proof has several facts about the uniform distribution on . None of them involve the labels, so they are identical to their counterparts in the binary analysis. We state them here for completeness and refer to (Li et al., 2024) for the proofs, which are unchanged.
Lemma 15 (Rotational invariance: (Li et al., 2024, Lemmas 6-7)). If are i.i.d. uniform on , then their joint law is invariant under any orthogonal matrix . Consequently, if is diagonal with -block , the gradient is a scalar multiple of .
Lemma 16 (Inner-product density: (Li et al., 2024, Lemma 17)). Let for a fixed unit vector and a uniform . Then has density on , where .
Lemma 17 (Expected nearest-neighbor alignment: (Li et al., 2024, Lemma 18)). If , then , where .
Lemma 18 (Concentration of the nearest-neighbor alignment: (Li et al., 2024, Lemma 19)). With as above and as in Lemma 16,
Equivalently, with the constant used in Lemmas 9 and 11, the gap satisfies with probability at least ; that is, lower bounds the separation of the nearest neighbor from the query with constant probability. Note , so the two forms agree up to constants.
Lemma 19 (Order-statistic gap: (Li et al., 2024, Lemma 20)). Let and be the largest and second-largest of . Then, for ,
D Compute Environment
All experiments were conducted on a single workstation running Linux (kernel 6.8.0-58-generic) with glibc 2.39. The system was equipped with a 16-core (32-thread) CPU, 128 GB of RAM, and one NVIDIA RTX 5000 Ada Generation GPU.