Task Vectors, Learned Not Extracted: Performance Gains and Mechanistic Insights

Haolin Yang, Hakaze Cho, Kaize Ding, Naoya Inoue

TL;DR

Instead of trying to "extract" task representations from a model's internal states, this paper proposes directly training Learned Task Vectors (LTVs) via gradient descent. These LTVs not only outperform existing extraction methods and rival In-Context Learning (ICL) performance, but they also reveal a surprisingly linear "rotate-then-stretch" mechanism by which Large Language Models (LLMs) process task information across layers.

The Problem: The Messiness of Extraction

In-Context Learning (ICL)—where an LLM learns a task from just a few examples in a prompt—is one of the most powerful yet mysterious properties of modern AI. Recent research suggests that LLMs handle this by compressing those examples into a "task vector" (TV), a compact numerical representation of the task's rules.

However, current methods for finding these vectors are messy. Researchers usually try to "extract" them by averaging hidden states or attention outputs. This approach is often suboptimal, sensitive to exactly where you look, and suffers from a "representational bottleneck" where internal activations might be noisy or incomplete. Furthermore, we haven't really understood the "plumbing": how does a single vector injected into a middle layer actually steer the model toward the right answer? This paper aims to replace extraction with learning and provide a clear mechanistic map of how these vectors operate.

The Solution: Learned Task Vectors (LTVs)

The authors introduce Learned Task Vectors (LTVs). Instead of looking for a vector that already exists, they treat the task vector $\theta$ as a trainable parameter. They inject this vector into the model's hidden states at a specific layer and token position, and use gradient descent (AdamW) to optimize it to minimize the loss on the target task.

Overview of LTV training and the rotate-then-stretch mechanism.

Beyond just building a better vector, the authors perform a "mechanistic autopsy" using several techniques:

  • Saliency Scoring: Identifying which specific attention heads are most "decisive" in using the TV.
  • OV-Circuit Reconstruction: Testing if the TV's effect can be replicated solely through the model's Output-Value (OV) circuits.
  • Linear Propagation Analysis: Using polar decomposition to break down how the vector changes as it moves through layers.

Mechanistic Insights: Rotate-then-Stretch

The paper's biggest "aha" moment comes from analyzing how LTVs propagate through the network. They found that despite the nonlinearities in Transformers (like ReLU/GELU), TV propagation is remarkably linear, following a "Rotate-then-Stretch" dynamic:

  1. Early Layers (Rotation): The model rotates the TV to align it with the "subspace" of the correct answer labels.
  2. Later Layers (Stretch): Once aligned, the model simply scales the vector's magnitude to boost the final prediction's confidence.

Additionally, the researchers discovered a Pareto Principle of Attention Heads. Not all heads are equal; a tiny subset (the top 10% "key heads") does almost all the heavy lifting. Unlike random heads that get stuck in "attention sinks" (like the first token), these key heads focus on the final tokens where the actual prediction happens.

Key Results

The study evaluates LTVs across a diverse range of tasks, including algorithmic tasks, natural language classification, complex generation, and compositional tasks, using models like Llama 2/3, Qwen 2.5, and Yi.

  • Accuracy: LTVs consistently matched or exceeded the performance of full 8-shot In-Context Learning. On Llama 3.1-8B, LTVs achieved ~83% accuracy on baseline tasks, while Vanilla TVs struggled at ~38%.
  • Flexibility: Unlike extracted vectors, which only work if injected into the exact layer they were pulled from, LTVs are highly robust. They can be trained to work at almost any layer or even across multiple token positions.
Performance comparison of LTVs against Vanilla TVs and Function Vectors (FVs) across different injection layers.
  • Compositionality: The authors successfully "added" two different LTVs (e.g., a translation vector and a gender-switching vector) to perform a composite task, proving that these vectors capture semantic structure.
  • Efficiency (LTV as PEFT): Because an LTV is just a single vector (e.g., 4096 dimensions for an 8B model), it is an incredibly efficient way to fine-tune a model. LTV training is faster and uses less memory than standard Parameter-Efficient Fine-Tuning (PEFT) methods like Prefix Tuning or LoRA, while maintaining higher accuracy in many cases.

Limitations and Future Work

While promising, the study notes a few limitations. Most tasks used were relatively simple classification or short-phrase generation; it remains to be seen how LTVs handle complex, multi-step reasoning. Additionally, LTVs are highly sensitive to the "label space." If two tasks don't share similar output tokens (e.g., "Positive/Negative" vs. "True/False"), a vector for one won't easily transfer to the other.

Future directions include exploring how LTVs could be used to "steer" models away from harmful behaviors or to inject specialized knowledge without the overhead of full fine-tuning.

Summary updated

BibTeX
@inproceedings{yang2026task,
  author = {Haolin Yang and Hakaze Cho and Kaize Ding and Naoya Inoue},
  title = {{Task Vectors, Learned Not Extracted: Performance Gains and Mechanistic Insights}},
  booktitle = {International Conference on Learning Representations},
  year = {2026},
  url = {https://openreview.net/forum?id=RGEbVZgf4E},
}
Figure