One of the most profound surprises in modern artificial intelligence is In-Context Learning (ICL): the ability of a frozen foundation model to acquire new skills and adapt to novel task formats purely from prompt demonstrations, without undergoing a single gradient update or parameter modification. Once thought to be magical emergence, mechanistic interpretability and linear algebra have revealed the precise neural circuits—specifically Induction Heads—and implicit gradient dynamics that power in-context computation.
1. The Anatomy of an Induction Head
Discovered by Catherine Olsson and Anthropic’s interpretability team (2022), Induction Heads are two-layer attention circuits that execute abstract copy-and-paste algorithms across sequences:
$dots [A][B] dots [A] longrightarrow [B]$
If token $[A]$ was followed by $[B]$ earlier in the context, and $[A]$ appears again, the induction head shifts attention back to the first instance of $[A]$, copies the representation of $[B]$, and elevates its output probability at the current position. The circuit consists of two cooperative layers:
- Layer 1 (Previous-Token Head): Attends to the token immediately preceding the current position ($t-1$), writing its embedding into the residual stream.
- Layer 2 (Induction Head): Uses the information from Layer 1 as its Query, matching it against the Keys of all previous positions. When it detects an earlier occurrence of token $[A]$, it attends to $[A]$’s successor $[B]$ and routes $[B]$’s Value vector directly to the unembedding projection.
In-context few-shot learning is essentially the macroscopic manifestation of millions of polysemantic induction heads operating across diverse levels of semantic and syntactic abstraction.
2. In-Context Learning as Implicit Meta-Optimization
Dai et al. (2022) and von Oswald et al. (2023) mathematically demonstrated that during forward attention passes, self-attention layers behave as implicit meta-optimizers performing gradient descent on an internal task representation:
mathbf{W}_{text{eff}} = mathbf{W}_0 + Delta mathbf{W}_{text{prompt}}
The prompt demonstrations act as pseudo-training data. The linear projection matrices $mathbf{W}_K$ and $mathbf{W}_V$ compute key-value inner products that mirror the mathematical update equations of standard Stochastic Gradient Descent (SGD), allowing the network to calibrate its linear manifold dynamically at inference time.
3. Chain-of-Thought (CoT) & Reasoning Tokens
Introduced by Wei et al. (2022), Chain-of-Thought (CoT) prompting (e.g., “Let’s think step by step”) triggers a qualitative shift in reasoning benchmarks. Because autoregressive Transformers allocate a fixed budget of FLOPs per token, directly predicting the answer to a multi-step mathematical problem forces the network to compress a complex computational graph into a single forward pass.
By generating intermediate reasoning tokens, the model effectively expands its computational graph dynamically: each emitted thought token becomes a temporary variable stored in the KV cache, allowing subsequent attention layers to attend to intermediate states and verify intermediate arithmetic logic.