Label Words are Anchors: An Information Flow Perspective for Understanding In-Context Learning
Lean Wang, Lei Li, Damai Dai, Deli Chen, Hao Zhou, Fandong Meng, Jie Zhou, Xu Sun
TL;DR
The paper investigates in-context learning (ICL) through an information-flow lens, arguing that label words act as anchors that gather information in shallow transformer layers and drive final predictions in deeper layers. It introduces saliency-based metrics and a formal two-part anchor hypothesis (H1/H2), validated with GPT2-XL and GPT-J across multiple classification tasks. Leveraging this anchor view, it proposes three practical enhancements: anchor re-weighting to boost accuracy, anchor-only context compression to accelerate inference, and an anchor-distance framework for diagnosing ICL errors, demonstrating improvements in efficiency and interpretability. Overall, the work provides a cohesive mechanistic account of ICL and actionable techniques to improve and diagnose ICL in large language models.
Abstract
In-context learning (ICL) emerges as a promising capability of large language models (LLMs) by providing them with demonstration examples to perform diverse tasks. However, the underlying mechanism of how LLMs learn from the provided context remains under-explored. In this paper, we investigate the working mechanism of ICL through an information flow lens. Our findings reveal that label words in the demonstration examples function as anchors: (1) semantic information aggregates into label word representations during the shallow computation layers' processing; (2) the consolidated information in label words serves as a reference for LLMs' final predictions. Based on these insights, we introduce an anchor re-weighting method to improve ICL performance, a demonstration compression technique to expedite inference, and an analysis framework for diagnosing ICL errors in GPT2-XL. The promising applications of our findings again validate the uncovered ICL working mechanism and pave the way for future studies.
