TL;DR
Researchers have discovered that Large Language Models (LLMs) represent tasks—like translation or antonym generation—as compact "function vectors" (FVs) within their internal layers. These vectors are highly portable: you can extract an FV from one context and "paste" it into a completely different one to trigger the task zero-shot, and even perform "vector algebra" to compose complex new functions.
What Problem Does This Paper Address?
In-Context Learning (ICL) is one of the most striking capabilities of LLMs—the ability to learn a new task from just a few examples in a prompt. However, the internal mechanics of how a model identifies and executes these tasks remain a "black box."
Previous research focused on how models copy tokens or perform Bayesian inference, but this paper investigates the existence of a specific, causal internal representation of the task itself. The authors seek to determine if there is a discrete "signal" that tells the model, "Now, perform an English-to-Spanish translation," regardless of the specific words involved.
Methods
The authors employ Causal Mediation Analysis to isolate the mechanism of ICL. Their approach involves several steps:
- Identification: They use "activation patching" to find which specific attention heads are responsible for a task. They compare "clean" prompts (correct examples) with "corrupted" prompts (shuffled labels) to see which heads' activations restore the correct output.
- Extraction: They found that a small subset of attention heads in the middle layers (e.g., about 10 heads in GPT-J) act as the primary transporters of task information. The Function Vector (FV) is defined as the sum of the average outputs of these causal heads.
- Intervention: To prove the FV is causal and not just correlative, they "inject" the vector into the model's hidden states during a zero-shot prompt (a prompt with no examples). If the model suddenly starts performing the task, the vector is a successful functional reference.
Datasets
The study uses a curated suite of over 40 diverse ICL tasks, categorized into:
- Abstractive Tasks: Generating new information (e.g., Antonym, English-French translation, Country-Capital).
- Extractive Tasks: Retrieving information from the prompt (e.g., Choose the nth item from a list, NER-person).
- Benchmarks: They utilized data from existing sources like Conneau et al. (2017) for translation and Nguyen et al. (2017) for antonyms, while also introducing new custom-built tasks for list manipulation and category selection.
The models tested include GPT-J (6B), GPT-NeoX (20B), and the Llama 2 family (7B, 13B, and 70B).
Key Insights and Ideas
- FVs are Portable: An FV extracted from a standard "Q&A" style prompt works even when injected into "natural text" (e.g., a sentence like "While reading a book, I came across the word 'x'..."). This suggests the model uses a universal internal representation for the task.
- Middle-Layer Dominance: FVs are most effective when injected into the early-to-middle layers. Injecting them into late layers has almost no effect. This implies that FVs don't just "bias" the final word choice; they trigger a multi-step, non-linear "program" within the model's deeper layers.
- Vector Algebra for Functions: Much like the famous
vec("King") - vec("Man") + vec("Woman") = vec("Queen"), FVs can be composed. For example, the authors created a "Last-Capitalize" function by combining vectors for "Last-Copy" and "First-Capitalize." - Beyond Vocabulary: While an FV contains information about the "output space" (e.g., the English-French FV contains French-like tokens), simply boosting those tokens isn't enough to replicate the FV's effect. The vector carries structural information about the transformation itself.
Key Results
- Zero-Shot Boost: In GPT-J, adding an FV to a zero-shot prompt increased task accuracy from 5.5% to 57.5%. In the massive Llama 2 (70B) model, accuracy jumped from 8.2% to 83.8%.
- Robustness: FVs remained effective across 20 different prompt templates, proving they are not overfit to a specific formatting style.
- Composition Success: Composed vectors often outperformed the model's own 10-shot ICL performance. For the "Last-Capitalize-First-Letter" task, the composed FV achieved 95% accuracy, while standard 10-shot ICL only reached 75%.
Limitations and Future Work
- Task Simplicity: The tasks used in this study primarily involve single-word or short-phrase outputs. It is currently unknown if complex, multi-step reasoning tasks can be compressed into a single function vector.
- Computational Cost: Extracting a high-quality FV requires averaging activations over many examples (the authors used 100), which may be computationally expensive for real-time applications.
- Safety and Ethics: The authors note that the ability to explicitly trigger functions via vector injection could be abused by bad actors to "steer" models toward undesirable or harmful behaviors.
- Future Direction: The authors suggest exploring whether FVs can be used for "model editing"—permanently baking new capabilities into a model without full fine-tuning.
Summary updated