Which Attention Heads Matter for In-Context Learning?

Kayo Yin, Jacob Steinhardt
2/19/2025
cs.LGcs.AIcs.CL

No official code found. Best implementation: kayoyin/icl-heads (10 stars, last commit 2025-02-21).

Abstract

Large language models (LLMs) exhibit impressive in-context learning (ICL) capability, enabling them to perform new tasks using only a few demonstrations in the prompt. Two different mechanisms have been proposed to explain ICL: induction heads that find and copy relevant tokens, and function vector (FV) heads whose activations compute a latent encoding of the ICL task. To better understand which of the two distinct mechanisms drives ICL, we study and compare induction heads and FV heads in 12 language models. Through detailed ablations, we discover that few-shot ICL performance depends primarily on FV heads, especially in larger models. In addition, we uncover that FV and induction heads are connected: many FV heads start as induction heads during training before transitioning to the FV mechanism. This leads us to speculate that induction facilitates learning the more complex FV mechanism that ultimately drives ICL.

View on arXivView PDF

Code Implementations(1)

kayoyin/icl-headsCommunity100%
101Feb 21, 20251 years ago

Similar Papers

Cite this paper

@article{yin2025which,
  title  = {Which Attention Heads Matter for In-Context Learning?},
  author = {Kayo Yin and Jacob Steinhardt},
  year   = {2025},
  eprint = {2502.14010},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2502.14010v1},
  journal = {ICML 2025 2025}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2502.14010.svg)](https://codeofpaper.com/paper/2502.14010)

Discussion