Interpret and Improve In-Context Learning via the Lens of Input-Label Mappings

Chenghao Sun, Zhen Huang, Yonggang Zhang, Le Lu, Houqiang Li, Xinmei Tian, Xu Shen, Jieping Ye

Introduction

In-Context Learning (ICL) allows Large Language Models (LLMs) to perform new tasks using only a few examples provided in the prompt. Despite its widespread utility, the internal mechanisms governing how models map inputs to labels remain largely opaque. This research seeks to "open the hood" of ICL to determine the nature of these mappings, their location within the model architecture, and the specific circuits responsible for their execution.

Methodology

The researchers developed a three-part framework to reverse-engineer the ICL process:

  1. Principal Component Lens (PCL): By applying Principal Component Analysis (PCA) to hidden states, the authors identified that top principal components (PCs) in middle layers align with task-related semantic concepts, even when arbitrary labels (e.g., "foo" or "bar") are used.
  2. PC Patching: To identify "ICL-heavy" modules, a causal intervention was designed. Instead of altering text inputs, the authors mathematically perturbed activations along task-related PC directions. This "virtual counterfactual" pinpointed specific attention heads affected by task mappings.
  3. Pinpoint SFT (Supervised Fine-Tuning): Based on the identified "key heads" (approximately 5% of the total), the authors performed targeted fine-tuning to enhance performance without degrading general model capabilities.
Overview of the Principal Component Lens (PCL) and PC Patching methodology for identifying task-related components and key attention heads.

Analysis of ICL Mechanics

The study reveals a structured three-stage pipeline for ICL predictions:

  • Layers 0-15 (Abstraction): The model builds associations between inputs and labels within the demonstration examples. Task-related information peaks sharply at Layer 15 in Mistral-7B, where the model abstracts the relationship between text and labels.
  • Layers 15-19 (Application): The model extracts the "rule" and applies it to the new query.
  • Layers 19-32 (Decoding): The abstract mapping is decoded back into specific vocabulary tokens for output.
Empirical evidence showing (a) semantic alignment of principal components, (b) the Layer 15 peak in task-related similarity, and (c) the causal effect of PC control on model logits.

Crucially, ICL is a "minority effort." Only about 5% of attention heads (e.g., 32 out of 1024 in Mistral-7B) are significantly involved in applying these mappings. The remainder of the model focuses on syntax and general knowledge.

Experimental Results

The researchers evaluated their approach using Mistral-7B, Llama-3, and Qwen2 across classification (SST-2, ETHOS, QQP, RTE), general knowledge (MMLU), and algorithmic reasoning tasks.

  • Performance Gains: Pinpoint SFT on just 32 heads improved average ICL accuracy by 14.99% across diverse NLP tasks. In algorithmic reasoning (BIG-bench), accuracy rose from 34.38% to 48.44%.
  • Preservation of General Knowledge: While full-model fine-tuning improved task performance by ~4.5% at the cost of a 21% drop in MMLU scores, Pinpoint SFT achieved significantly higher gains with virtually no impact (-0.03%) on general knowledge. This suggests that targeting specific ICL circuits avoids the "catastrophic forgetting" typical of broader fine-tuning.

Discussion and Limitations

While the study identifies a clear "sweet spot" for ICL (e.g., Layer 15 in Mistral-7B), these locations vary by architecture, meaning there is no universal ICL layer. Additionally, the success of Pinpoint SFT is sensitive to the number of heads selected. Future work will explore how these mappings function in more complex scenarios, such as long-form generation or multi-step reasoning.

Summary updated

BibTeX
@inproceedings{sun2025interpret,
  author = {Chenghao Sun and Zhen Huang and Yonggang Zhang and Le Lu and Houqiang Li and Xinmei Tian and Xu Shen and Jieping Ye},
  title = {{Interpret and Improve In-Context Learning via the Lens of Input-Label Mappings}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2025},
}
Figure