Trained Transformer Classifiers Generalize and Exhibit Benign Overfitting In-Context
Abstract
Transformers have the capacity to act as supervised learning algorithms: by properly encoding a set of labeled training ("in-context") examples and an unlabeled test example into an input sequence of vectors of the same dimension, the forward pass of the transformer can produce predictions for that unlabeled test example. A line of recent work has shown that when linear transformers are pre-trained on random instances for linear regression tasks, these trained transformers make predictions using an algorithm similar to that of ordinary least squares. In this work, we investigate the behavior of linear transformers trained on random linear classification tasks. Via an analysis of the implicit regularization of gradient descent, we characterize how many pre-training tasks and in-context examples are needed for the trained transformer to generalize well at test-time. We further show that in some settings, these trained transformers can exhibit "benign overfitting in-context": when in-context examples are corrupted by label flipping noise, the transformer memorizes all of its in-context examples (including those with noisy labels) yet still generalizes near-optimally for clean test examples.
Ask Lune
Know this paper in minutes, not an afternoon.
Lune can read every page of it and the top-tier papers that cite it, and gives you its claims, its evidence and its limits, each one cited to the paper it comes from. No skimming, no AI slop.
11 top-tier papers have cited it since. Know what they found before your reviewers do.
Lune can draw on
the full paper · the top-tier papers that cite it · related work
Free to start. No credit card required.
Lineage
- Transformers as Statisticians: Provable In-Context Learning with In-Context Algorithm Selection cites Language Models are Few-Shot Learners
- Transformers as Statisticians: Provable In-Context Learning with In-Context Algorithm Selection cites Transformers Learn In-Context by Gradient Descent
- Transformers as Statisticians: Provable In-Context Learning with In-Context Algorithm Selection cites What Can Transformers Learn In-Context? A Case Study of Simple Function Classes
- Short-length Adversarial Training Helps LLMs Defend Long-length Jailbreak Attacks: Theoretical and Empirical Evidence cites Language Models are Few-Shot Learners
- Short-length Adversarial Training Helps LLMs Defend Long-length Jailbreak Attacks: Theoretical and Empirical Evidence cites Transformers Learn In-Context by Gradient Descent
- Short-length Adversarial Training Helps LLMs Defend Long-length Jailbreak Attacks: Theoretical and Empirical Evidence cites What Can Transformers Learn In-Context? A Case Study of Simple Function Classes
- Transformers are almost optimal metalearners for linear classification cites Transformers as Statisticians: Provable In-Context Learning with In-Context Algorithm Selection
- Transformers are almost optimal metalearners for linear classification cites Gradient Descent Maximizes the Margin of Homogeneous Neural Networks
- Transformers are almost optimal metalearners for linear classification cites Language Models are Few-Shot Learners
- Transformers are almost optimal metalearners for linear classification cites Transformers Learn In-Context by Gradient Descent
- Transformers are almost optimal metalearners for linear classification cites What Can Transformers Learn In-Context? A Case Study of Simple Function Classes
- Adversarially Pretrained Transformers May Be Universally Robust In-Context Learners cites Transformers as Statisticians: Provable In-Context Learning with In-Context Algorithm Selection
- Adversarially Pretrained Transformers May Be Universally Robust In-Context Learners cites Short-length Adversarial Training Helps LLMs Defend Long-length Jailbreak Attacks: Theoretical and Empirical Evidence
- Adversarially Pretrained Transformers May Be Universally Robust In-Context Learners cites Language Models are Few-Shot Learners
- Adversarially Pretrained Transformers May Be Universally Robust In-Context Learners cites On the Robustness of Transformers against Context Hijacking for Linear Classification
- Adversarially Pretrained Transformers May Be Universally Robust In-Context Learners cites Transformers Learn In-Context by Gradient Descent
- Adversarially Pretrained Transformers May Be Universally Robust In-Context Learners cites What Can Transformers Learn In-Context? A Case Study of Simple Function Classes
- On the Robustness of Transformers against Context Hijacking for Linear Classification cites Transformers as Statisticians: Provable In-Context Learning with In-Context Algorithm Selection
- On the Robustness of Transformers against Context Hijacking for Linear Classification cites Language Models are Few-Shot Learners
- On the Robustness of Transformers against Context Hijacking for Linear Classification cites Transformers Learn In-Context by Gradient Descent
- On the Robustness of Transformers against Context Hijacking for Linear Classification cites What Can Transformers Learn In-Context? A Case Study of Simple Function Classes
- Provably Transformers Harness Multi-Concept Word Semantics for Efficient In-Context Learning cites Transformers as Statisticians: Provable In-Context Learning with In-Context Algorithm Selection
- Provably Transformers Harness Multi-Concept Word Semantics for Efficient In-Context Learning cites Transformers Learn In-Context by Gradient Descent
- Transformers Learn In-Context by Gradient Descent cites Language Models are Few-Shot Learners
- Transformers Learn In-Context by Gradient Descent cites What Can Transformers Learn In-Context? A Case Study of Simple Function Classes
- What Can Transformers Learn In-Context? A Case Study of Simple Function Classes cites Language Models are Few-Shot Learners
Cited by top-tier papers11
- Short-length Adversarial Training Helps LLMs Defend Long-length Jailbreak Attacks: Theoretical and Empirical EvidenceShaopeng Fu, Liang Ding, Jingfeng Zhang, Di WangNeurIPS 2025 · 15 citations
- Provably Transformers Harness Multi-Concept Word Semantics for Efficient In-Context LearningDake Bu, Wei Huang, Andi Han, Atsushi Nitanda et al.NeurIPS 2024 · 11 citations
- On the Robustness of Transformers against Context Hijacking for Linear ClassificationTianle Li, Chenyang Zhang, Xingwu Chen, Yuan Cao et al.NeurIPS 2025 · 7 citations
- Transformers are almost optimal metalearners for linear classificationRoey Magen, Gal VardiNeurIPS 2025 · 2 citations
- Adversarially Pretrained Transformers May Be Universally Robust In-Context LearnersSoichiro Kumano, Hiroshi Kera, Toshihiko YamasakiICLR 2026 · 2 citations
Builds on16
- Language Models are Few-Shot LearnersTom B. Brown, Benjamin Mann, Nick Ryder, Melanie Subbiah et al.NeurIPS 2020 · 64,255 citations
- What Can Transformers Learn In-Context? A Case Study of Simple Function ClassesShivam Garg, Dimitris Tsipras, Percy Liang, Gregory ValiantNeurIPS 2022 · 883 citations
- Transformers Learn In-Context by Gradient DescentJohannes von Oswald, Eyvind Niklasson, Ettore Randazzo, João Sacramento et al.ICML 2023 · 729 citations
- Gradient Descent Maximizes the Margin of Homogeneous Neural NetworksKaifeng Lyu, Jian LiICLR 2020 · 402 citations
- Transformers as Statisticians: Provable In-Context Learning with In-Context Algorithm SelectionYu Bai, Fan Chen, Huan Wang, Caiming Xiong et al.NeurIPS 2023 · 356 citations
Related papers
- Linear Transformers are Versatile In-Context LearnersMax Vladymyrov, Johannes von Oswald, Mark Sandler, Rong GeNeurIPS 2024 · 37 citations
- Transformers Efficiently Perform In-Context Logistic Regression via Normalized Gradient DescentChenyang Zhang, Yuan CaoICML 2026 · 1 citation
- In-context Learning on Function Classes Unveiled for TransformersZhijie Wang, Bo Jiang, Shuai LiICML 2024 · 8 citations
- Pretrain–Test Task Alignment Governs Generalization in In-Context LearningMary Letey, Jacob A Zavatone-Veth, Yue M. Lu, Cengiz PehlevanICLR 2026 · 6 citations
- Transformers learn to implement preconditioned gradient descent for in-context learningKwangjun Ahn, Xiang Cheng, Hadi Daneshmand, Suvrit SraNeurIPS 2023 · 324 citations
