In-Context Learning

104 beliefs (104 IN, 0 OUT)

In-Context Learning (ICL) refers to the ability of pretrained language models to adapt to new tasks at inference time purely by conditioning on demonstration examples in the prompt, without any gradient updates to model weights (icl-frozen-weights-no-parameter-updates, in-context-learning-temporary-no-gradient-updates). The belief set treats this as a central open problem in mechanistic interpretability: what computational algorithm, if any, does a frozen Transformer actually execute when it "learns" from context? The stakes are high because a correct account would explain both the impressive few-shot generalization of modern LLMs and the systematic failures (order sensitivity, distribution mismatch, limited sample efficiency) that distinguish ICL from explicit fine-tuning. The beliefs are unanimous in status—every entry is IN (accepted), with no retracted claims—so the knowledge base presents a coherent, if multi-threaded, picture rather than a field in active revision.

The dominant theoretical thread identifies ICL with implicit gradient descent. A single linear self-attention layer with a specific block-matrix weight construction exactly reproduces one GD step on a mean-squared-error regression loss (lsa-layer-exact-gd-step-weight-construction, single-attention-layer-exactly-one-gd-step), and Dai et al. (ACL 2023) extend this to the dual form, showing that the meta-gradients computed over prompt tokens are algebraically identical to the error-signal matrix in the GD dual (dai-2023-icl-meta-optimization-dual-form, meta-gradients-defined-as-wv-xprime-value-projections, attention-is-mathematical-dual-of-one-gradient-descent-step). Akyürek et al. (ICLR 2023) add a depth-dependent phase transition: roughly one layer approximates a single GD step, two to four layers approximate ridge regression with regularization λ = σ²/τ², and eight or more layers approach ordinary least squares (icl-depth-determines-algorithm-regime, icl-bayesian-ridge-lambda-sigma2-tau2). These constructive results, however, rely on hand-built weight matrices with no specified training procedure (prior-icl-gd-proofs-use-hand-constructed-weights), and Shen et al. (ICML 2024) raise a sharp counterargument: standard GD is order-stable because it averages the batch gradient, whereas ICL in decoder-only Transformers is inherently order-sensitive due to causal masking (gd-order-stable-averages-gradients, icl-order-sensitive-causal-attention, icl-gd-order-sensitivity-discriminator). Their Theorem 1 formalizes the implication—any algorithm equivalent to ICL must share its permutation sensitivity, which rules out vanilla GD (theorem1-equivalence-implies-order-sensitivity). Empirically, the ICL-versus-GD accuracy gap does not close as model size grows from 1.5B to 7B parameters or as demonstration count increases (icl-gd-gap-persists-across-scales, model-capacity-15b-7b-does-not-close-icl-gd-gap), and permuting four GINC prompt examples produces 10–40% accuracy swings (icl-prompt-ordering-sensitivity-10-40pct), all consistent with the two procedures being related but not identical.

A complementary thread frames ICL as implicit Bayesian inference. Xie et al. (2021) prove that prompt likelihood concentrates on the correct latent concept as example count grows, provided a distinguishability condition on per-token KL divergence holds (xin-icl-likelihood-ratio-convergence, xin-icl-distinguishability-condition), and they show on the synthetic GINC factorial-HMM benchmark that ICL error decreases with example length and that long-range coherence in pretraining data is necessary for ICL to emerge at all (xie-2021-icl-error-decreases-example-length, xie-2021-icl-requires-long-range-coherence). Notably, ICL quality is not a monotonic function of pretraining loss: models with identical validation perplexity can differ in ICL accuracy, and larger models improve ICL even at constant loss (icl-scale-independent-of-pretraining-loss, xie-2021-scaling-improves-icl-constant-loss), suggesting the phenomenon reflects better posterior approximation rather than mere distribution fitting. Mechanistically, the task-relevant computation is encoded non-linearly in mid-to-late layers—the moment vector XᵀY is decodable around layer 7 and the OLS weight around layer 12 of a 16-layer model, with a 2-layer MLP probe outperforming a linear probe (icl-moment-vector-and-weight-encoded-nonlinearly-in-late-layers)—and the A/f decomposition of Hendel et al. (EMNLP 2023) confirms that demonstrations can be compressed into a task vector independent of the query, with the no-demonstration baseline capturing only 10–20% of ICL accuracy (hendel-2023-core-decomposition-equation, hendel-hypothesis-procedure-accuracy-retention).

Several practical and scope-limiting findings round out the picture. Dai et al. (2023) validate the GD-as-ICL account on six real NLP classification benchmarks using off-the-shelf GPT 1.3B and 2.7B models, reporting a Kendall rank correlation of 0.19–0.21 between ICL and fine-tuning attention patterns versus 0.00 against random attention, and a Rec2FTP metric showing ICL covers over 85% of fine-tuning's gains over zero-shot (dai2023-kendall-icl-ft-019-021-vs-random-000, dai2023-rec2ftp-icl-covers-over-85-percent-of-ft). Yet they explicitly restrict their claims to Transformer architectures under 2.7B parameters and classification tasks (dai-2023-empirical-scope-limits), and the theoretical GD-simulating constructions require over 99.99% sparsity in W_K and W_Q—far denser weights than real LLMs like LLaMA-7B or GPT-J exhibit (gd-simulating-transformer-sparsity-requirements). ICL is also confirmed to be an emergent side-effect of causal language modelling pretraining rather than an explicitly optimized objective (icl-gd-icl-is-emergent-not-trained, real-llms-trained-via-clm-not-icl-objective), induction heads are a specific circuit-level instance of the broader GD-based mechanism (induction-heads-specific-case-of-gd-icl, olsson-2022-induction-heads-icl), and the phenomenon is not architecture-specific: on GINC, a 28M-parameter LSTM outperforms a comparable 4-layer Transformer, and both architectures exhibit ICL (icl-lstm-outperforms-transformer-ginc-hmm, xie-2021-icl-both-architectures-ginc). Taken together, the belief set paints ICL as a real but fragile, emergent, order-sensitive, and scale-dependent approximation of an optimization or inference procedure—closely related to gradient descent or Bayesian updating, but not reducible to either without significant qualifications.