Papers › Transformers learn in-context by gradient descent

Transformers learn in-context by gradient descent

15 Dec 2022arXiv:2212.07677archive 2025-07-28

Johannes von Oswald, Eyvind Niklasson, Ettore Randazzo, João Sacramento, Alexander Mordvintsev, Andrey Zhmoginov, Max Vladymyrov

At present, the mechanisms of in-context learning in Transformers are not well understood and remain mostly an intuition. In this paper, we suggest that training Transformers on auto-regressive objectives is closely related to gradient-based meta-learning formulations. We start by providing a simple weight construction that shows the equivalence of data transformations induced by 1) a single linear self-attention layer and by 2) gradient-descent (GD) on a regression loss. Motivated by that construction, we show empirically that when training self-attention-only Transformers on simple regression tasks either the models learned by GD and Transformers show great similarity or, remarkably, the weights found by optimization match the construction. Thus we show how trained Transformers become mesa-optimizers i.e. learn models by gradient descent in their forward pass. This allows us, at least in the domain of regression problems, to mechanistically understand the inner workings of in-context learning in optimized Transformers. Building on this insight, we furthermore identify how Transformers surpass the performance of plain gradient descent by learning an iterative curvature correction and learn linear models on deep data representations to solve non-linear regression tasks. Finally, we discuss intriguing parallels to a mechanism identified to be crucial for in-context learning termed induction-head (Olsson et al., 2022) and show how it could be understood as a specific case of in-context learning by gradient descent learning within Transformers. Code to reproduce the experiments can be found at https://github.com/google-research/self-organising-systems/tree/master/transformers_learn_icl_by_gd .

PaperPDFCodeCode Syntology ran

In Syntology Open this paper in Syntology's Atlas, the map of the papers in Syntology's graph and their citations.

For agents, Syntology's MCP tool lists every function and class Syntology harvested from this paper and whether it ran (how to connect): get_harvested_code_for_paper(arxiv_id="2212.07677")

Code

Syntology Ran 0 of 16 code samples harvested from 2 repositories linked to this paper; 16 have no recorded run.

By repository: official repository: 13 samples from 1 repository, 0 ran; community (archive-listed): 3 samples from 1 repository, 0 ran. The run record, sample by sample. “Ran” means executed on a synthesized input, not that the code is correct or reproduces the paper.

google-research/self-organising-systems officialmentioned in papertfApache-2.0 report
RobvanGastel/meta-in-context-learning mentioned on GitHubjaxMIT report

Repository list and official/mentioned flags are the archive's, frozen 2025-07-28. Reachability, where shown, is from one Syntology probe window (2026-09-16 to 2026-09-18); repositories not probed show nothing. GitHub stars are not tracked.

Code Syntology ran Syntology

16 samples harvested; 0 ran; 0 honoured the contract we drafted; 16 have no recorded run. Read from Syntology's graph 2026-09-24; that is when this build read the record, not when the samples ran.

16unverified

Licence: 0 of the 16 samples are pointer only, meaning Syntology does not serve that copy's text. This page shows no code text for any sample; each one links to its file in the repository.

Harvested from 2 repositories linked to this paper, official or community; each sample names its own and says which. “Ran” means the sample executed on a synthesized input. It does not mean the output is correct, and nothing here reproduces the paper's results. “Honoured” and “violated” refer to a contract Syntology drafted from the code itself; “our draft was wrong” and “fixture could not drive it” are failures of Syntology's instrument, not of the code.

Each sample ends with its code_sha256, Syntology's identity for that exact code. An agent fetches the stored sample with Syntology's MCP tool get_code(code_sha256="…") (how to connect); click an identity to copy that call.

