TL;DR
In-context learning (ICL) allows large language models to adapt to new tasks via prompt examples, but it incurs heavy computational costs as context length grows. This paper introduces $d_{\text{NTP}}$, a metric that evaluates "task vectors" (compressed representations of demonstrations) by how well they mimic ICL's predictive distribution, and leverages it to design Linear Task Vector (LTV)—a training-free method that significantly boosts accuracy while maintaining zero-shot inference speeds.
What Problem Does This Paper Address?
Large Language Models (LLMs) excel at In-Context Learning (ICL), where providing a few examples (demonstrations) directly in the prompt guides the model to perform a task without updating its weights. However, as the number of examples grows, so does the computational cost and memory overhead during inference, because the model must process the entire sequence of demonstrations for every new query.
"Task vectors" aim to solve this by compressing these demonstrations into a single, compact vector injected directly into the model's internal hidden states, allowing for fast, zero-shot-like inference.
However, until now, task vector quality has been evaluated solely through downstream task accuracy. This indirect evaluation provides little insight into why certain extraction methods work or how to systematically design better ones. This paper addresses this gap by proposing a direct, distribution-level criterion for task vector quality.
Methods
The authors introduce two main contributions:
- $d_{\text{NTP}}$ (Next-Token Probability Discrepancy): A novel metric that measures the Kullback-Leibler (KL) divergence between the next-token probability distribution produced by full ICL and the distribution produced by a task vector method. A lower $d_{\text{NTP}}$ means the task vector more faithfully reproduces the behavior of full ICL.
- Linear Task Vector (LTV): Instead of using heuristics, the authors derive a proxy objective based on Mean Squared Error (MSE) in the hidden state space and mathematically prove that minimizing this MSE bounds the $d_{\text{NTP}}$ discrepancy. Assuming the demonstration effect is a linear function of the zero-shot hidden state ($f(x,Z) = W \cdot h_{\text{zs}}(x)$), they solve for the optimal mapping matrix $W^\star$ using a closed-form ridge regression solution over a small set of unlabeled queries. At inference time, the task vector is dynamically computed as $v = W^\star h_{\text{zs}}(x_{\text{test}})$.
Datasets
The method was evaluated across eight text classification benchmarks:
- SST-2 & SST-5 (Sentiment Analysis)
- MR (Movie Reviews)
- AGNews (News Classification)
- DBPedia (Ontology Classification)
- TREC (Question Type Classification)
- SUBJ (Subjectivity Classification)
- HateSpeech18 (Hate Speech Detection)
Additionally, to test beyond discrete classification, the authors evaluated LTV on synthetic continuous linear regression and ReLU regression tasks.
Key Insights and Ideas
- Distributional Alignment Predicts Accuracy: The authors found a powerful negative correlation (Pearson coefficients often exceeding 0.6 to 0.9) between $d_{\text{NTP}}$ and downstream accuracy. If a task vector aligns well with ICL's output distribution, it performs well on the task—validating $d_{\text{NTP}}$ as a reliable, label-free evaluation proxy.
- Query-Dependent Vectors are Essential: A simple constant task vector (e.g., averaging the demonstration effects) performs poorly compared to a query-dependent mapping. The effect of demonstrations on a hidden state changes depending on the specific test query, which is why LTV's linear mapping works so well.
- Cross-Model Transfer via Logit Space: Task vectors can be transferred across model scales (e.g., from a 72B model to a 7B model). Because different models have different hidden dimensions, the authors cleverly perform the regression alignment in the shared logit space (leveraging a common tokenizer), allowing a smaller model to inherit the task-understanding capabilities of a larger model.
Key Results
- Accuracy Boost: LTV consistently outperformed existing task vector baselines (like Function Vector, State Vector, and I2CL) across 5 different LLMs. For instance, on LLaMA-2-13B, LTV improved average accuracy by 9.2% over the best baseline (State Vector), reaching 79.46%.
- Zero Inference Overhead: LTV achieves an inference latency of 0.0226s per sample, completely matching the speed of zero-shot inference and running roughly 10x faster than full ICL (0.2238s).
- Cross-Model Success: Transferring task vectors from Qwen-2.5-72B to Qwen-2.5-7B boosted the smaller model's classification accuracy by 6.43%, nearly matching the performance of the 72B model's native task vector.
Limitations and Future Work
- Linearity Assumption: LTV relies on a simple linear mapping. While the authors show that a 2-layer MLP mapping can improve accuracy further (by ~2.5%), it requires iterative gradient descent and significantly higher extraction time. Finding a more expressive mapping with a closed-form solution remains an open challenge.
- Short Outputs Only: The evaluation is restricted to single-token classification and scalar regression. It is currently unclear how well this approach scales to long-form generation tasks like summarization or multi-turn dialogue.
- Tokenizer Dependency: Cross-model transfer currently requires both the source and target models to share the exact same tokenizer to align in logit space.
Summary updated