[Paper Review] Trained Transformers Learn Linear Models In-Context
The paper shows that a single-layer linear self-attention transformer trained by gradient flow on linear regression prompts can in-context learn linear models, converging to a global minimum and achieving prediction error competitive with the best linear predictor under certain conditions; it also analyzes robustness to distribution shifts and covariate shifts, with nonlinear transformers offering increased robustness.
Attention-based neural networks such as transformers have demonstrated a remarkable ability to exhibit in-context learning (ICL): Given a short prompt sequence of tokens from an unseen task, they can formulate relevant per-token and next-token predictions without any parameter updates. By embedding a sequence of labeled training data and unlabeled test data as a prompt, this allows for transformers to behave like supervised learning algorithms. Indeed, recent work has shown that when training transformer architectures over random instances of linear regression problems, these models' predictions mimic those of ordinary least squares. Towards understanding the mechanisms underlying this phenomenon, we investigate the dynamics of ICL in transformers with a single linear self-attention layer trained by gradient flow on linear regression tasks. We show that despite non-convexity, gradient flow with a suitable random initialization finds a global minimum of the objective function. At this global minimum, when given a test prompt of labeled examples from a new prediction task, the transformer achieves prediction error competitive with the best linear predictor over the test prompt distribution. We additionally characterize the robustness of the trained transformer to a variety of distribution shifts and show that although a number of shifts are tolerated, shifts in the covariate distribution of the prompts are not. Motivated by this, we consider a generalized ICL setting where the covariate distributions can vary across prompts. We show that although gradient flow succeeds at finding a global minimum in this setting, the trained transformer is still brittle under mild covariate shifts. We complement this finding with experiments on large, nonlinear transformer architectures which we show are more robust under covariate shifts.
Motivation & Objective
- Motivate understanding of in-context learning (ICL) in transformers for function classes, focusing on linear models.
- Demonstrate that gradient-flow training of a single-layer linear self-attention transformer converges to a global minimum on linear regression prompts.
- Characterize the prediction error on new prompts and under distribution shifts.
- Investigate robustness to covariate shifts and generalize to prompts with varying covariate distributions.
- Contrast linear self-attention with larger nonlinear transformers in terms of covariate-shift robustness.
Proposed method
- Study a one-layer transformer with a linear self-attention module (LSA) and a simplified parameterization (WPV and WKQ).
- Train by gradient flow on prompts generated from random linear-regression tasks with Gaussian inputs.
- Derive the global minimizer for the population loss under suitable initialization.
- Provide closed-form expressions for the limiting predictors and the test-prompt predictions.
- Derive a bound on the prediction error for test prompts drawn from a joint distribution of (x,y).
- Compare behavior under isotropic and anisotropic covariances and assess covariate shift robustness, extending to nonlinear transformers empirically.
Experimental results
Research questions
- RQ1Can gradient-flow training on in-context prompts lead LSAs to global minima that effectively learn linear models in-context?
- RQ2What is the resulting predictor structure at convergence and its prediction error on new prompts?
- RQ3How robust are LSAs to various distribution shifts, especially covariate shifts, when trained on prompts from linear models?
- RQ4Do prompts with varying covariate distributions across tasks mitigate brittleness under covariate shift?
- RQ5How do nonlinear transformers compare in robustness to covariate shifts?
Key findings
- Gradient flow on the population loss converges to a global minimum for the LSAs under a suitable initialization.
- At convergence, the model implements a learning rule that can in-context learn linear predictors on test prompts.
- For prompts from a joint (x,y) distribution, the predicted y on a query equals the best linear predictor error plus finite-sample error terms that shrink with prompt lengths N and M.
- The trained LSAs exhibit robustness to several distribution shifts (task shift, query shift) but are brittle under covariate shifts in the covariate distribution.
- When covariate shifts are present across prompts, LSAs still converge to a global minimum but perform poorly on new prompts, whereas larger nonlinear transformers show improved robustness empirically.
- Theoretical results are complemented by experiments indicating nonlinear transformers are more robust to covariate shifts.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.