[Paper Review] What learning algorithm is in-context learning? Investigations with linear models
The paper proves transformers can implement standard linear-learning algorithms (gradient descent and closed-form ridge regression) in-context, and shows trained in-context learners behave like these algorithms under various conditions, linking ICL to Bayesian and minimum-norm predictors.
Neural sequence models, especially transformers, exhibit a remarkable capacity for in-context learning. They can construct new predictors from sequences of labeled examples $(x, f(x))$ presented in the input without further parameter updates. We investigate the hypothesis that transformer-based in-context learners implement standard learning algorithms implicitly, by encoding smaller models in their activations, and updating these implicit models as new examples appear in the context. Using linear regression as a prototypical problem, we offer three sources of evidence for this hypothesis. First, we prove by construction that transformers can implement learning algorithms for linear models based on gradient descent and closed-form ridge regression. Second, we show that trained in-context learners closely match the predictors computed by gradient descent, ridge regression, and exact least-squares regression, transitioning between different predictors as transformer depth and dataset noise vary, and converging to Bayesian estimators for large widths and depths. Third, we present preliminary evidence that in-context learners share algorithmic features with these predictors: learners' late layers non-linearly encode weight vectors and moment matrices. These results suggest that in-context learning is understandable in algorithmic terms, and that (at least in the linear case) learners may rediscover standard estimation algorithms. Code and reference implementations are released at https://github.com/ekinakyurek/google-research/blob/master/incontext.
Motivation & Objective
- Understand whether in-context learning (ICL) in transformers corresponds to implicit learning algorithms.
- Determine which standard linear algorithms can be implemented by transformers in-context.
- Assess how depth, width, and training data noise affect the ICL behavior and its alignment with classical predictors.
- Explore whether intermediate quantities (like weight vectors and moment matrices) are encoded in in-context representations.
Proposed method
- Prove by construction that a transformer can implement a single step of gradient descent for linear models with O(d) hidden units and constant depth.
- Prove by construction that a transformer can implement a single Sherman–Morrison update corresponding to ridge regression with O(d^2) hidden units and constant depth.
- Empirically compare ICL predictions with gradient descent, ridge regression, and ordinary least squares across varying depth, hidden size, and noise.
- Use behavioral metrics: squared prediction difference (SPD) and implicit weight difference (ILWD) to quantify agreement between ICL and standard predictors.
- Probe intermediate representations to determine if quantities like X^T Y and w_OLS are encoded in hidden states.
Experimental results
Research questions
- RQ1Can transformers implement standard linear-learning algorithms (e.g., gradient descent, ridge regression) within the in-context learning setup?
- RQ2Do trained in-context learners’ predictions align with classical predictors (OLS, ridge, GD) and Bayesian estimators under different depths, widths, and data noise?
- RQ3What intermediate quantities do in-context learners encode, and where in the network do these quantities emerge?
- RQ4How does model capacity (depth/hidden size) influence the algorithmic behavior of in-context learners (phase transitions between GD, ridge, and OLS)?
Key findings
- Transformers can compute a single step of gradient descent for linear regression with O(d) hidden units and constant depth.
- Transformers can perform a single Sherman–Morrison update to realize ridge regression with O(d^2) hidden units and constant depth.
- ICL predictions closely match gradient descent, ridge regression, and exact least-squares predictions, and transition between these as depth and noise vary.
- With larger widths and depths, ICL converges toward Bayesian estimators for linear models.
- Intermediate quantities such as X^T Y and w_OLS can be decoded from hidden representations, indicating the network computes meaningful algorithmic quantities.
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.