The Atlas of In-Context Learning: How Attention Heads Shape In-Context Retrieval Augmentation

Patrick Kahardipraja, Reduan Achtibat, Thomas Wiegand, Wojciech Samek, Sebastian Lapuschkin
5/21/2025
cs.CLcs.IRcs.LG

No official code found. Best implementation: pkhdipraja/in-context-atlas (11 stars, last commit 2026-01-20).

Abstract

Large language models are able to exploit in-context learning to access external knowledge beyond their training data through retrieval-augmentation. While promising, its inner workings remain unclear. In this work, we shed light on the mechanism of in-context retrieval augmentation for question answering by viewing a prompt as a composition of informational components. We propose an attribution-based method to identify specialized attention heads, revealing in-context heads that comprehend instructions and retrieve relevant contextual information, and parametric heads that store entities' relational knowledge. To better understand their roles, we extract function vectors and modify their attention weights to show how they can influence the answer generation process. Finally, we leverage the gained insights to trace the sources of knowledge used during inference, paving the way towards more safe and transparent language models.

View on arXivView PDF

Code Implementations(1)

Code for "The Atlas of In-Context Learning: How Attention Heads Shape In-Context Retrieval Augmentation", NeurIPS 2025

110PythonMay 20, 20259 months agoNOASSERTION

Similar Papers

Cite this paper

@article{kahardipraja2025atlas,
  title  = {The Atlas of In-Context Learning: How Attention Heads Shape In-Context Retrieval Augmentation},
  author = {Patrick Kahardipraja and Reduan Achtibat and Thomas Wiegand and Wojciech Samek and Sebastian Lapuschkin},
  year   = {2025},
  eprint = {2505.15807},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2505.15807v2}
}

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/2505.15807.svg)](https://codeofpaper.com/paper/2505.15807)

Discussion