Where does In-context Learning Happen in Large Language Models?

Suzanna Sia, David Mueller, Kevin Duh
2/3/2026

No confident code implementation found for this paper.

Abstract

Self-supervised large language models have demonstrated the ability to perform various tasks via in-context learning, but little is known about where the model locates the task with respect to prompt instructions and demonstration examples. In this work, we attempt to characterize the region where large language models transition from recognizing the task to performing the task. Through a series of layer-wise context-masking experiments on GPTN EO 2.7B, B LOOM 3B, and S TARCODER 2-7B, L LAMA 3.1-8B, L LAMA 3.1-8B-I NSTRUCT , on Machine Translation and Code generation, we demonstrate evidence of a "task recognition" point where the task is encoded into the input representations and attention to context is no longer necessary. Taking advantage of this redundancy results in 45% computational savings when prompting with 5 examples, and task recognition achieved at layer 14 / 32 using an example with Machine Translation. Our findings also have implication for resource and parameter efficient fine-tuning; we observe a correspondence between fine-tuning performance of individual LoRA layers and the task recognition layers.

DOISemantic Scholar

Code Implementations

No confident code match yet

We couldn't find an author-owned or strongly-evidenced community implementation for this paper. Any repos shown below are weak matches — verify before relying on them.

No code implementations found yet.

Know of an implementation? Let us know in the comments below!

Cite this paper

@article{sia2026where,
  title  = {Where does In-context Learning Happen in Large Language Models?},
  author = {Suzanna Sia and David Mueller and Kevin Duh},
  year   = {2026},
  doi    = {10.52202/079017-1030},
  url    = {https://doi.org/10.52202/079017-1030},
  journal = {NEURIPS 2024 2024}
}

Discussion