Nothing changes in the weights. What changes is the activations. A trained transformer computes a function of its whole input, so examples in the prompt act like extra arguments that change what that function does on the query. The real question is what kind of computation turns those examples into better predictions. There are three main accounts, and they don't fully exclude each other.
1. Implicit Bayesian inference / task location
Claim: In-context learning (ICL) doesn't learn anything new. Pretraining data is a mixture of many latent "tasks" or "concepts" (documents with a consistent topic, format or style). To predict the next token well, the model has to infer which latent task produced the text so far. Prompt examples are evidence that narrows down that posterior. ICL is the model recognizing a task it already knows, not learning one.
- Formalized by Xie et al. (2021, "An Explanation of In-context Learning as Implicit Bayesian Inference"). ICL emerges when pretraining documents have long-range coherence produced by latent concepts.
Evidence for:
- Labels barely matter in large pretrained LMs. Min et al. (2022) found that randomly reassigning the labels in demonstrations often hurt classification accuracy only a little. What mattered more was the input distribution, the label space and the format. That fits "the examples tell the model which task" better than "the model learns the input→label mapping."
- ICL depends on properties of the pretraining data. Chan et al. (2022) showed it emerges when the data is "bursty" (items recur in clusters) and has many rare classes, which is the kind of structure where inferring the latent context pays off.
- Prompt format, ordering and calibration effects (Zhao et al., 2021) look like prior-driven inference, not clean learning.
Evidence against / limits:
- Larger models do follow flipped or semantically unrelated labels (Wei et al., 2023, "Larger language models do in-context learning differently"). Small models fall back on their priors. Big ones can override them and learn the mapping actually given. So "it only locates tasks" breaks down at scale.
- Models trained from scratch on tasks they have never seen (below) still do ICL, so retrieving a known task can't be the whole story.
2. Implicit learning algorithms in the forward pass ("mesa-optimization")
Claim: The forward pass actually runs a learning algorithm on the prompt examples, for example something close to gradient descent on a linear model, ridge regression, or a higher-order method. The attention layers act as the optimizer.
- Garg et al. (2022) trained transformers from scratch to in-context learn linear functions, sparse linear functions, decision trees and small networks. They reached near-optimal performance (e.g., matching least squares) on new functions drawn from the class.
- von Oswald et al. (2023, "Transformers learn in-context by gradient descent") showed by construction that one linear self-attention layer can implement one step of gradient descent on a regression loss, and that trained models end up close to that construction.
- Akyürek et al. (2022) found trained models move between gradient descent, ridge regression and exact least squares depending on depth and noise. Probing recovered intermediate quantities, such as weight vectors, from the activations.
- Dai et al. (2023) argued attention is formally dual to a gradient-descent update ("meta-optimizers").
Evidence for:
- On truly novel synthetic tasks, performance tracks known optimal estimators closely. That's hard to explain as retrieving a pretrained task.
- Mechanistic and probing results in small models line up with explicit algorithmic constructions.
- Raventós et al. (2023) found a task-diversity threshold. With few pretraining tasks, the model memorizes them and behaves like a Bayesian estimator over that finite set (account 1). Past a threshold, it switches to ridge-regression-like behavior that generalizes to unseen tasks (account 2). This is the cleanest evidence that both regimes exist and that the data decides which one you get.
Evidence against / limits:
- Most of the clean results come from small models on toy regression. Whether large LMs on natural language run anything like gradient descent is much less established. Shen et al. (2023) and others found that ICL in real LLMs often doesn't behave like fine-tuning with gradient descent, for example in how much it depends on example order.
- "Equivalent to GD" constructions show the model could do this, not that it does.
3. Induction heads and copying/matching circuits
Claim: A large share of ICL comes from specific attention circuits, mainly induction heads. These find an earlier occurrence of the current token (or pattern) and copy what came after it: [A][B] … [A] → [B]. Fuzzier versions match abstract patterns, not just literal tokens. ICL is pattern completion built from these parts.
- Olsson et al. (2022, Anthropic, "In-context Learning and Induction Heads").
Evidence for:
- Phase change: at one point in training, induction heads form, ICL ability jumps sharply (measured as the loss reduction at later tokens versus early ones), and a visible bump appears in the training loss, all at the same time.
- Ablating induction heads in small models removes much of the ICL ability. Changing the architecture so induction heads form earlier moves the ICL jump earlier too.
- Later work found related "function vector" or "task vector" mechanisms (Todd et al., 2023; Hendel et al., 2023). A few heads compress the demonstrations into a vector that, when patched into a new context, triggers the task zero-shot. That links nicely to account 1: the vector looks like an encoding of the inferred latent task.
Evidence against / limits:
- The causal evidence is strongest in small attention-only models. For large models it is mostly correlational.
- Literal copying doesn't explain ICL of regression or other numeric functions. You need the more abstract, account-2-style computation for that.
How they fit together
The view I'd defend: these describe different levels or regimes, not rival theories. Induction-style heads and task vectors are mechanisms. Bayesian inference and gradient-descent-like learning are computational descriptions of what those mechanisms do. Pretraining data decides which description fits better, with low task diversity giving retrieval and high diversity giving actual learning (Raventós et al.). Scale also pushes models from leaning on priors toward following the mapping in the prompt (Wei et al.).
Open questions:
- How much of real-world LLM ICL is retrieval and how much is actual learning.
- Whether anything like gradient descent runs inside large models.
- How these circuits combine across many layers.
A caveat on the citations: I'm giving them from memory of the literature as of my training. I didn't find any related records in your workspace to cite, so check the specific numbers and claims before you rely on them.