Repository labels, per sample. official repository: The archive marks this repository official for the paper. named in the paper: The archive records that the paper mentions this repository; it is not marked official. community (archive-listed): In the archive's code links for this paper, not marked official and not recorded as mentioned in the paper. found in paper text by Syntology: Syntology found this repository in the paper's own text; whether it is the authors' implementation is not asserted. community: Not in the archive's code links for this paper; a community repository Syntology harvested. Samples from a repository marked official are listed first. Licence labels name the repository's licence as recorded at harvest. “Pointer only” means Syntology does not serve that copy's text, for one of four reasons: no licence file was found; the licence was not identified; the licence is recorded as permissive but that copy's record is not marked cleared; or the licence is outside the permissive list Syntology serves text under (MIT, Apache-2.0, BSD and similar). Some licences outside that list permit redistribution, such as WTFPL, and GPL-3.0 under its conditions; they are simply not on the list. Hover a licence label for the reason. File links open the file on GitHub at the default branch, which may have changed since the harvest.

arrayContains google-research/self-organising-systems/self_organising_systems/biomakerca/utils.py official repository unverified Apache-2.0 (permissive) · 15182f943143a6c8 · report
clip_residual google-research/self-organising-systems/self_organising_systems/biomakerca/agent_logic.py official repository unverified Apache-2.0 (permissive) · 75c456f521df57df · report
conditional_update google-research/self-organising-systems/self_organising_systems/biomakerca/utils.py official repository unverified Apache-2.0 (permissive) · 824bd8da9ddf7f92 · report
imencode google-research/self-organising-systems/self_organising_systems/biomakerca/display_utils.py official repository unverified Apache-2.0 (permissive) · 38f91bb22eeeaa13 · report
make_empty_agent_state_cell google-research/self-organising-systems/self_organising_systems/biomakerca/env_logic.py official repository unverified Apache-2.0 (permissive) · 17c1d14bf36b249a · report
make_empty_exclusive_op_cell google-research/self-organising-systems/self_organising_systems/biomakerca/env_logic.py official repository unverified Apache-2.0 (permissive) · 15c4c038d8a867cf · report
make_empty_grid_agent_id google-research/self-organising-systems/self_organising_systems/biomakerca/environments.py official repository unverified Apache-2.0 (permissive) · 8c04902f0945c434 · report
make_empty_grid_state google-research/self-organising-systems/self_organising_systems/biomakerca/environments.py official repository unverified Apache-2.0 (permissive) · 372a22e7a0877aa4 · report
make_empty_grid_type google-research/self-organising-systems/self_organising_systems/biomakerca/environments.py official repository unverified Apache-2.0 (permissive) · 520aa1da21b7b789 · report
make_empty_upd_state google-research/self-organising-systems/self_organising_systems/biomakerca/env_logic.py official repository unverified Apache-2.0 (permissive) · b8693f5392a22b13 · report
np2pil google-research/self-organising-systems/self_organising_systems/biomakerca/display_utils.py official repository unverified Apache-2.0 (permissive) · eebeba31f9da6479 · report
split_2d google-research/self-organising-systems/self_organising_systems/biomakerca/utils.py official repository unverified Apache-2.0 (permissive) · 597aadacf31a2d26 · report
valuenoise1d google-research/self-organising-systems/self_organising_systems/biomakerca/mutators.py official repository unverified Apache-2.0 (permissive) · 16e85b6c82b85822 · report
augment_tasks RobvanGastel/meta-in-context-learning/meta_icl/transforms.py community (archive-listed) unverified MIT (permissive) · 32143cfb8422ba7f · report
create_reg_dataset RobvanGastel/meta-in-context-learning/meta_icl/data.py community (archive-listed) unverified MIT (permissive) · ca2ba6b3ce6e7e18 · report
sample_regression_dataset RobvanGastel/meta-in-context-learning/meta_icl/data.py community (archive-listed) unverified MIT (permissive) · 925adf7210923459 · report

Tasks

In-Context LearningMeta-Learningregression

Results from the paper archive 2025-07-28

No leaderboard rows for this paper in the archive.

Report a problem or propose a change · a person checks every report against the paper or source before anything changes; decisions are listed on /corrections