Transformers Can Learn Multiclass Classification In-Context: Isotropy Governs Generalization

Daehan Yoon, Chulhee YunNeurIPS 2026

TL;DR

Why do Large Language Models sometimes struggle when a prompt has uneven examples, yet larger models shrug this off? By extending the theory of in-context learning (ICL) to realistic multiclass classification, the authors show that generalization—and immunity to "majority label bias"—hinges on isotropy, or how evenly class representations spread out in embedding space. It turns out that geometry acts as a natural shield against lopsided prompts.

What Problem Does This Paper Address?

Give an LLM a few input-output pairs in a prompt, and it figures out the task on the fly. While we use this in-context learning (ICL) magic daily, our mathematical grasp of why it works has been stuck in toy worlds.

Most theoretical studies simplify ICL to linear regression, even though next-token prediction is fundamentally classification. The few studies tackling classification usually look at binary tasks where the two classes point in exact opposite directions, or multiclass setups where class centers are perfectly, uniformly spaced.

Real-world embeddings aren't that neat—they often cluster into low-dimensional, uneven (anisotropic) subspaces. Furthermore, symmetrical binary setups can't explain quirks like majority label bias, where a prompt stuffed with five "positive" examples and one "negative" example tricks the LLM into guessing "positive" for the test query. The authors bridge this gap by building a theory for multiclass ICL that accounts for messy geometries and imbalanced prompts.

Methods

To keep the math tractable, the authors follow standard theoretical practice and analyze a single-layer Linear Self-Attention transformer trained via gradient descent. What’s novel is how they feed it data and analyze its geometry:

  • Spectral Data Generation: Instead of assuming classes are equally spaced, they construct a class-center matrix using Singular Value Decomposition ($\mathbf{M} = \mathbf{U}\mathbf{D}\mathbf{V}^\top$), drawing directions uniformly at random while prescribing a specific spectrum of singular values ($\mathbf{D}$).
  • Measuring Isotropy via Stable Rank: This setup lets them dial the stable rank (the squared Frobenius norm divided by the squared spectral norm) up or down. Think of stable rank as "effective dimensionality"—a high stable rank means class centers spread their energy evenly across many directions (isotropic), while a low stable rank means they are squished into a narrow subspace (anisotropic).
  • Implicit Bias & Concentration: They prove that gradient descent nudges the attention weights toward a max-margin classifier. To bound the test error on new tasks, they derive a novel bilinear Hanson-Wright concentration inequality for random orthogonal matrices.

Datasets

  • Synthetic Spectral Tasks: Generated via their new framework to test both linear attention and multi-layer nonlinear (softmax) transformers across varying class counts ($K \in \{5, 10\}$) and prompt imbalances.
  • WordNet-based Multiclass Benchmark: A newly constructed real-world word classification dataset using WordNet hypernyms (e.g., dog -> animal). They sample 500 combinations of semantic categories, crafting 200 prompts per combination across three label-allocation patterns (from balanced to heavily skewed) to test pretrained LLMs: Llama-3.2-1B-Instruct, Qwen2.5-3B-Instruct, and Phi-3-mini-4k-instruct.

Key Insights and Ideas

  • Geometry acts as a buffer against bias: Under test-time label imbalance, minority-class queries are mathematically harder to classify. However, the label-imbalance penalty interacts multiplicatively with the stable rank. Spread-out, isotropic representations directly counteract the pull of a majority class!
  • Why bigger LLMs handle bad prompts better: Prior empirical work noted that larger LLMs suffer less from majority label bias. This paper offers a crisp geometric explanation: larger models likely induce class-center embeddings with higher stable rank, naturally shielding them from skewed prompts.
  • Test-time flexibility: Even if a transformer is meta-trained on well-behaved, isotropic tasks (requiring a stable rank on the order of $K$), it can generalize at test time to much flatter, more squished geometries (requiring a stable rank of roughly $\sqrt{K}$), achieving near-optimal sample complexity per label.

Key Results

  • Synthetic Validation: In 3-layer softmax transformers (for $K=5$ and $K=10$), test accuracy steadily climbs as the stable rank of the class centers increases, while steeper label imbalance predictably degrades minority-class accuracy (e.g., for $K=10$, accuracy drops from >0.9 on balanced prompts to ~0.4–0.75 on heavily skewed [9,6,4,3,2,2,1,1,1,1] prompts, recovering as stable rank grows from 2 to 6).
  • Pretrained LLMs Follow the Math: Extracting input-layer token embeddings from Llama, Qwen, and Phi-3 on the WordNet tasks revealed statistically significant positive correlations between stable rank and ICL accuracy under imbalanced prompts (e.g., Qwen achieved a Pearson $r = 0.3114, p = 1.06 \times 10^{-12}$ on the most imbalanced pattern).
  • Shrinking the Imbalance Gap: Across all three LLMs, higher stable rank significantly correlated with a smaller accuracy drop when moving from balanced to imbalanced prompts (e.g., Qwen showed $r = -0.2440, p = 1.08 \times 10^{-8}$), confirming that isotropy breeds robustness.

Limitations and Future Work

The theoretical guarantees weaken when there are too few training tasks relative to the input dimension, when class signals are weak, or under extreme label imbalance. Additionally, the math relies on the limiting max-margin direction of gradient descent (infinite training steps) on a single linear attention layer, rather than finite-step training on deep architectures. Extending this geometric lens to multi-head softmax attention and nonlinear MLPs is the natural next frontier.

Summary updated

BibTeX
@inproceedings{yoon2026transformers,
  author = {Daehan Yoon and Chulhee Yun},
  title = {{Transformers Can Learn Multiclass Classification In-Context: Isotropy Governs Generalization}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2026},
  url = {https://openreview.net/forum?id=hSlGiiuHL6},
}
Figure