Table of Contents
Fetching ...

Transformers are almost optimal metalearners for linear classification

Roey Magen, Gal Vardi

TL;DR

This work analyzes whether a pretrained, simplified linear transformer can serve as a metalearner for binary classification in a Gaussian-mixture setting where task means lie in a shared $k$-dimensional subspace. By linking gradient-descent dynamics to max-margin solutions, the authors prove that after training on $B$ tasks, the required number of in-context examples at test time scales as $M = \tilde{O}(k/\tilde{R}^4)$, independent of the ambient dimension $d$, and nearly matches the performance of an optimal learner that knows the subspace. They establish information-theoretic lower bounds for single-task learning and show the transformer achieves near-optimal metalearning performance under reasonable conditions, including explicit task-count and sample-size requirements $B$ and $N$ tied to the training SNR. Experiments with linear attention corroborate the theory, showing the transformer approaches projected MLE performance and outperforms SVM and full MLE on synthetic data, while suggesting future work to extend these guarantees to richer architectures and broader distributions.

Abstract

Transformers have demonstrated impressive in-context learning (ICL) capabilities, raising the question of whether they can serve as metalearners that adapt to new tasks using only a small number of in-context examples, without any further training. While recent theoretical work has studied transformers' ability to perform ICL, most of these analyses do not address the formal metalearning setting, where the objective is to solve a collection of related tasks more efficiently than would be possible by solving each task individually. In this paper, we provide the first theoretical analysis showing that a simplified transformer architecture trained via gradient descent can act as a near-optimal metalearner in a linear classification setting. We consider a natural family of tasks where each task corresponds to a class-conditional Gaussian mixture model, with the mean vectors lying in a shared $k$-dimensional subspace of $R^d$. After training on a sufficient number of such tasks, we show that the transformer can generalize to a new task using only $O(k / R^4)$ in-context examples, where $R$ denotes the signal strength at test time. This performance (almost) matches that of an optimal learner that knows exactly the shared subspace and significantly outperforms any learner that only has access to the in-context data, which requires $Ω(d / R^4)$ examples to generalize. Importantly, our bounds on the number of training tasks and examples per task needed to achieve this result are independent of the ambient dimension $d$.

Transformers are almost optimal metalearners for linear classification

TL;DR

This work analyzes whether a pretrained, simplified linear transformer can serve as a metalearner for binary classification in a Gaussian-mixture setting where task means lie in a shared -dimensional subspace. By linking gradient-descent dynamics to max-margin solutions, the authors prove that after training on tasks, the required number of in-context examples at test time scales as , independent of the ambient dimension , and nearly matches the performance of an optimal learner that knows the subspace. They establish information-theoretic lower bounds for single-task learning and show the transformer achieves near-optimal metalearning performance under reasonable conditions, including explicit task-count and sample-size requirements and tied to the training SNR. Experiments with linear attention corroborate the theory, showing the transformer approaches projected MLE performance and outperforms SVM and full MLE on synthetic data, while suggesting future work to extend these guarantees to richer architectures and broader distributions.

Abstract

Transformers have demonstrated impressive in-context learning (ICL) capabilities, raising the question of whether they can serve as metalearners that adapt to new tasks using only a small number of in-context examples, without any further training. While recent theoretical work has studied transformers' ability to perform ICL, most of these analyses do not address the formal metalearning setting, where the objective is to solve a collection of related tasks more efficiently than would be possible by solving each task individually. In this paper, we provide the first theoretical analysis showing that a simplified transformer architecture trained via gradient descent can act as a near-optimal metalearner in a linear classification setting. We consider a natural family of tasks where each task corresponds to a class-conditional Gaussian mixture model, with the mean vectors lying in a shared -dimensional subspace of . After training on a sufficient number of such tasks, we show that the transformer can generalize to a new task using only in-context examples, where denotes the signal strength at test time. This performance (almost) matches that of an optimal learner that knows exactly the shared subspace and significantly outperforms any learner that only has access to the in-context data, which requires examples to generalize. Importantly, our bounds on the number of training tasks and examples per task needed to achieve this result are independent of the ambient dimension .
Paper Structure (28 sections, 11 theorems, 79 equations, 2 figures, 1 table)

This paper contains 28 sections, 11 theorems, 79 equations, 2 figures, 1 table.

Key Result

Theorem 2.3

Let ${\bm{W}}_{\text{MM}}$ denote the solution to the max-margin problem: If the above problem is feasible and the learning rate $\alpha$ is sufficiently small, then ${\bm{W}}_t$ converges in direction to ${\bm{W}}_{\text{MM}}$, that is ${\bm{W}}_t/\|{\bm{W}}_t\| \to c{\bm{W}}_{\text{MM}}$, as $t \rightarrow \infty$, for some constant $c>0$.

Figures (2)

  • Figure 1: Test accuracy versus the number of in-context examples $M$, where each plot represents a different signal strength $R=\Tilde{R}$. We compare the performance of the trained linear transformer model against three baselines: full MLE, projected MLE (with access to the true subspace), and SVM. The transformer closely approaches the performance of the projected MLE and outperforms both the full MLE and SVM, which lack access to the subspace. Accuracy improves as the signal strength $R = \Tilde{R}$ increases. $d=500,k=30, B=20000$.
  • Figure 2: Test accuracy versus the number of in-context examples $M$ for various subspace dimensions $k$. Accuracy improves as the signal strength $R = \Tilde{R}$ increases and as the subspace dimension $k$ decreases. $B=d=2000$.

Theorems & Definitions (28)

  • Theorem 2.3: soudry2018implicit
  • Remark 2.1: giraud2019partial, Appendix B
  • Remark 2.2
  • Theorem 3.1
  • Remark 4.1
  • Lemma C.1
  • proof
  • Lemma C.2
  • proof
  • Lemma C.3
  • ...and 18 more