Distributional Alignment as a Criterion for Designing Task Vectors in In-Context Learning

Jihoon Kwon, Jiwon Choi, Jy-yong Sohn

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.

Comparison of Zero-Shot, In-Context Learning, and Task Vector inference modes.

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:

  1. $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.
  2. 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}})$.
Overview of the Linear Task Vector (LTV) method using ridge regression to map zero-shot hidden states to the ICL demonstration effect.

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.
Figure 3: Correlation between the proposed discrepancy metric dNTP(f; Z) and the test accuracy, measured on various task vector extraction methods f and the demonstrations Z. We test on four variants of f: Function Vector [41], Task Vector [16], State Vector [24], and I2CL [28], each of which is shown in different colors. Here, each point corresponds to the result for different demonstrations Z. Pearson correlation coefficients (ρ) are reported for each method f. Across four classification benchmarks (columns) and two models (rows), lower dNTP(f; Z) consistently correlates with higher accuracy, validating our metric as a principled criterion for the quality of the task vector.
  • 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

Abstract

In-context learning (ICL) allows large language models (LLMs) to adapt to new tasks through demonstrations, yet it suffers from escalating inference costs as context length increases. While task vectors offer a promising alternative by compressing demonstrations into compact hidden-state representations, their quality has been evaluated only through downstream task accuracy. This indirect criterion provides limited insight into how to design more effective task vector extraction methods. In this paper, we posit that inference using task vectors should align their predictive distribution with that of ICL. To quantify this, we introduce $d_{\text{NTP}}$, a metric that measures the discrepancy in next-token probabilities between task vector-based and ICL-based inference. Our empirical analysis reveals that $d_{\text{NTP}}$ serves as a performance proxy, exhibiting a strong negative correlation with downstream accuracy. Motivated by this, we develop Linear Task Vector (LTV), a method designed to minimize $d_{\text{NTP}}$ via a closed-form linear mapping that estimates demonstration effects through regression. Across eight classification benchmarks and five LLMs, LTV consistently outperforms existing task vector baselines, improving average accuracy by 9.2\% while reducing inference latency. We further show that LTV outperforms the baselines on regression tasks. Moreover, we investigate the transferability of LTV across different model scales; an aspect that has remained nascent in task vector research. Specifically, we empirically show that task vectors from a larger model can enhance a smaller model's performance by 6.4\%, suggesting a new utility for extracted task representations.
BibTeX
@inproceedings{kwon2026distributional,
  author = {Jihoon Kwon and Jiwon Choi and Jy-yong Sohn},
  title = {{Distributional Alignment as a Criterion for Designing Task Vectors in In-Context Learning}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2026},
  url = {https://openreview.net/forum?id=PRjQ0E5e0e},
}
Figure