Manuscript Offprint

arXiv:2610.07572

Two Vectors Replace In-Context Demos: Structured Task Adaptation via Embeddings

Xi Ding, Naichen Shi, Jiawei Zhang

ABSTRACT

In-context learning (ICL) adapts frozen large multimodal models (LMMs) to new tasks from a few demonstrations (demos), but re-encodes them at every query, where each demo image adds up to hundreds of visual tokens. Demo-free methods remove this cost with a compact task state. However, they add it at locations searched per task or at every decoder layer, where task parameters grow with depth. Moreover, inserted tokens or keys cannot change how the original prompt divides its attention within a layer. To address these issues, we propose Structured Task Adaptation via Embeddings (STAVE), which replaces demos with two task-specific vectors added to existing input embeddings. Specifically, a readout vector updates the answer-producing tokens and a context vector updates the other structural token groups. Both are trained with answer labels on prompts with and without demos. We justify these design choices theoretically using a first-order analysis of the loss and a margin bound. Extensive experiments on six LMMs and five large language models show that STAVE matches or outperforms state-of-the-art methods on multimodal tasks with far fewer task parameters and surpasses 15-shot ICL and prior task vectors on 18 text tasks, all at zero-shot inference cost.

1 Introduction

In-context learning (ICL) lets a frozen large language model (LLM) perform a new task from a few input–output demonstrations (demos) placed in its prompt (Brown et al., 2020; Dong et al., 2024). Large multimodal models (LMMs) inherit this ability (Alayrac et al., 2022; Laurençon et al., 2024b; Li et al., 2024b), so one frozen model can handle visual question answering (VQA) or image captioning without training. This flexibility is costly, since every query re-encodes its demos (Liu et al., 2022a) and each demo image expands into up to hundreds of visual tokens. Its accuracy also depends on which demos are chosen and in what order they appear (Zhao et al., 2021). We study how to adapt a frozen model to a task at the prompt length and cost of zero-shot inference.

Demo-free methods store the task in a compact state added to the frozen model at inference. Extracted task vectors take this state from demo activations. The task vector (TV) (Hendel et al., 2023) and the function vector (FV) (Todd et al., 2024) add one vector at an intermediate layer, while MTV (Huang et al., 2024) and STV (Ma et al., 2026) place it at attention heads selected for each task. Trained interventions instead optimize the state with supervision. LIVE (Peng et al., 2024) learns a shift vector for every decoder layer, and MimIC (Jiang et al., 2025) and HiFICL (Li et al., 2026) learn per-head shifts or virtual keys and values in every layer to approximate the effect of demos on the query. Prompt tuning (PT) (Lester et al., 2021) inserts learned virtual tokens into the input prompt.

These methods remove the demos at inference, yet two limitations remain. First, the task state enters either at a location searched for each task or at every decoder layer. A vector added at an intermediate layer cannot act through the blocks before it, and its layer or heads must be chosen for each task. Trained interventions avoid this choice by adding a shift to every layer, so their task parameters and per-query computation grow with model depth. Second, methods that insert tokens or keys, such as PT and HiFICL, cannot change how the original prompt divides its attention within a layer. For fixed queries and keys of the original tokens, added keys scale all their attention weights by one factor, so the relative attention between the image and the question stays unchanged (Petrov et al., 2024). PT must also choose where to insert its tokens, before the prompt, after it, or before its final token, and each inserted token lengthens the prompt and its computation.

To address these limitations, we ask two questions: where a demo-free update should enter a frozen model, and how it can be shared across tokens without losing answer-relevant directions. For the first, only an update at the input embeddings acts through every decoder block, and to first order an unrestricted input update can reproduce the first-answer effect of shifts in every layer. Added to existing tokens, the update keeps the prompt length and changes their attention queries and keys, so it can reweight the attention between the image and the question. For the second, structural token groups, such as the question text and the query image, recur in every prompt of a task, so one vector per group serves every query. Sharing has a cost: the final prompt token predicts the first answer token, whereas the other tokens reach it only through attention and still hold query-specific evidence, and a vector shared with many weak-gradient tokens, or with tokens whose gradients point in other directions, has a diluted first-order loss decrease.

Based on this analysis, we propose Structured Task Adaptation via Embeddings (STAVE), which adds two task-specific vectors to the input embeddings of a frozen LLM or LMM. A readout vector updates only the final prompt token and the answer cue, and a context vector covers the remaining groups. Both are trained with answer labels instead of an ICL teacher, on queries with and without demos, and added once to the demo-free prompt.

Contributions. ① Framework. We propose STAVE, which replaces in-context demos with a readout vector and a context vector added to the input embeddings of a frozen model. Its task parameters do not grow with model depth, and it runs at zero-shot inference cost. ② Theoretical Explanation. We show that only an input update reaches every decoder block, but one vector shared there is limited in norm and direction. Weak-gradient tokens such as image tokens dilute its norm, and its single direction cannot follow readout and context gradients that differ. At equal total norm, two separately normalized vectors never give a smaller first-order loss decrease, and their advantage grows as these gradients diverge. We also bound the margin cost of tying groups and show when training with and without demos lowers the demo-free loss. ③ Extensive Evaluations. On multimodal and text tasks, STAVE matches or outperforms per-layer interventions with far fewer task

Figure

Figure 1: STAVE performance and efficiency. Bars are relative to STAVE, and params use a log scale (Appendix E.3).

parameters and surpasses ICL and task vectors without demos at inference (Figure 1). ④ Insight. The gain comes from the readout/context separation, not a modality split or a second vector. The readout vector sets a shared answer format, the context vector adds query-specific evidence, and together they mainly elicit answers the model already holds.

References (73)