Transformers can perform in-context classification from a few labeled examples, yet the inference-time algorithm remains opaque. We study multi-class linear classification in the hard no-margin regime and make the computation identifiable by enforcing feature- and label-permutation equivariance at every layer. This enables interpretability while maintaining functional equivalence and yields highly structured weights. From these models we extract an explicit depth-indexed recursion: an end-to-end identified, emergent update rule inside a softmax transformer, to our knowledge the first of its kind. Attention matrices formed from mixed feature-label Gram structure drive coupled updates of training points, labels, and the test probe. The resulting dynamics implement a geometry-driven algorithmic motif, which can provably amplify class separation and yields robust expected class alignment.
Figures & tables
Figure 1: Symmetry reveals coupled mean-shift inference in transformers. Left: Enforcing feature/label permutation symmetry layer by layer preserves the inference rule: we match predictions, response to query perturbations (local decision rule), and influential examples (context sensitivity). Middle: The symmetry constraint denoises weights into a canonical low-dimensional structure. Right: The resulting structure makes the forward pass readable as a closed-form iterative classifier (depth ↔ iterations), yielding a geometry-driven algorithmic motif in which features and labels co-evolve.
Figure 2: Learned weight matrices for the unconstrained transformer (left) and the symmetry-preserving transformer (right) trained on in-context linear classification. The unconstrained model exhibits little visible structure, whereas enforcing the task symmetries produces a more regular pattern that is easier to interpret. The top and bottom rows show WQK,ℓ and WVP,ℓ , respectively.
Figure 3: Transformer symmetrization preserves inference behavior. Left: The symmetrized transformer (S) matches the unconstrained (U): on the same prompt, U–S fingerprint matches the U–U baseline across query (local decision rule at the test point), context (which demonstrations drive the logits), and predictions, while the different-prompt control is near zero (mean over 2 048 tasks; averaged over 10 training runs; ± 1 s.d. across runs). Right: After averaging predictions across 5 training runs, U and S are functionally nearly identical: ground-truth-class probabilities agree with R2>0.98 over 10000 tasks, yielding the same decision boundaries.
Figure 4: Transformers match baselines. Test performance vs. context length (mean over 10,000 tasks; averaged over 5 training runs; ± 1 s.d. across runs).
Figure 5: Label-driven mean-shift increases class separation. Simulated dynamics with fixed parameters (α,γ,α′,γ′)=(1,5,0.08,0.1) , showing class centroids drifting apart.
Figure 6: A simulation of the mean-shift trajectories with constant parameters (α,γ,α′,γ′)=(1,5,0.08,0.1) . The test point ‘follows’ a trailing path towards its cluster.
Figure 7: Classification dynamics for Voronoi cells. Top: Simulation for (α,γ,α′,γ′)=(1,5,0.05,0.2) . Bottom: Trained transformer weights encode the same dynamics ( 7 ), matching Fig. 2 .
Figure 8: Transformers use unlabeled context to improve semi-supervised in-context learning. Top: Each prompt has 8 labeled examples; longer contexts add unlabeled points only. We plot accuracy vs. context length (mean over 10 000 tasks; averaged over 3 runs; ± 1 s.d. across runs). Bottom: Trained transformer weights encode the same dynamics ( 7 ), matching Fig. 2 .
Appendix figures & tables14 assets
Supplementary material from the paper’s appendix.
Appendix
Figure 9: We compare predictive performance of unconstrained and symmetry-preserving transformers across problem instances (dimension, sample size, data margin) and model depths. Both architectures achieve the same performance throughout.
Figure 10: Weight abstraction preserves the symmetric transformer’s input–output behavior. Left: Clustering the learned weight matrices (Figure 2 ) reveals a simple, low-dimensional structure. In the symmetry-preserving model, summarizing each matrix with just four parameters retains essentially the full predictive performance. Right (three panels): Alignment with the original unconstrained transformer for (left to right) the symmetrized model, the weight-abstracted dynamics with three layer-wise hyperparameters (no explicit label centering), and the further-simplified dynamics with two layer-wise hyperparameters (with explicit label centering).
Figure 11
Figure 13: Learned weight matrices for the unconstrained transformer (left) and the symmetry-preserving transformer (right) trained on noisy linear classification. The unconstrained model exhibits little visible structure, whereas enforcing the task symmetries produces a more regular pattern that is easier to interpret. The top and bottom rows show WQK,ℓ and WVP,ℓ , respectively.
Figure 14: Left: Accuracy on the Voronoi (nearest-centroid) classification task as a function of context size, comparing the transformer (mean over 3 runs, L=5 , trained with n=64 ) to nearest-neighbor baselines. Right: Ground-truth-class probability for the query point: symmetrized transformer vs. unconstrained transformer on the same Voronoi task, mean across 5 training seeds are shown.
Figure 15: Learned weight matrices for the unconstrained transformer (left) and the symmetry-preserving transformer (right) trained on in-context Voronoi cell classification. The unconstrained model exhibits little visible structure, whereas enforcing the task symmetries produces a more regular pattern that is easier to interpret. The top and bottom rows show WQK,ℓ and WVP,ℓ , respectively.
Figure 16: Left: Ground-truth query-class probability predicted by the symmetrized vs. unconstrained transformer on the same semi-supervised classification task (mean over 5 training seeds). Right: Ablation with Unstructured Noise. When unlabeled context points are replaced with random noise N(0,Id) , the Transformer (Blue) ceases to outperform the supervised Linear SVM baseline (Green dashed). Compare this to Figure 8 , where the Transformer leverages geometric structure to exceed the supervised baseline by >10% . This confirms the model relies on the geometry of the unlabeled data to improve classification.
Figure 17: Learned weight matrices for the unconstrained transformer (left) and the symmetry-preserving transformer (right) trained on semi-supervised in-context linear classification. The unconstrained model exhibits little visible structure, whereas enforcing the task symmetries produces a more regular pattern that is easier to interpret. The top and bottom rows show WQK,ℓ and WVP,ℓ , respectively.
Figure 18: Setting α=0 gives us label-driven mean-shift, and the probe point does not move.
Figure 19: Setting α>0 leads to a probe point trajectory.
Figure 20: Mean-Shift Effects on separated ellipses.
Transformers have demonstrated remarkable in-context learning (ICL) capabilities. The strong ICL performance of transformers is commonly believed to arise from their ability to implicitly execute certain algorithms on the context, thereby enhancing prediction and generation. In this work, we investigate how transformers with softmax attention perform in-context learning on linear classification data. We first construct a class of multi-layer transformers that can perform in-context logistic regression, with each layer exactly performing one step of normalized gradient descent on an in-context loss. Then, we show that our constructed transformer can be obtained through (i) training a single self-attention layer supervised by one-step gradient descent, and (ii) recurrently applying the trained layer to obtain a looped model. Training convergence guarantees of the self-attention layer and out-of-distribution generalization guarantees of the looped model are provided. Our results advance the theoretical understanding of ICL mechanism by showcasing how softmax transformers can effectively act as in-context learners.
Chenyang Zhang, Yuan Cao
School of Computing & Data Science, The University of Hong Kong
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.
Skanda Athreya, Yutong Wang
James B. Conant High School · Hoffman Estates, IL · Illinois Institute of Technology +1
In-context learning (ICL) allows Transformers to adapt to novel tasks without weight updates, yet the underlying algorithms remain poorly understood. We adopt a statistical decision-theoretic perspective by investigating simple binary hypothesis testing, where the optimal policy is determined by the likelihood-ratio test. Notably, this setup provides a mathematically rigorous setting for mechanistic interpretability where the target algorithmic ground truth is known. By training Transformers on tasks requiring distinct geometries (linear shifted means vs. nonlinear variance estimation), we demonstrate that the models approximate the Bayes-optimal sufficient statistics from context up to some monotonic transformation, matching the performance of an ideal oracle estimator in nonlinear regimes. Leveraging this analytical ground truth, mechanistic analysis via logit lens and circuit alignment suggests that the model does not rely on a fixed kernel smoothing heuristic. Instead, it appears to adapt the point at which decisions become linearly decodable: exhibiting patterns consistent with a voting-style ensemble for linear tasks while utilizing a deeper sequential computation for nonlinear tasks. These findings suggest that ICL emerges from the construction of task-adaptive statistical estimators rather than simple similarity matching.
Faris Chaudhry, Siddhant Gadkari
Department of Computer Science Imperial College London