Large Language Models (LLMs) possess a remarkable ability to perform in-context learning (ICL)—solving tasks simply by observing a few examples in a prompt without any weight updates. But how exactly does this work under the hood?
Historically, researchers have approached this question from two disconnected paradigms:
- The Introspective Paradigm: This approach looks inside the network to find specific components responsible for ICL, such as "Induction Heads" (IHs). However, relying on ablations (turning heads off) mostly shows how much a head matters, rather than how it functionally implements ICL.
- The Holistic Paradigm: This view treats the model as a black box and breaks ICL down into two functional parts: Task Recognition (TR) (recognizing the format and possible label space, e.g., knowing the answer should be "positive" or "negative") and Task Learning (TL) (learning the actual mapping from the input text to the correct label).
A recent paper bridges these two views, localizing the holistic functions of TR and TL into specific, identifiable attention heads using a novel geometric framework.
The Geometry of Attention Heads: Aligners and Rotators
To determine which attention heads perform which functions, the authors propose a new metric called Task Subspace Logit Attribution (TSLA). Instead of just measuring if a head boosts the probability of a specific token, TSLA analyzes the geometric subspace spanned by the task's labels.
This geometric approach reveals two distinct types of attention heads:
- Task Recognition (TR) Heads act as "Aligners": A head scores high in TR if its output projects heavily onto the task-label subspace. Essentially, these heads pull the model's hidden states into the correct realm, signaling, "We are looking for these specific types of labels."
- Task Learning (TL) Heads act as "Rotators": A head scores high in TL if its output creates a contrastive gap within that subspace. These heads rotate the hidden state toward the specific correct label and away from incorrect ones.
Key Insights and Discoveries
By applying the TSLA framework across standard classification benchmarks and custom generation datasets, the researchers uncovered several critical insights about the mechanics of ICL.
Demystifying Induction Heads
One of the most significant findings is the massive overlap between previously discovered Induction Heads and the newly identified TR heads. This resolves a major debate in mechanistic interpretability: Induction Heads do not necessarily figure out the correct answer. Rather, they primarily help the model recognize the label space (Task Recognition).
Layer Distribution: Learning Before Recognizing
Interestingly, TL heads tend to activate in earlier layers than TR heads. The model figures out the correct-vs-incorrect margin (the actual task learning) early on, but only boosts the task-vs-irrelevant margin (recognizing the task format) in deeper layers.
Independent and Separable Functions
TR and TL functions are highly separable; you can break one without breaking the other.
- Ablating TR heads: If you remove the top 3% of TR heads (e.g., in Llama3-8B), the model forgets what the valid labels are. The Task Recognition Ratio plummets from nearly 100% to ~20%, causing a drastic accuracy drop.
- Ablating TL heads: If you remove the top 3% of TL heads, the model still outputs valid labels (the TR ratio remains intact), but its accuracy drops by ~30% as it resorts to random guessing within that valid label space.
Task Vectors are Context-Dependent
The framework also sheds light on how to steer models zero-shot. For standard classification tasks, injecting TR head outputs into zero-shot prompts magically recovers ICL-level performance (e.g., jumping from ~10% to ~40% accuracy on Llama3-8B). However, for open-ended generation tasks where there is no fixed label space to "recognize," TL-based vectors are far more effective at steering the model toward coherent and accurate outputs.
Looking Ahead
While this framework provides a unified and interpretable account of how LLMs execute ICL, it primarily focuses on attention heads. The role of Multi-Layer Perceptrons (MLPs) in the TR/TL decomposition remains an open question. Future work will likely explore how these specialized geometric heads form during pretraining and how they handle complex, composite tasks.
Summary updated