A Circuit for In-Context Learning
TL;DR - This paper identifies a causal transformer circuit for in-context classification with arbitrary labels. It shows that models implement gated associative lookup, storing class-label mappings from demonstrations and retrieving the matching label for a query.
- Middle-layer attention heads write demonstration classes into label-token representations, forming key-value memory.
- Upper-layer heads match the query class to stored keys and copy the corresponding label.
- Early-layer repetition signals gate retrieval, while separate heads suppress the most recently seen label.
- Activation patching, ablations, and steering reveal similar circuitry across model sizes, architectures, and instruction-tuned variants.