betaFeedback

WorksComputer Science

Learn the Effects, Not the Examples: Implicit ICL via Attention Patching

Abstract

In-context learning (ICL) enables language models to adapt to new tasks from demonstrations, but repeatedly including multiple examples increases context length and inference cost. Many existing implicit ICL methods encode demonstrations as fixed vectors, limiting adaptation of the intervention to individual queries and token positions. We propose Attention-Patching, an implicit ICL method that models contextual changes in self-attention outputs through task-specific updates to attention output projections. Using query-answer pairs processed with and without a fixed demonstration set, Attention-Patching fits layer-wise affine transformations from non-contextual attention representations to the demonstration-induced output changes. Across 12 classification benchmarks and four model families, Attention-Patching achieves higher average accuracy than the evaluated implicit ICL baselines while maintaining performance comparable to explicit ICL at near zero-shot inference cost. Further experiments on diverse generation tasks demonstrate its applicability to autoregressive multi-token generation.

Introduction

In-context learning (ICL) enables large language models (LLMs) to adapt to new tasks from a small set of input-output demonstrations without gradient-based parameter updates Brown et al. [2]; Wies et al. [44]; Schoch & Ji [37]; Min et al. [27]. In explicit ICL, however, the demonstrations must be included in the prompt for every query Hao et al. [12]; Li et al. [19]. This increases sequence length and the associated prefill computation and memory requirements, particularly when the same task is repeatedly applied to many queries.

Recent studies address this cost through implicit ICL, which encodes demonstrations into task representations and applies them during inference without retaining the demonstration tokens. These representations are commonly derived from contextual hidden states, attention-head outputs, or activation differences Hendel et al. [13]; Todd et al. [41]; Liu et al. [24]; Liu & Deng [25]; Li et al. [21]. Prior results show that such representations can recover a substantial portion of the task behavior induced by explicit demonstrations while using shorter inference prompts.

While vector-based implicit ICL avoids retaining demonstrations in the inference prompt, it typically represents their effect using a fixed vector. Such a representation cannot account for the fact that the influence of the same demonstrations may vary with the current query and token representation.

To address this limitation, we propose Attention-Patching, which learns task-specific transformations that map attention representations to the activation shifts observed under explicit ICL. By fitting layer-wise affine mappings over paired forward passes, our method enables adaptive steering, producing input-dependent corrections in both direction and magnitude rather than applying a fixed steering direction. These mappings are incorporated directly into the attention output projections, preserving the original inference architecture without introducing additional matrix multiplications.

We evaluate Attention-Patching on 12 classification benchmarks across four model families. The results demonstrate consistent improvements in average accuracy over the evaluated implicit ICL baselines, with performance approaching or exceeding explicit few-shot ICL depending on the model.

Beyond classification, experiments on diverse generation tasks provide evidence that the learned patches extend to autoregressive multi-token generation. Because the learned patches are merged into the model weights, per-query inference cost of Attention-Patching remains close to zero-shot inference even when the task representation is derived from long demonstration contexts.

Overall, our contributions are threefold:

  • We introduce Attention-Patching, which represents the contextual effect of demonstrations as task-specific updates to the attention output projections.

  • Across classification and multi-token generation tasks, Attention-Patching generally outperforms evaluated implicit ICL baselines while remaining competitive with explicit ICL and maintaining inference cost close to zero-shot inference.

  • We analyze the adaptive steering behavior of the learned patches, showing that input-dependent weight transformations account for most of their performance and characterizing their structure across singular directions and model layers.

Related Work

Implicit In-Context Learning

Implicit ICL seeks to encode demonstrations into internal task representations that can be reused during query-only inference. Early approaches primarily differ in the activation source used to construct these representations. Hendel et al. [13] introduce Task Vectors (TV), which are extracted from hidden states at selected layers; Todd et al. [41] construct Function Vectors (FV) by aggregating the outputs of attention heads associated with ICL, Liu et al. [24] derive In-Context Vectors (ICV) as steering directions from activation differences between paired demonstration inputs and outputs.

More recent work has focused on improving the robustness and expressiveness of these representations, as well as their injection strategies. Zhang et al. [46] and Liu & Deng [25] aggregate or iteratively refine activation changes across demonstrations, whereas Li et al. [21] integrate attention and MLP representations through calibrated layer-wise coefficients. LTV Saglam et al. [36] and DyVec Cai et al. [3] further replace heuristic choices with learned strategies for composing attention-derived representations and determining their injection locations.

Beyond activation-vector methods, Dherin et al. [8] and Mazzawi et al. [26] propose Thought Patch, showing that contextual effects as implicit updates to downstream MLP weights and study static approximations in controlled settings. Attention-Patching instead targets the attention output projection, where demonstration-induced changes can be modeled before being propagated through downstream nonlinear dynamics.

Attention-based task adaptation

Prior work has identified specialized attention heads that support different aspects of ICL, including heads that encode task functions, retrieve contextual information, and access parametric knowledge ([28, 45, 16]). Complementary theoretical studies in controlled regression and categorical prediction settings show that multi-head attention performs layer-dependent computations that can be interpreted as preprocessing and optimization-like inference Von Oswald et al. [42]; Chen et al. [4]; Wang et al. [43].

Building on these findings, SITE (Park et al., [31]) learns task-specific head-wise coefficients to interpolate current head activations with fixed task embeddings extracted from few-shot prompts. In-Context Routing (ICR) (Li et al., [18]) trains a query-conditioned router on multiple tasks to combine cross-task query-key directions and modify attention logits.

These findings further motivate us to encode demonstration effects at the attention output projection, where information across attention heads is combined. Unlike SITE and ICR, Attention-Patching fits task-specific affine patches via ridge regression on activations collected from paired forward passes, without backpropagation through the language model.

Method

In this section, we introduce Attention-Patching by defining demonstration effect in attention (§ 3.1) and constructing affine attention patches to capture these effects (§ 3.2). We then provide an adaptive steering view of the learned patches in § 3.3.

Demonstration Effect in Attention

Let D\mathcal{D} denote an ordered sequence of demonstrations, and let Q={(xi,yi)}i=1M\mathcal{Q} = \{(x_i, y_i)\}_{i=1}^{M} denote MM query–answer pairs. For a query–answer pair (x,y)∈Q(x, y) \in\mathcal{Q}, we consider two prompts that contain the same query–answer pair but differ in whether the demonstrations are included:

pctx=[D;x;y],pnon-ctx=[x;y].p_{\mathrm{ctx}} = [\mathcal{D}; x; y], \qquad p_{\mathrm{non\text{-}ctx}} = [x; y].

We compare the attention outputs at the token positions corresponding to the query–answer pair under these two prompts. At layer ℓ\ell, let

Octx(ℓ)(x,y), Onon-ctx(ℓ)(x,y)∈Rn×doutO_{\mathrm{ctx}}^{(\ell)}(x, y),\ O_{\mathrm{non\text{-}ctx}}^{(\ell)}(x, y) \in\mathbb{R}^{n \times d_{\mathrm{out}}}

denote the corresponding attention outputs. Here, nn is the number of tokens in (x,y)(x, y), and doutd_{\mathrm{out}} is the representation dimension. We define the layer-wise demonstration effect as

δO(ℓ)(x,y)=Octx(ℓ)(x,y)−Onon-ctx(ℓ)(x,y).\delta O^{(\ell)}(x, y) = O_{\mathrm{ctx}}^{(\ell)}(x, y) - O_{\mathrm{non\text{-}ctx}}^{(\ell)}(x, y).

Attention-Patching

Calibration At each layer ℓ\ell, the attention output is obtained by applying the output projection (WO(ℓ),bO(ℓ))(W_O^{(\ell)}, b_O^{(\ell)}) to the attention representation Z(ℓ)Z^{(\ell)}:

O(ℓ)=Z(ℓ)WO(ℓ)+1nbO(ℓ)T,Z(ℓ)=Concat⁡h=1H(zh(ℓ)),O^{(\ell)} = Z^{(\ell)}W_O^{(\ell)} + \mathbf{1}_n b_O^{(\ell)\mathsf{T}}, \qquad Z^{(\ell)} = \operatorname{Concat}_{h=1}^{H}\left(z_h^{(\ell)}\right),

where zh(ℓ)z_h^{(\ell)} denotes the output of attention head hh. Accordingly, the demonstration effect defined in § 3.1 can be expressed as

δO(ℓ)(x,y)=(Zctx(ℓ)(x,y)−Znon-ctx(ℓ)(x,y))WO(ℓ),\delta O^{(\ell)}(x, y) = \left(Z_{\mathrm{ctx}}^{(\ell)}(x, y) - Z_{\mathrm{non\text{-}ctx}}^{(\ell)}(x, y)\right)W_O^{(\ell)},

where the shared output-projection bias cancels between the two forward passes.

Motivated by the affine structure of the output projection, we model the demonstration effect from the non-contextual attention representation as

δO^(ℓ)(x,y)=Znon−ctx(ℓ)(x,y)ΔW(ℓ)+1nΔb(ℓ)⊤,\widehat{\delta O}^{(\ell)}(x,y)=Z_{\mathrm{non-ctx}}^{(\ell)}(x,y)\Delta W^{(\ell)}+\mathbf{1}_n\Delta b^{(\ell)\top},

where (ΔW(ℓ),Δb(ℓ))(\Delta W^{(\ell)},\Delta b^{(\ell)}) parameterize the layer-wise attention patch.

Combining the demonstration effect with the non-contextual attention output gives

Octx(ℓ)=Onon−ctx(ℓ)+δO(ℓ)=Znon−ctx(ℓ)WO(ℓ)+1nbO(ℓ)⊤+(Zctx(ℓ)−Znon−ctx(ℓ))WO(ℓ)≈Znon−ctx(ℓ)(WO(ℓ)+ΔW(ℓ))+1n(bO(ℓ)+Δb(ℓ))⊤.\begin{aligned} O_{\mathrm{ctx}}^{(\ell)}=O_{\mathrm{non-ctx}}^{(\ell)}+\delta O^{(\ell)} \\ &=Z_{\mathrm{non-ctx}}^{(\ell)}W_O^{(\ell)}+\mathbf{1}_n b_O^{(\ell)\top}+\left(Z_{\mathrm{ctx}}^{(\ell)}-Z_{\mathrm{non-ctx}}^{(\ell)}\right)W_O^{(\ell)} \\ &\approx Z_{\mathrm{non-ctx}}^{(\ell)}\left(W_O^{(\ell)}+\Delta W^{(\ell)}\right)+\mathbf{1}_n\left(b_O^{(\ell)}+\Delta b^{(\ell)}\right)^\top. \end{aligned}

Thus, approximating the demonstration effect with the affine patch is equivalent to approximating the contextual attention output through an update to the original output projection.

To calibrate the patch parameters, we collect the non-contextual attention representations and their corresponding demonstration effects over the calibration set QQ. Let Z(ℓ)∈RN×dinZ^{(\ell)}\in\mathbb{R}^{N\times d_{\mathrm{in}}} and ΔO(ℓ)∈RN×dout\Delta O^{(\ell)}\in\mathbb{R}^{N\times d_{\mathrm{out}}} denote the row-wise concatenations of Znon−ctx(ℓ)(x,y)Z_{\mathrm{non-ctx}}^{(\ell)}(x,y) and δO(ℓ)(x,y)\delta O^{(\ell)}(x,y) over all (x,y)∈Q(x,y)\in Q, respectively, where NN is the total number of query-answer tokens in the calibration set.

The layer-wise attention patch is then fitted by ridge regression:

(ΔW∗(ℓ),Δb∗(ℓ))=arg⁡min⁡ΔW,Δb 1N∥Z(ℓ)ΔW+1NΔb⊤−ΔO(ℓ)∥F2+ρ∥ΔW∥F2,\left(\Delta W_*^{(\ell)},\Delta b_*^{(\ell)}\right)=\underset{\Delta W,\Delta b}{\arg\min}\ \frac{1}{N}\left\|Z^{(\ell)}\Delta W+\mathbf{1}_N\Delta b^\top-\Delta O^{(\ell)}\right\|_F^2+\rho\|\Delta W\|_F^2,

where ρ>0\rho>0 controls the regularization strength. This objective admits the following closed-form solution:

ΔW∗(ℓ)=(Zˉ(ℓ)⊤Zˉ(ℓ)+NρI)−1Zˉ(ℓ)⊤ΔO‾(ℓ),Δb∗(ℓ)⊤=μΔO(ℓ)−μZ(ℓ)ΔW∗(ℓ),\Delta W_*^{(\ell)}=\left(\bar Z^{(\ell)\top}\bar Z^{(\ell)}+N\rho I\right)^{-1}\bar Z^{(\ell)\top}\overline{\Delta O}^{(\ell)},\qquad\Delta b_*^{(\ell)\top}=\mu_{\Delta O}^{(\ell)}-\mu_Z^{(\ell)}\Delta W_*^{(\ell)},

where Zˉ(ℓ)\bar Z^{(\ell)} and ΔO‾(ℓ)\overline{\Delta O}^{(\ell)} denote the centered versions of Z(ℓ)Z^{(\ell)} and ΔO(ℓ)\Delta O^{(\ell)}, respectively. The full derivation and definitions are provided in Appendix A.1, with a functional view of the learned patches presented in Appendix A.2.

Inference. To reduce sensitivity to the calibration set QQ, we introduce a scalar patch strength α\alpha that controls the magnitude of the calibrated patch. After calibration, the scaled layer-wise patches are merged into the original attention output projections:

WO(ℓ)←WO(ℓ)+αΔW∗(ℓ),bO(ℓ)←bO(ℓ)+αΔb∗(ℓ).W_O^{(\ell)}\leftarrow W_O^{(\ell)}+\alpha\Delta W_*^{(\ell)},\qquad b_O^{(\ell)}\leftarrow b_O^{(\ell)}+\alpha\Delta b_*^{(\ell)}.

The coefficient α\alpha therefore controls the strength of the learned contextual correction while preserving the same parameterization as the original attention output projection. Once merged, the patch is applied through the existing projection and requires no additional matrix multiplication or intervention module at inference time. The overall framework is depicted in Figure 1, and the pseudocode is provided in Algorithm 1 (Appendix A.3).

Framework of Attention-Patching

Figure 1. Framework of Attention-Patching. Attention output shifts induced by demonstrations are used to learn task-specific mappings, incorporated into the attention output projections for inference.

Adaptive Steering with Attention-Patching

At token position tt, applying the calibrated attention patch with strength α\alpha yields

δO^t=α(Znon−ctxtΔW∗+Δb∗⊤),\widehat{\delta O}_t=\alpha\left(Z_{\mathrm{non-ctx}}^t\Delta W_*+\Delta b_*^\top\right),

where we omit the layer index for clarity. Using the singular value decomposition ΔW∗=UΣV⊤=∑iσiuivi⊤\Delta W_*=U\Sigma V^\top=\sum_i\sigma_i u_i v_i^\top, the correction becomes

δO^t=α(∑iσi(Znon−ctxtui)vi⊤+Δb∗⊤).\widehat{\delta O}_t=\alpha\left(\sum_i\sigma_i\left(Z_{\mathrm{non-ctx}}^t u_i\right)v_i^\top+\Delta b_*^\top\right).

This decomposition provides an adaptive steering view of Attention-Patching. The right singular vectors viv_i define task-specific steering directions, with coefficients σi(Znon−ctxtui)\sigma_i(Z_{\mathrm{non-ctx}}^t u_i) that vary with the current attention representation across inputs and token positions. The bias term Δb∗⊤\Delta b_*^\top provides a shared additive correction, and the patch strength α\alpha controls the overall correction magnitude.

Experiments

Experimental Setup

Models We evaluate Attention-Patching (AP) using four open-weight language model families: Llama-3.2-3B-Instruct (Grattafiori et al., [11]), Qwen3.5-0.8B (Qwen Team, [32]), Mistral-7B-Instruct-v0.3 (Jiang et al., [15]), Gemma-2-27b-it and Gemma-2-2b-it (Team et al., [40]).

Baselines Across 12 classification benchmarks, we compare Attention-Patching with 0-shot and explicit few-shot ICL. We also include LoRA (Hu et al., [14]) and SITE (Park et al., [31]), both of which require gradient-based optimization. We consider six vector-based implicit ICL baselines: Task Vector (TV) (Hendel et al., [13]), Function Vector (FV) (Todd et al., [41]), Iterative Vectors (IV) (Liu & Deng, [25]), Implicit In-context Learning (I2CL) (Li et al., [21]), ICV (Liu et al., [24]), and Linear Task Vector (LTV) (Kwon et al., [17]). We also compare against Thought Patching (TP) (Mazzawi et al., [26]). For all baselines, we follow the experimental details reported in their original papers.

Evaluation Following Li et al. [18], we evaluate each method on up to 500 instances from the evaluation split of each of the 12 benchmarks, using all available instances for smaller datasets. We evaluate the classification tasks: AGNews (Zhang et al., [47]), SST-2 (Socher et al., [39]), TREC (Li & Roth, [20]), CSQA (Talmor et al., 2019), PIQA (Bisk et al., [1]), SST-5 (Socher et al., [39]), MR (Pang & Lee, [30]), MRPC (Dolan & Brockett, [9]), CB (de Marneffe et al., [7]), COPA (Roemmele et al., [35]), CREAK (Onoe et al., [29]), and AI2SciE (Clark et al., [5]), using five random seeds. For the multi-token prediction task, we evaluate on GSM8K (Cobbe et al., 2021), FLORES (Korean and Spanish subsets) [10], DailyMail (See et al., 2017) and CommonGen [22]. Other details are in Appendix § 11.§ 1.

Main Results

Table 1 presents the results on Llama-3.2-3B-Instruct, Gemma-2-27b-it, and Qwen3.5-0.8B. Additional results on Mistral-7B-Instruct-v0.3 and Gemma-2-2b-it are provided in Appendix § 12.§ 1.

MethodAvg.AGSST-2TRECCSQAPIQASST-5MRMRPCCBCOPACREAKAI2SciE
Llama-3.2-3B-Instruct
0-shot73.558.890.862.076.675.633.889.066.967.9_94.0_79.287.0
ICL_78.6_86.4(±1.5)93.5(±0.5)_79.9(±4.5)_73.4(±1.4)74.9(±2.0)47.8(±2.6)91.2(±0.9)50.7(±7.1)83.6(±4.6)88.8(±1.9)86.0(±0.4)86.9(±0.7)
LoRA77.187.4(±0.8)91.1(±0.6)86.3(±1.7)76.3(±0.5)76.0(±0.5)43.8(±1.8)88.8(±0.8)56.3(±5.2)64.6(±1.5)94.4(±0.5)73.0(±2.9)87.2(±0.2)
SITE77.988.8(±1.7)91.7(±0.5)78.3(±8.4)73.4(±0.7)75.8(±2.5)38.2(±1.7)90.4(±0.4)_68.4(±0.0)_67.9(±10.3)91.0(±4.3)84.1(±1.3)87.0(±1.4)
TV71.368.8(±3.8)90.7(±0.3)69.9(±2.7)76.2(±0.2)76.1(±1.1)31.0(±5.4)90.2(±0.6)40.9(±13.1)54.3(±19.1)90.8(±2.4)79.4(±1.2)87.4(±0.3)
I2CL74.683.3(±3.3)86.3(±2.6)79.5(±7.3)68.8(±2.2)_74.2(±2.0)_41.9(±2.6)88.4(±1.9)59.4(±4.7)65.0(±6.9)90.2(±3.4)72.8(±4.2)85.1(±1.4)
FV73.561.1(±1.2)91.4(±0.6)81.4(±0.8)71.9(±0.9)74.2(±1.6)31.2(±1.2)88.5(±0.4)53.0(±1.5)_82.0(±1.0)_82.5(±1.9)77.4(±1.6)87.8(±0.5)
IV72.684.8(±2.1)92.6(±0.4)70.0(±1.9)67.6(±1.0)73.2(±1.3)45.9(±2.1)88.2(±0.4)31.6(±0.0)70.5(±3.7)74.7(±1.3)85.9(±1.2)86.6(±0.5)
ICV74.564.4(±0.7)88.5(±1.5)71.0(±2.6)75.8(±0.3)76.4(±0.7)35.7(±0.4)88.9(±0.3)66.9(±0.0)67.9(±0.0)94.0(±0.0)79.0(±0.4)85.9(±0.5)
LTV76.679.3(±3.1)92.0(±1.2)81.1(±3.6)71.9(±2.2)72.6(±3.8)42.4(±1.7)89.4(±1.5)49.0(±4.3)78.9(±2.9)92.2(±2.7)82.2(±2.3)_87.7(±1.4)_
TP70.874.6(±3.6)88.0(±0.9)71.4(±5.2)62.4(±2.0)74.6(±1.2)38.4(±2.9)88.4(±1.2)64.4(±4.7)78.6(±4.4)88.2(±2.2)75.2(±3.0)45.7(±5.1)
AP (Ours)80.785.8(±2.9)93.0(±0.6)83.9(±1.5)76.2(±0.4)75.8(±0.2)46.7(±2.5)91.1(±0.8)68.7(±0.8)79.6(±7.2)93.2(±1.3)86.0(±1.3)87.7(±0.8)
Gemma-2-27b-it
0-shot82.278.295.277.680.488.839.693.863.785.798.087.6_97.8_
ICL87.988.6(±1.0)94.7(±0.6)91.6(±2.4)85.7(±0.4)90.4(±0.5)55.3(±2.3)93.7(±0.2)75.0(±1.6)90.0(±2.0)100.0(±0.0)92.7(±0.6)97.0(±0.2)
LoRA86.989.4(±0.9)94.6(±1.2)91.8(±2.7)82.8(±0.6)87.5(±1.2)52.5(±4.6)91.7(±3.6)77.0(±2.7)87.9(±2.6)99.0(±0.7)91.4(±1.4)97.6(±0.3)
SITE85.190.3(±1.2)95.5(±0.5)84.7(±3.4)82.3(±0.6)87.8(±1.3)40.4(±1.5)93.6(±0.5)68.9(±1.1)90.4(±1.0)98.8(±0.4)91.4(±1.2)97.1(±0.2)
TV81.581.3(±2.9)95.0(±0.2)79.0(±1.4)80.8(±0.3)88.1(±0.5)39.2(±0.3)93.6(±0.4)56.5(±2.8)80.7(±0.8)98.0(±1.0)86.0(±1.2)97.5(±1.0)
I2CL82.784.4(±3.9)92.0(±0.6)82.4(±5.1)80.2(±0.6)87.7(±1.1)42.1(±3.4)92.3(±1.0)64.7(±11.7)83.6(±5.6)99.2(±0.5)85.9(±3.3)97.2(±0.3)
FV85.088.0(±0.6)96.0(±0.5)85.5(±0.2)82.6(±0.6)86.4(±0.9)47.4(±1.4)92.9(±0.4)72.4(±0.8)90.4(±2.0)98.8(±0.4)82.0(±0.8)97.4(±0.3)
IV86.3_89.5(±0.6)_94.8(±0.9)87.9(±0.9)83.4(±1.0)85.9(±1.1)49.1(±1.8)92.5(±1.0)75.4(±1.1)92.4(±1.0)99.1(±0.8)89.0(±0.4)97.2(±0.4)
ICV82.278.1(±2.0)94.4(±0.5)78.4(±1.1)81.0(±0.4)88.7(±1.0)39.4(±1.0)93.8(±0.8)63.5(±0.4)84.6(±1.0)98.0(±0.0)89.3(±1.7)97.6(±1.1)
LTV85.988.2(±0.9)95.8(±0.7)88.3(±1.0)81.3(±0.9)88.9(±0.5)50.5(±3.3)92.6(±1.1)68.0(±1.1)91.1(±1.9)97.8(±0.4)92.1(±1.0)98.1(±0.5)
TP84.783.8(±2.0)94.8(±0.7)84.1(±1.1)83.4(±0.7)88.9(±0.5)39.6(±0.4)93.7(±0.3)68.3(±1.6)93.9(±1.0)99.0(±0.0)90.0(±0.9)96.5(±0.4)
AP (Ours)_87.3_89.2(±1.0)95.1(±0.2)91.3(±1.8)81.5(±0.7)_88.9(±0.5)_53.3(±2.3)93.6(±0.7)74.6(±1.2)91.8(±3.7)_99.8(±0.4)_90.3(±1.2)97.5(±0.4)
Qwen3.5-0.8B
0-shot61.064.288.462.849.059.028.686.468.432.156.057.679.6
ICL68.581.2(±2.4)83.4(±5.2)76.8(±5.9)56.6(±0.7)62.4(±1.1)43.8(±2.7)85.4(±5.2)72.4(±14.2)69.6(±5.8)62.2(±3.4)72.6(±3.0)85.0(±0.6)
LoRA62.879.4(±3.0)85.9(±1.1)69.5(±7.8)57.1(±0.8)60.5(±1.3)35.0(±1.8)84.4(±1.6)31.9(±0.3)32.9(±4.8)73.4(±1.1)60.0(±3.1)83.5(±0.7)
SITE69.484.8(±2.3)88.2(±1.1)71.6(±14.0)57.2(±1.4)64.1(±4.3)25.1(±2.4)85.4(±0.8)68.4(±0.0)57.1(±13.7)78.2(±1.3)_69.6(±5.7)_83.7(±1.0)
TV66.073.3(±4.6)86.4(±2.3)64.4(±1.8)53.4(±1.5)65.2(±1.0)27.4(±4.0)84.8(±0.4)65.3(±6.9)52.1(±12.7)_78.0(±3.5)_58.4(±1.0)83.3(±0.3)
I2CL64.973.6(±6.5)85.6(±2.9)69.3(±6.8)49.7(±2.9)56.0(±5.2)34.2(±2.2)81.9(±2.7)56.1(±1.4)56.4(±14.7)74.8(±2.6)63.7(±3.1)77.4(±3.6)
FV56.975.3(±1.5)81.9(±0.8)77.5(±0.5)26.6(±0.5)53.0(±1.1)33.0(±1.7)76.2(±1.2)33.1(±0.1)52.5(±2.0)45.7(±1.0)62.7(±1.4)64.7(±1.1)
IV70.180.2(±1.5)83.3(±1.6)80.9(±1.0)_57.5(±0.6)_62.2(±1.3)37.3(±2.6)82.6(±0.8)68.1(±1.3)80.0(±0.5)54.1(±5.9)72.9(±1.9)82.3(±0.8)
ICV60.463.6(±0.8)87.0(±0.7)56.6(±2.2)52.0(±0.8)57.7(±0.5)31.0(±1.4)84.4(±0.6)59.9(±7.3)37.9(±10.4)57.2(±2.9)57.2(±2.3)80.0(±0.4)
LTV64.376.8(±1.4)82.7(±2.4)66.4(±8.3)53.5(±1.4)59.6(±2.5)32.2(±2.2)84.6(±2.0)56.8(±3.4)48.9(±8.9)67.6(±2.1)61.6(±2.4)81.5(±1.0)
TP56.254.9(±3.4)78.1(±1.3)49.0(±5.7)37.4(±3.9)61.1(±1.2)27.1(±2.4)81.5(±2.3)68.3(±0.1)58.2(±6.6)57.8(±2.4)59.6(±2.0)41.8(±3.4)
AP (Ours)70.481.5(±1.2)88.3(±1.5)73.2(±3.8)59.0(±2.5)64.2(±1.9)37.9(±2.6)85.3(±1.6)67.9(±0.4)63.9(±5.9)73.8(±2.9)66.8(±6.7)83.2(±0.9)

Table 1. Baseline comparison across classification benchmarks. All results are averaged over five independent runs. The best and second-best results in each column within each model are indicated in bold and underline, respectively. Method abbreviations are defined in § 4.1.

Attention-Patching outperforms implicit ICL baselines. As shown in Table 1, Attention-Patching achieves the highest average accuracy among the evaluated implicit ICL methods across all three models. With 25 calibration examples per class, Attention-Patching obtains average accuracies of 80.7, 87.3, and 70.4 on Llama-3.2-3B-Instruct, Gemma-2-27b-it, and Qwen3.5-0.8B, respectively, outperforming the strongest implicit ICL baseline on each model by 2.8, 1.0, and 0.3 percentage points.

Attention-Patching remains competitive with explicit ICL. Despite processing only query tokens at inference time, Attention-Patching achieves performance comparable to explicit ICL across the three models. Specifically, Attention-Patching exceeds explicit ICL by 2.1 and 1.9 percentage points on Llama and Qwen, respectively, while remaining within 0.6 points on Gemma-2-27b-it. Compared with LoRA, Attention-Patching also achieves higher average accuracy across all three models, with improvements of 3.6, 0.4, and 7.6 percentage points, respectively. These findings suggest that the learned weight-space transformations can match or exceed the predictive performance of explicit prompting and LoRA on the evaluated classification tasks.

Multi-token Generation Task

To examine whether the learned patches remain effective beyond single-token classification, we evaluate Attention-Patching on four autoregressive generation tasks using 32 calibration samples. GSM8K is evaluated using flexible-match accuracy, while DailyMail and CommonGen use ROUGE-L F1 [23]. For FLORES, COMET [33], a neural metric for translation quality, is reported alongside ROUGE-L F1 to complement lexical overlap. We compare Attention-Patching against SITE, ICV, and LTV, whose original formulations support autoregressive generation. Other implicit ICL baselines primarily target single-token prediction and lack a standardized intervention procedure for multi-token decoding.

As shown in Table 2, Attention-Patching generally outperforms the evaluated implicit ICL baselines across generation tasks and demonstration-context budgets. Averaged across the five context budgets on Llama, Attention-Patching achieves 70.3 accuracy on GSM8K, compared with 69.4 for SITE and 70.3 for explicit many-shot ICL. On FLORES Korean and Spanish, Attention-Patching obtains average ROUGE-L F1 scores of 19.9 and 52.0 and COMET scores of 76.5 and 84.6, respectively, outperforming SITE on both metrics. On DailyMail and CommonGen, Attention-Patching achieves average ROUGE-L F1 scores of 22.8 and 55.9 on Llama, and 26.2 and 60.3 on Gemma, respectively, approaching explicit many-shot ICL performance. These results suggest that the learned patches remain effective during autoregressive multi-token generation.

MethodAvg.GSM8KFLORES(Ko) ROUGE-L F1FLORES(Ko) COMETFLORES(Sp) ROUGE-L F1FLORES(Sp) COMETDailyMailCommonGen
ROUGE-L F1COMETROUGE-L F1COMET
Llama-3.2-3B-Instruct
Zero-shot42.951.4(±0.7)4.8(±0.5)47.3(±0.3)50.6(±0.2)83.2(±0.5)16.8(±0.3)45.8(±0.4)
LoRA47.456.1(±2.9)11.4(±1.3)62.7(±3.3)51.1(±0.4)84.2(±0.2)18.1(±1.4)48.2(±0.5)
Many-shot (1K)55.169.6(±3.3)21.3(±1.0)79.3(±0.5)51.8(±0.1)85.0(±0.4)22.1(±0.9)56.9(±1.4)
SITE47.969.4(±2.6)8.6(±0.7)56.6(±0.7)50.7(±1.1)84.0(±0.4)16.9(±0.3)49.1(±0.2)
ICV43.052.1(±1.4)5.2(±0.3)46.4(±0.8)51.0(±0.2)83.5(±0.3)16.9(±0.2)46.1(±0.6)
LTV38.139.9(±0.6)10.2(±1.1)45.7(±0.4)49.7(±0.8)82.7(±0.9)17.8(±0.8)20.4(±4.3)
AP54.670.4(±5.1)20.4(±0.7)77.6(±0.4)51.9(±0.4)84.6(±0.3)21.1(±1.5)56.4(±1.1)
Many-shot (2K)55.470.9(±1.3)21.0(±0.7)77.0(±5.0)51.8(±0.1)85.3(±0.2)24.5(±0.8)57.1(±1.1)
SITE48.369.4(±1.2)9.6(±0.9)57.7(±1.4)50.9(±0.6)84.1(±0.3)16.9(±0.4)49.4(±0.1)
ICV43.152.8(±0.9)5.2(±0.4)46.3(±0.3)51.1(±0.3)83.6(±0.3)17.0(±0.2)45.9(±0.4)
LTV38.242.1(±3.8)9.8(±2.0)45.6(±1.2)49.1(±1.8)82.2(±1.6)17.5(±0.6)21.3(±6.1)
AP54.570.1(±1.5)19.7(±0.6)76.0(±2.2)52.0(±0.3)84.6(±0.3)22.0(±1.2)57.0(±1.3)
Many-shot (4K)55.870.9(±0.6)21.5(±0.9)79.7(±0.4)51.6(±0.3)85.2(±0.4)25.3(±1.3)56.2(±1.4)
SITE48.470.1(±3.3)10.1(±0.2)57.5(±0.4)51.0(±0.8)84.1(±0.3)16.9(±0.4)49.2(±0.7)
ICV43.252.7(±1.9)5.1(±0.6)46.8(±1.0)51.0(±0.2)83.5(±0.2)16.9(±0.2)46.2(±0.4)
LTV38.042.8(±3.9)10.2(±1.5)46.1(±1.1)47.8(±2.1)81.1(±1.8)17.1(±0.3)21.0(±7.4)
AP54.970.4(±2.3)20.6(±0.7)77.1(±0.7)52.1(±0.3)84.7(±0.1)23.4(±2.4)55.9(±1.2)
Many-shot (8K)55.770.2(±1.1)21.0(±0.5)79.7(±0.3)51.5(±0.3)85.3(±0.1)26.4(±0.4)56.0(±0.6)
SITE48.268.7(±4.3)9.9(±0.5)57.6(±1.4)51.1(±0.5)84.2(±0.2)16.9(±0.4)49.0(±0.6)
ICV43.052.0(±0.9)5.3(±0.5)46.4(±0.8)51.0(±0.3)83.5(±0.3)16.9(±0.2)46.2(±0.7)
LTV37.441.5(±3.2)8.9(±0.4)45.7(±0.8)48.0(±1.5)81.2(±1.5)16.9(±0.2)19.2(±5.6)
AP54.370.7(±4.6)19.0(±0.7)75.4(±1.8)52.0(±0.4)84.6(±0.4)23.5(±0.2)55.1(±0.6)
Many-shot (16K)55.769.7(±2.3)20.8(±0.9)79.7(±0.6)51.6(±0.2)85.3(±0.1)26.2(±0.4)56.9(±1.4)
SITE47.969.4(±1.2)8.7(±0.3)56.0(±1.5)50.7(±0.8)83.9(±0.5)17.0(±0.5)49.3(±0.6)
ICV43.051.8(±1.8)5.2(±0.3)46.4(±0.9)50.9(±0.2)83.4(±0.2)17.0(±0.2)46.2(±0.4)
LTV36.941.0(±0.3)8.4(±3.1)44.8(±2.6)46.7(±2.4)80.3(±2.2)16.8(±0.4)20.0(±7.6)
AP54.670.0(±0.0)20.0(±1.2)76.3(±1.2)52.0(±0.2)84.7(±0.1)24.1(±0.3)55.1(±1.1)
Gemma-2-27b-it
Zero-shot58.779.8(±0.5)23.5(±0.8)89.4(±0.2)55.7(±0.1)86.9(±0.2)21.0(±0.3)54.8(±0.4)
LoRA55.058.8(±7.9)23.6(±1.0)89.6(±0.1)52.6(±1.7)86.5(±0.8)14.4(±3.4)59.3(±0.8)
Many-shot (1K)61.988.1(±1.7)24.0(±1.5)90.2(±0.0)56.3(±0.3)87.5(±0.2)25.6(±0.6)61.6(±1.2)
SITE59.178.9(±0.8)23.5(±0.7)89.7(±0.2)55.5(±0.1)87.0(±0.2)21.8(±0.1)57.1(±0.8)
ICV59.080.1(±0.6)24.1(±1.3)89.2(±0.1)55.8(±0.1)86.9(±0.2)21.4(±0.2)55.1(±0.3)
LTV58.278.4(±3.2)23.4(±1.1)88.9(±0.6)55.7(±0.1)86.9(±0.2)20.4(±0.7)53.9(±1.4)
AP61.084.0(±1.0)24.1(±0.9)89.8(±0.1)56.0(±0.2)87.3(±0.2)24.9(±0.7)60.8(±0.9)
Many-shot (2K)62.087.7(±0.9)23.7(±1.5)90.2(±0.0)56.3(±0.3)87.7(±0.1)27.1(±0.7)61.4(±1.1)
SITE59.178.8(±0.9)23.5(±0.9)89.8(±0.1)55.3(±0.2)86.9(±0.3)22.3(±0.3)56.9(±0.4)
ICV58.980.1(±0.4)24.2(±1.3)89.2(±0.2)55.8(±0.1)86.9(±0.2)21.3(±0.2)55.0(±0.3)
LTV58.379.9(±2.9)23.5(±1.3)88.9(±0.5)55.8(±0.1)86.9(±0.2)19.3(±0.9)53.8(±1.1)
AP61.184.4(±3.7)24.3(±1.1)89.7(±0.3)56.2(±0.3)87.5(±0.2)26.5(±0.6)60.6(±0.7)
Many-shot (4K)62.288.1(±2.2)24.0(±0.8)90.2(±0.0)56.3(±0.3)87.8(±0.1)27.8(±0.7)61.5(±1.3)
SITE59.279.4(±1.1)23.1(±0.7)89.8(±0.1)55.6(±0.4)87.0(±0.2)22.9(±0.2)56.8(±0.6)
ICV59.080.3(±0.3)24.3(±1.2)89.2(±0.1)55.7(±0.1)86.9(±0.2)21.5(±0.5)55.3(±0.5)
LTV58.480.9(±0.6)23.8(±1.2)89.0(±0.4)55.7(±0.2)86.9(±0.3)18.5(±1.3)53.8(±0.4)
AP61.082.2(±1.9)24.1(±1.0)89.6(±0.2)56.3(±0.2)87.5(±0.2)27.3(±0.6)59.6(±1.1)

Table 2. Multi-token generation results under different context lengths, averaged over three independent runs. We report flexible-match accuracy on GSM8K, ROUGE-L F1 and COMET scores on FLORES, and ROUGE-L F1 scores on DailyMail and CommonGen. The best and second-best results in each column within each model and context length are indicated in bold and underline, respectively.

Analysis

Inference Efficiency

To investigate whether Attention-Patching preserves the inference efficiency, we measure its computational cost as the demonstration context used for calibration increases in length.

FLOPs. Figure 2 compares the per-query inference cost of Attention-Patching with zero-shot, LoRA, LTV, SITE, ICV, PrefixKV Caching, and many-shot ICL on GSM8K across context lengths from 1K to 16K tokens. We estimate FLOPs using an analytical FLOP counter based on runtime tensor shapes. All results are normalized by the corresponding zero-shot result. As context length increases, the computational cost of explicit ICL rises from 10.22×10.22 \times to 269.29×269.29 \times that of zero-shot inference. In contrast, Attention-Patching maintains approximately the same per-query FLOPs as zero-shot inference, as the learned updates are incorporated directly into the existing attention output projections.

Average inference FLOPs and TTFT on GSM8K across different context lengths

Figure 2. Average inference FLOPs and TTFT on GSM8K using Llama-3.2-3B-Instruct across different context lengths, averaged over 500 samples.

TFTT. A similar trend holds for time-to-first-token (TTFT). Many-shot ICL increases from 4.75× to 122.91×, while Attention-Patching remains within 0.99–1.00× of zero-shot inference. ICV also avoids processing demonstration tokens and has approximately constant FLOPs, but incurs a TTFT overhead of 1.45–1.47×, since each layer and token position requires adding a steering vector and renormalizing the activation. Together, the FLOPs and TTFT measurements show that Attention-Patching introduces negligible per-query inference overhead.

Role of Linear and Bias Components

To understand whether the gains of Attention-Patching stem from input-dependent transformations or fixed additive corrections, we compare linear, bias, and full affine patch formulations. We evaluate two variants: Bias-only, parameterized by Δb(ℓ)\Delta b^{(\ell)}, and Weight-only, parameterized by Z(ℓ)ΔW(ℓ)Z^{(\ell)}\Delta W^{(\ell)}.

As shown in Table 3, the weight component accounts for most of the performance of the full patch. On the classification benchmarks, Bias-only achieves an average accuracy of 72.8, whereas Weight-only reaches 80.6, nearly matching the 80.7 accuracy of the full Bias + Weight parameterization.

MethodAGSST-2TRECCSQAPIQASST-5MRMRPCCBCOPACREAKAI2SciEAvg.
Bias58.887.168.776.175.834.289.068.258.293.877.287.072.8
Weight85.793.184.675.776.046.690.868.380.092.686.087.680.6
Full85.893.083.976.275.846.791.168.779.693.286.087.780.7

Table 3. Component ablation of Attention-Patching on Llama-3.2-3B-Instruct. We report average accuracy across the 12 classification benchmarks.

From the adaptive steering perspective, ΔW(ℓ)\Delta W^{(\ell)} combines multiple steering directions with input-dependent coefficients, whereas Δb(ℓ)\Delta b^{(\ell)} provides only a single fixed steering vector. This explains the smaller contribution of the bias component and suggests that the effectiveness of Attention-Patching primarily arises from input-dependent transformations rather than fixed additive corrections.

Singular Structure of Adaptive Steering

To empirically examine the adaptive steering interpretation in § 3.3, we compare the learned weight patch with a bias-only variant. For the bias-only variant, the closed-form solution is Δbbias⊤=μΔO=1N∑j=1NδOj\Delta b_{\mathrm{bias}}^{\top} = \mu\Delta O = \frac{1}{N}\sum_{j=1}^{N}\delta O_j, which corresponds to a fixed steering vector and matches the averaging form used in Contrastive Activation Addition [34].

We then replace ΔW⋆\Delta W_{\star} with its rank-kk truncated SVD, ΔW⋆,k=∑i=1kσiuivi⊤\Delta W_{\star,k} = \sum_{i=1}^{k}\sigma_i u_i v_i^{\top}, while retaining the bias Δb⋆\Delta b_{\star} learned jointly with the full affine patch. The resulting correction is

δOkt=α(∑i=1kσi(Znon−ctxtui)vi⊤+Δb⋆⊤).\delta O_k^{t} = \alpha\left(\sum_{i=1}^{k}\sigma_i\left(Z_{\mathrm{non-ctx}}^{t}u_i\right)v_i^{\top}+\Delta b_{\star}^{\top}\right).

Unlike a fixed steering vector, the contribution of each singular direction is modulated by the current attention representation. Note that k=0k = 0 retains only the bias of the full affine patch and is therefore distinct from the separately fitted bias-only variant.

As shown in Figure 3, the k=0k = 0 intervention shows positive alignment with the bias-only steering vector, with a cosine similarity of 0.636. As the leading singular components are incorporated, the similarity steadily decreases to 0.438, while average accuracy increases from 73.0 to 80.7. This trend

Singular structure of adaptive steering on Llama-3.2-3B-Instruct

Figure 3. Singular structure of adaptive steering on Llama-3.2-3B-Instruct. Average accuracy across 12 classification tasks (left) and cosine similarity to the bias-only steering vector averaged across tasks and layers (right) using rank-kk truncated SVD of the weight patch.

supports the adaptive steering view, where singular directions provide input-dependent refinements beyond a fixed steering vector.

Layer-wise Structure of Learned Patches

Figure 4 illustrates the layer-wise structure of the learned patches across different model architectures, characterizing their update magnitude and effective dimensionality using the normalized Frobenius norm and stable rank, respectively.

Layer-wise structure of the learned attention patches across classification benchmarks

Figure 4. Layer-wise structure of the learned attention patches across classification benchmarks. The top row shows the normalized Frobenius norm of the patch weights, while the bottom row shows their stable rank. Each column corresponds to a model architecture, and each curve represents one classification task.

For each layer ℓ\ell, the top row of Figure 4 reports the update magnitude using the normalized Frobenius norm: m(ℓ)=∥ΔW(ℓ)∥Fdindoutm^{(\ell)} = \frac{\lVert\Delta W^{(\ell)} \rVert_{\mathrm{F}}}{\sqrt{d_{\mathrm{in}}d_{\mathrm{out}}}}, and the bottom row reports the stable rank of each matrix update:

srank⁡(ΔW(ℓ))=∥ΔW(ℓ)∥F2∥ΔW(ℓ)∥22=∑i(σi(ℓ))2(max⁡iσi(ℓ))2,\operatorname{srank}(\Delta W^{(\ell)}) = \frac{\lVert\Delta W^{(\ell)} \rVert_{\mathrm{F}}^2}{\lVert\Delta W^{(\ell)} \rVert_2^2} = \frac{\sum_i \left(\sigma_i^{(\ell)}\right)^2}{\left(\max_i \sigma_i^{(\ell)}\right)^2},

where σi(ℓ)\sigma_i^{(\ell)} denotes the ii-th singular value of ΔW(ℓ)\Delta W^{(\ell)}.

The two measures exhibit distinct layer-wise patterns across model architectures, indicating that larger updates do not necessarily correspond to higher-dimensional transformations. This suggests that Attention-Patching distributes task-specific corrections across different layers and singular directions rather than relying on a uniform intervention throughout the model.

Performance Alignment Between ICL and Attention-Patching

To investigate whether AP captures the task-specific behavior of explicit ICL, we analyze the relationship between the performance changes induced by explicit ICL and AP. For each task and model, we compute the performance differences relative to zero-shot inference: ICL − Zero-shot and AP − Zero-shot. As shown in Figure 5, the two performance differences exhibit strong positive correlations across all five models, with Pearson correlation coefficients ranging from 0.850 to 0.998. These results suggest that AP closely follows the performance trends of explicit ICL.

Correlation between performance changes induced by explicit ICL and AP relative to zero-shot inference

Figure 5. Correlation between performance changes induced by explicit ICL and AP relative to zero-shot inference. Each point represents a task.

Conclusion

We introduce Attention-Patching, a method that compresses the effects of in-context demonstrations into attention patches, enabling query-only inference without repeatedly processing the demonstrations. Across 12 classification benchmarks, Attention-Patching achieved the strongest average performance among the evaluated implicit ICL methods, while remaining competitive with explicit ICL. Attention-Patching also generally outperformed the evaluated implicit ICL methods on multi-token generation tasks across context budgets from 1K to 16K tokens, demonstrating its applicability beyond single-token classification. These results suggest Attention-Patching as an effective approach for retaining demonstration-induced behavior while reducing the inference-time overhead of explicit ICL.

Discussion and Limitations

Attention-Patching enables backpropagation-free adaptation by capturing demonstration-induced effects from internal model representations and incorporating them directly into attention projections without additional inference-time modules. However, this approach requires access to internal activations and model weights, limiting its applicability to open-weight models rather than closed-source models accessible only through black-box APIs.

AI USE STATEMENT

In this work, we used generative AI tools to assist with translation, improve the readability and clarity of the manuscript, assist in the writing of proofs, and assist with code implementation. All AI-assisted content was reviewed and verified by the authors, who take full responsibility for the final content of this work. We have not used generative AI tools for developing theoretical models or conceptual frameworks, formulating mathematical claims, providing critical ingredients for proving mathematical claims, proposing or refining hypotheses, designing or providing feedback on research methodology or experiments, cleaning and reformatting datasets, or interpreting results. Generating synthetic datasets and supporting qualitative and thematic data analysis were not applicable to this work.

REPRODUCIBILITY STATEMENT

We provide the source code and configurations for all key experiments, including model training and evaluation. Detailed descriptions of the proposed method, experimental settings, and implementation details are provided in Section 4.1 and Appendix B.1 to facilitate reproducibility.

Theoretical Analysis of Attention-Patching

Derivation of the Closed-Form Ridge Solution

In this section, we derive the closed-form solution used to compute the layer-wise attention patch in Attention-Patching. For conciseness, we omit the layer index ℓ\ell throughout the derivation.

We collect the non-contextual attention representations and their target demonstration effects over all query-answer token positions in the calibration set as

Z∈RN×din,ΔO∈RN×dout,Z \in\mathbb{R}^{N \times d_{\mathrm{in}}}, \qquad\Delta O \in\mathbb{R}^{N \times d_{\mathrm{out}}},

where NN is the total number of query-answer token positions. The rows of ZZ are taken from Znon−ctxZ_{\mathrm{non-ctx}}, and the corresponding rows of ΔO\Delta O are the demonstration effects δO\delta O defined in § 3.1.

The patch parameters

ΔW∈Rdin×dout,Δb∈Rdout\Delta W \in\mathbb{R}^{d_{\mathrm{in}} \times d_{\mathrm{out}}}, \qquad\Delta b \in\mathbb{R}^{d_{\mathrm{out}}}

are fitted by

min⁡ΔW,ΔbL(ΔW,Δb)=1N∥ZΔW+1NΔbT−ΔO∥F2+ρ∥ΔW∥F2,\min_{\Delta W,\Delta b}\mathcal{L}(\Delta W,\Delta b)=\frac{1}{N}\left\|Z\Delta W+\mathbf{1}_{N}\Delta b^{\mathsf{T}}-\Delta O\right\|_{F}^{2}+\rho\left\|\Delta W\right\|_{F}^{2},

where 1N\mathbf{1}_{N} is the all-ones vector and ρ>0\rho> 0 is the ridge coefficient.

We first solve for the bias term. Differentiating the objective with respect to Δb\Delta b gives

∇ΔbL=2N(ZΔW+1NΔbT−ΔO)T1N.\nabla_{\Delta b}\mathcal{L}=\frac{2}{N}\left(Z\Delta W+1_N\Delta b^{\mathsf{T}}-\Delta O\right)^{\mathsf{T}}1_N.

Setting the gradient to zero yields

1NTZΔW+NΔbT−1NTΔO=0.1_N^{\mathsf{T}}Z\Delta W+N\Delta b^{\mathsf{T}}-1_N^{\mathsf{T}}\Delta O=0.

We define the row means as

μZ=1N1NTZ,μΔO=1N1NTΔO.\mu_Z=\frac{1}{N}1_N^{\mathsf{T}}Z,\qquad\mu_{\Delta O}=\frac{1}{N}1_N^{\mathsf{T}}\Delta O.

For any fixed ΔW\Delta W, the optimal bias is therefore

ΔbT=μΔO−μZΔW.\Delta b^{\mathsf{T}}=\mu_{\Delta O}-\mu_Z\Delta W.

We then center the two matrices as

Z‾=Z−1NμZ,ΔO‾=ΔO−1NμΔO.\overline{Z}=Z-1_N\mu_Z,\qquad\overline{\Delta O}=\Delta O-1_N\mu_{\Delta O}.

Substituting the expression for Δb\Delta b into the residual gives

ZΔW+1NΔbT−ΔO=ZΔW+1N(μΔO−μZΔW)−ΔO=(Z−1NμZ)ΔW−(ΔO−1NμΔO)=Z‾ΔW−ΔO‾.\begin{aligned} Z\Delta W+1_N\Delta b^{\mathsf{T}}-\Delta O &=Z\Delta W+1_N\left(\mu_{\Delta O}-\mu_Z\Delta W\right)-\Delta O\\ &=\left(Z-1_N\mu_Z\right)\Delta W-\left(\Delta O-1_N\mu_{\Delta O}\right)\\ &=\overline{Z}\Delta W-\overline{\Delta O}. \end{aligned}

The objective therefore reduces to

L(ΔW)=1N∥Z‾ΔW−ΔO‾∥F2+ρ∥ΔW∥F2.\mathcal{L}(\Delta W)=\frac{1}{N}\left\|\overline{Z}\Delta W-\overline{\Delta O}\right\|_F^2+\rho\left\|\Delta W\right\|_F^2.

Differentiating with respect to ΔW\Delta W gives

∇ΔWL=2NZ‾T(Z‾ΔW−ΔO‾)+2ρΔW.\nabla_{\Delta W}\mathcal{L}=\frac{2}{N}\overline{Z}^{\mathsf{T}}\left(\overline{Z}\Delta W-\overline{\Delta O}\right)+2\rho\Delta W.

Setting the gradient to zero and rearranging gives

(Z‾TZ‾+NρIdin)ΔW=Z‾TΔO‾.\left(\overline{Z}^{\mathsf{T}}\overline{Z}+N\rho I_{d_{\mathrm{in}}}\right)\Delta W=\overline{Z}^{\mathsf{T}}\overline{\Delta O}.

Since ρ>0\rho>0, the matrix on the left is positive definite and therefore invertible. The optimal weight patch is

ΔW⋆=(Z‾TZ‾+NρIdin)−1Z‾TΔO‾,\Delta W_\star=\left(\overline{Z}^{\mathsf{T}}\overline{Z}+N\rho I_{d_{\mathrm{in}}}\right)^{-1}\overline{Z}^{\mathsf{T}}\overline{\Delta O},

with the corresponding bias

Δb⋆T=μΔO−μZΔW⋆.\Delta b_\star^{\mathsf{T}}=\mu_{\Delta O}-\mu_Z\Delta W_\star.

Restoring the layer index, the calibrated patch parameters are

ΔW⋆(ℓ)=(Z‾(ℓ)TZ‾(ℓ)+NρIdin)−1Z‾(ℓ)TΔO‾(ℓ),\Delta W_\star^{(\ell)}=\left(\overline{Z}^{(\ell)\mathsf{T}}\overline{Z}^{(\ell)}+N\rho I_{d_{\mathrm{in}}}\right)^{-1}\overline{Z}^{(\ell)\mathsf{T}}\overline{\Delta O}^{(\ell)},

and

Δb⋆(ℓ)T=μΔO(ℓ)−μZ(ℓ)ΔW⋆(ℓ).\Delta b_\star^{(\ell)\mathsf{T}}=\mu_{\Delta O}^{(\ell)}-\mu_Z^{(\ell)}\Delta W_\star^{(\ell)}.

Functional View

Consider a single attention head and a target position tt in a query-answer pair, and omit the layer and head indices for clarity. Let Xt\mathcal{X}_t denote the source positions from the query-answer pair visible to tt, and let DtD_t denote the demonstration-token positions visible to tt in the contextual prompt. The non-contextual attention representation is

ztnon-ctx=∑s∈Xtexp⁡(atsnon-ctx)vsnon-ctx∑s∈Xtexp⁡(atsnon-ctx).z_t^{\mathrm{non\text{-}ctx}}= \frac{\sum_{s\in\mathcal{X}_t}\exp\left(a_{ts}^{\mathrm{non\text{-}ctx}}\right)v_s^{\mathrm{non\text{-}ctx}}} {\sum_{s\in\mathcal{X}_t}\exp\left(a_{ts}^{\mathrm{non\text{-}ctx}}\right)}.

When demonstrations are added, the attention weights and value representations of the original context may change. We define the contextual attention mass over Xt\mathcal{X}_t and the corresponding normalized representation as

Atctx=∑s∈Xtexp⁡(atsctx),zt,Xctx=1Atctx∑s∈Xtexp⁡(atsctx)vsctxA_t^{\mathrm{ctx}} = \sum_{s \in\mathcal{X}_t} \exp(a_{ts}^{\mathrm{ctx}}), \qquad z_{t,\mathcal{X}}^{\mathrm{ctx}} = \frac{1}{A_t^{\mathrm{ctx}}} \sum_{s \in\mathcal{X}_t} \exp(a_{ts}^{\mathrm{ctx}})v_s^{\mathrm{ctx}}

For the demonstration-token positions, we similarly define

Bt=∑m∈Dtexp⁡(atmctx),rD,t=1Bt∑m∈Dtexp⁡(atmctx)vmctxB_t = \sum_{m \in\mathcal{D}_t} \exp(a_{tm}^{\mathrm{ctx}}), \qquad r_{D,t} = \frac{1}{B_t} \sum_{m \in\mathcal{D}_t} \exp(a_{tm}^{\mathrm{ctx}})v_m^{\mathrm{ctx}}

The contextual attention representation can then be written as

ztctx=(1−λt)zt,Xctx+λtrD,t,λt=BtAtctx+Btz_t^{\mathrm{ctx}} = (1-\lambda_t)z_{t,\mathcal{X}}^{\mathrm{ctx}} + \lambda_t r_{D,t}, \qquad\lambda_t = \frac{B_t}{A_t^{\mathrm{ctx}} + B_t}

Subtracting the non-contextual output gives

ztctx−ztnon-ctx=λtrD,t⏟demonstration retrieval−λtztnon-ctx⏟attention redistribution+(1−λt)(zt,Xctx−ztnon-ctx)⏟context changez_t^{\mathrm{ctx}} - z_t^{\mathrm{non\text{-}ctx}} = \underbrace{\lambda_t r_{D,t}}_{\text{demonstration retrieval}} - \underbrace{\lambda_t z_t^{\mathrm{non\text{-}ctx}}}_{\text{attention redistribution}} + \underbrace{(1-\lambda_t)\left(z_{t,\mathcal{X}}^{\mathrm{ctx}} - z_t^{\mathrm{non\text{-}ctx}}\right)}_{\text{context change}}

This decomposition shows that the effect of demonstrations is not a single fixed shift. At each token position, the head-level changes are combined across attention heads to form ZctxZ_{\mathrm{ctx}} and Znon-ctxZ_{\mathrm{non\text{-}ctx}}. Over all token positions, these representations give the layer-wise demonstration effect

δO=(Zctx−Znon-ctx)WO.\delta O = (Z_{\mathrm{ctx}} - Z_{\mathrm{non\text{-}ctx}})W_O.

From this perspective, Attention-Patching can be viewed as compactly representing these demonstration-induced changes through an affine correction, which provides the basis for the adaptive steering view.

pseudocode

Algorithm 1 describes the calibration and patch strength selection procedure of Attention-Patching. We first collect contextual attention outputs from the model. Patches are then fitted sequentially using ridge regression. Each fitted patch remains active when fitting subsequent layers, so later layers receive activations that reflect the effects of previously fitted patches. Finally, we select the patch strength on a held-out validation set.

Experimental Setup

Reproducibility Details

All classification experiments are repeated using five random seeds, {42,43,44,45,46}\{42, 43, 44, 45, 46\}, and the results are averaged across the five runs. All experiments are conducted on NVIDIA RTX 6000 Ada Generation GPUs.

For each classification task, we use a fixed demonstration set containing five examples per class and construct a disjoint calibration set from the training split. Attention-Patching uses 25 calibration examples per class. We select the patch strength α\alpha by sweeping α∈{0.001,0.1,0.2,…,1.0}\alpha\in\{0.001, 0.1, 0.2, \ldots, 1.0\} over 100 held-out validation instances and choosing the value that achieves the best validation performance. For evaluation, we use up to 500 instances from the evaluation split of each classification benchmark, using all available instances for smaller datasets.

For multi-token generation, we use 32 calibration examples and follow the same procedure for selecting the patch strength α\alpha. For evaluation, we use 500 instances for each task, with demonstration-context budgets ranging from 1K to 16K tokens; for models with shorter context windows, we use budgets from 1K to 4K tokens.

Figure 6 reports the selected patch strengths across tasks and models.

Heatmaps of selected patch strengths for classification and multi-token generation tasks

Figure 6. Selected patch strength α\alpha for each task and model. The left panel corresponds to classification tasks, where values are averaged across five independent runs, and the right panel corresponds to multi-token generation tasks, where values are averaged across the evaluated context lengths and three independent runs for each model. In each experiment, α\alpha is selected on the held-out validation set following the procedure described above.

Algorithm 1 Attention-Patching

Input: Model fθf_\theta, demonstrations D\mathcal{D}, calibration set Q={(xi,yi)}i=1M\mathcal{Q}=\{(x_i,y_i)\}_{i=1}^{M}, validation set V\mathcal{V}

Parameter: Ridge coefficient ρ\rho, patch strength candidates A\mathcal{A}

Output: Patched model fθ~f_{\tilde{\theta}}

1: Initialize P←∅P \leftarrow\varnothing

2: // Collect contextual attention outputs

3: for each (xi,yi)∈Q(x_i,y_i) \in\mathcal{Q} do

4: Octx(1:L)(xi,yi)←AttnOut⁡(fθ([D;xi;yi]))O_{\mathrm{ctx}}^{(1:L)}(x_i,y_i) \leftarrow\operatorname{AttnOut}(f_\theta([\mathcal{D};x_i;y_i]))

5: end for

6: // Sequential fitting

7: for ℓ=1,…,L\ell=1,\ldots,L do

8: for each (xi,yi)∈Q(x_i,y_i) \in\mathcal{Q} do

9: (Znon−ctx(ℓ)(xi,yi),Onon−ctx(ℓ)(xi,yi))←AttnProj⁡ℓ(fθ+P([xi;yi]))(Z_{\mathrm{non-ctx}}^{(\ell)}(x_i,y_i),O_{\mathrm{non-ctx}}^{(\ell)}(x_i,y_i)) \leftarrow\operatorname{AttnProj}_{\ell}(f_{\theta+P}([x_i;y_i]))

10: δO(ℓ)(xi,yi)←Octx(ℓ)(xi,yi)−Onon−ctx(ℓ)(xi,yi)\delta O^{(\ell)}(x_i,y_i) \leftarrow O_{\mathrm{ctx}}^{(\ell)}(x_i,y_i)-O_{\mathrm{non-ctx}}^{(\ell)}(x_i,y_i)

11: end for

12: Z(ℓ)←RowConcat⁡iZnon−ctx(ℓ)(xi,yi)Z^{(\ell)} \leftarrow\operatorname{RowConcat}_i Z_{\mathrm{non-ctx}}^{(\ell)}(x_i,y_i)

13: ΔO(ℓ)←RowConcat⁡iδO(ℓ)(xi,yi)\Delta O^{(\ell)} \leftarrow\operatorname{RowConcat}_i \delta O^{(\ell)}(x_i,y_i)

14: // Fit the attention patch via ridge regression

15: (ΔW∗(ℓ),Δb∗(ℓ))←arg⁡min⁡ΔW,Δb1N∥Z(ℓ)ΔW+1NΔb⊤−ΔO(ℓ)∥F2+ρ∥ΔW∥F2(\Delta W_*^{(\ell)},\Delta b_*^{(\ell)}) \leftarrow\arg\min_{\Delta W,\Delta b}\frac{1}{N}\lVert Z^{(\ell)}\Delta W+\mathbf{1}_N\Delta b^\top-\Delta O^{(\ell)}\rVert_F^2+\rho\lVert\Delta W\rVert_F^2

16: P←P∪{(ℓ,ΔW∗(ℓ),Δb∗(ℓ))}P \leftarrow P \cup\{(\ell,\Delta W_*^{(\ell)},\Delta b_*^{(\ell)})\}

17: end for

18: // Patch strength selection

19: α∗←arg⁡max⁡α∈AScore⁡(fθ+αP,V)\alpha_* \leftarrow\arg\max_{\alpha\in\mathcal{A}}\operatorname{Score}(f_{\theta+\alpha P},\mathcal{V})

20: θ~←θ+α∗P\tilde{\theta} \leftarrow\theta+\alpha_*P

21: return fθ~f_{\tilde{\theta}}

Classification Prompt Templates

Table 4 summarizes the dataset-specific prompt templates used in our classification experiments. Each template specifies the input format and the corresponding set of candidate labels.

DatasetTask TypeTemplate
AGNewsTopic classificationNews: {text}; Type: [World, Sports, Business, Technology]
SST-2SentimentReview: {text}; Sentiment: [negative, positive]
TRECQuestion type classificationQuestion: {text}; Answer Type: [Abbreviation, Entity, Description, Person, Location, Number]
CSQACommonsenseQuestion: {question}; A. {optA}; B. {optB}; C. {optC}; D. {optD}; E. {optE}; Answer (A/B/C/D/E); Options: [A, B, C, D, E]
PIQAPhysical commonsenseGoal: {goal}; A. {optA}; B. {optB}; Answer (A/B); Options: [A, B]
SST-5SentimentSentence: {text}; Sentiment: [terrible, negative, neutral, positive, great]
MRMovie reviewReview: {text}; Sentiment: [negative, positive]
MRPCParaphrase{pair}; A. Paraphrase; B. Not paraphrase; Answer (A/B); Options: [A, B]
CBNLI{pair}; A. Entailment; B. Contradiction; C. Neutral; Answer (A/B/C); Options: [A, B, C]
CREAKClaim verificationClaim: {claim}; Label: yes / no; Options: [yes, no]
COPACausal reasoning{context}; A. {optA}; B. {optB}; Answer (A/B); Options: [A, B]
AI2SciEScience MCQQuestion: {question}; A. {optA}; B. {optB}; C. {optC}; D. {optD}; E. {optE}; F. {optF}; G. {optG}; H. {optH}; Answer (A/B/C/. . . ); Options: [A, B, C, D, E, F, G, H]

Table 4. Prompt templates used in the classification experiments.

LoRA Setup

For comparison with Attention-Patching, we apply LoRA to the attention output projection (o_proj), corresponding to the projection modified by our method. We use a rank of 8, a scaling factor of 16, and a dropout rate of 0.05. The model is trained for one epoch using AdamW with a learning rate of 2×10−42 \times10^{-4} and a batch size of 4. We use no weight decay or learning-rate warmup and set the maximum gradient norm to 1.0.

For classification, LoRA is trained on 5, 15 or 25 examples per class, corresponding to the data budgets reported in the experiments. For multi-token generation, we use 32 training examples, matching the calibration-set size used for Attention-Patching.

Additional Results

Classification Results on Additional Models

Table 5 presents additional classification results on Gemma-2-2b-it and Mistral-7B-Instruct-v0.3, complementing the main results reported in § 4.2.

MethodAvg.AGSST-2TRECCSQAPIQASST-5MRMRPCCBCOPACREAKAI2SciE
Gemma-2-2b-it
0-shot72.775.692.672.869.871.836.891.645.362.594.072.487.4
ICL80.183.3(±2.4)93.6(±1.2)83.3(±3.0)72.2(±0.9)75.5(±1.0)48.0(±1.8)92.2(±0.7)69.2(±4.1)76.1(±9.8)92.0(±1.4)87.0(±1.1)88.8(±0.6)
LoRA75.287.0(±2.3)91.6(±1.5)81.7(±5.5)68.0(±1.3)75.2(±0.6)44.6(±1.7)91.0(±1.8)45.2(±11.4)71.4(±4.6)94.4(±0.5)64.8(±2.2)87.9(±0.2)
SITE78.889.6(±1.2)93.0(±0.4)82.9(±2.5)69.0(±1.9)74.5(±1.5)36.0(±1.3)91.3(±0.7)68.4(±0.0)73.2(±5.6)94.6(±0.5)86.4(±2.3)87.0(±1.3)
TV73.785.4(±1.0)92.5(±0.1)76.4(±0.1)70.3(±0.3)71.8(±0.3)37.7(±1.2)90.0(±1.8)43.5(±3.3)57.1(±4.0)93.4(±0.9)79.3(±4.0)86.6(±1.2)
I2CL73.082.8(±1.0)86.8(±7.3)75.8(±8.6)66.2(±2.7)73.4(±1.8)36.4(±2.9)89.4(±0.5)64.0(±6.8)61.1(±3.4)93.0(±1.2)62.5(±8.3)85.1(±1.3)
FV70.675.2(±1.4)79.9(±1.3)78.7(±2.0)65.8(±0.3)69.8(±1.5)29.8(±1.0)75.5(±0.6)69.2(±0.4)72.1(±0.5)90.6(±0.8)55.6(±0.6)84.6(±0.7)
IV73.078.2(±0.8)90.4(±0.9)75.9(±0.9)66.5(±0.6)59.8(±1.0)45.5(±1.8)87.2(±1.2)65.7(±2.5)59.3(±1.1)85.8(±0.9)77.6(±2.2)84.6(±1.2)
ICV72.775.6(±0.0)92.1(±1.1)72.8(±0.0)69.6(±0.7)72.9(±1.1)38.5(±0.5)91.8(±0.4)47.3(±2.5)59.3(±0.8)94.8(±0.8)70.7(±1.2)86.7(±0.3)
LTV77.181.8(±3.0)93.1(±1.1)78.6(±5.2)69.0(±1.5)71.1(±1.2)43.2(±3.5)90.2(±1.3)62.7(±4.3)71.8(±6.8)91.8(±1.3)83.0(±1.1)89.0(±0.8)
TP66.551.8(±2.6)89.0(±0.9)47.5(±7.2)54.8(±1.5)69.6(±1.2)34.8(±1.3)87.7(±1.3)68.3(±0.4)55.7(±8.5)92.0(±1.4)81.0(±2.6)65.8(±5.4)
AP (Ours)80.386.6(±2.1)93.2(±0.3)88.9(±1.1)70.5(±0.2)74.9(±1.2)44.3(±4.7)91.5(±0.7)70.6(±0.9)74.3(±7.2)95.0(±0.7)85.9(±0.8)87.8(±0.6)
Mistral-7B-Instruct-v0.3
0-shot65.076.690.458.869.677.036.289.232.619.692.051.686.8
ICL82.883.5(±1.8)94.0(±1.0)80.9(±4.0)76.2(±0.7)80.0(±0.6)51.1(±1.5)93.1(±0.4)69.6(±5.2)88.2(±5.5)96.6(±1.1)90.7(±0.4)90.0(±0.4)
LoRA77.386.9(±2.9)90.4(±0.7)86.7(±3.4)69.8(±0.8)78.2(±1.1)46.2(±3.7)89.0(±2.8)51.5(±19.9)71.4(±15.3)92.8(±0.8)77.2(±2.5)87.3(±0.6)
SITE79.989.4(±2.2)93.8(±0.6)75.5(±4.9)70.1(±1.7)75.8(±3.4)42.2(±4.2)91.8(±0.6)68.4(±0.0)81.8(±3.9)93.4(±0.5)88.6(±1.2)87.8(±0.7)
TV67.781.6(±4.2)88.2(±3.4)71.4(±1.7)74.4(±1.2)77.4(±1.5)36.5(±0.9)92.1(±0.6)35.8(±2.9)30.4(±3.3)93.2(±1.1)57.0(±3.9)87.1(±0.8)
I2CL77.285.1(±1.6)90.4(±1.3)76.7(±1.2)64.8(±2.6)77.0(±1.6)44.6(±2.1)88.2(±1.8)63.3(±10.6)73.2(±3.3)93.6(±1.1)81.4(±2.5)87.6(±1.5)
FV81.485.7(±1.6)90.4(±1.3)76.7(±1.2)74.4(±2.6)77.0(±1.6)44.6(±2.1)88.2(±1.8)63.3(±10.6)73.2(±3.3)93.6(±1.1)81.4(±2.5)87.6(±1.5)
IV81.981.4(±1.6)92.1(±0.8)84.4(±1.8)73.4(±1.0)79.5(±1.2)40.3(±1.2)91.0(±0.7)73.9(±1.2)93.5(±1.1)95.2(±0.6)89.8(±0.5)88.6(±0.6)
ICV69.076.6(±0.0)90.1(±0.9)64.4(±0.8)71.0(±0.1)76.8(±0.0)36.0(±0.2)90.4(±0.7)32.6(±0.0)27.1(±0.8)92.6(±0.5)83.3(±1.5)86.9(±0.2)
LTV79.681.7(±1.4)92.0(±1.0)79.8(±3.3)69.2(±1.3)77.0(±1.5)50.0(±1.0)89.5(±1.2)68.5(±4.5)82.5(±2.0)93.2(±1.3)84.4(±2.9)88.0(±0.9)
TP77.269.5(±5.3)90.6(±0.8)68.9(±1.9)71.0(±0.9)78.8(±1.1)39.4(±1.6)91.1(±1.0)68.1(±1.5)78.2(±3.4)96.2(±0.8)89.0(±0.8)85.3(±0.4)
AP (Ours)82.785.8(±1.8)94.3(±0.5)79.8(±3.0)74.2(±1.0)79.6(±0.7)52.0(±2.2)93.7(±0.6)71.9(±2.7)87.5(±3.1)95.8(±2.3)90.4(±1.0)87.9(±0.6)

Table 5. Baseline comparison across classification benchmarks. All results are averaged over five independent runs. The best and second-best results in each column within each model are indicated in bold and underline, respectively.

Multi-token Generation Results on Additional Models

Table 6 presents additional multi-token generation results on Mistral-7B-Instruct-v0.3, Gemma-2-2b-it, and Qwen3.5-0.8B across mathematical reasoning, translation, summarization, and constrained text generation.

MethodAvg.GSM8KFLORES(Ko) ROUGE-L F1FLORES(Ko) COMETFLORES(Sp) ROUGE-L F1FLORES(Sp) COMETDailyMailCommonGen
Gemma-2-2b-it
Zero-shot51.755.2(±1.2)20.9(±0.7)81.5(±0.1)52.7(±0.4)85.5(±0.3)18.7(±0.2)47.3(±0.8)
LoRA51.957.2(±1.7)21.1(±0.6)80.9(±0.4)52.8(±0.3)85.8(±0.2)15.9(±0.3)49.4(±1.2)
Many-shot (1K)53.248.5(±3.1)22.6(±0.6)84.4(±0.4)53.4(±0.2)85.9(±0.3)23.4(±0.6)54.4(±1.3)
SITE50.845.9(±1.5)21.6(±0.8)83.3(±0.4)51.5(±0.2)85.4(±0.2)18.4(±1.0)49.8(±0.9)
ICV52.056.5(±0.9)21.3(±0.3)81.2(±0.6)52.8(±0.3)85.5(±0.3)18.9(±0.5)47.6(±0.7)
LTV42.726.8(±14.0)20.3(±0.5)79.6(±0.6)51.2(±0.6)84.6(±0.1)19.8(±0.7)16.3(±4.9)
AP54.457.6(±0.2)23.2(±1.0)83.4(±0.9)53.2(±0.1)85.7(±0.3)23.5(±0.8)54.5(±1.1)
Many-shot (2K)53.147.5(±2.0)22.2(±0.7)84.5(±0.4)53.4(±0.1)86.0(±0.2)24.0(±0.3)54.1(±1.4)
SITE50.946.7(±2.4)21.5(±0.5)83.4(±0.1)51.7(±0.5)85.4(±0.3)17.8(±0.5)49.6(±0.4)
ICV52.056.5(±1.0)21.2(±0.5)81.6(±0.1)52.8(±0.3)85.5(±0.3)18.9(±0.5)47.6(±0.7)
LTV42.123.5(±1.5)20.5(±0.6)79.7(±0.5)50.9(±0.7)84.5(±0.1)19.8(±1.1)15.5(±3.4)
AP54.257.4(±2.1)22.5(±1.3)83.5(±0.4)52.8(±0.5)85.6(±0.3)23.3(±0.2)54.2(±1.6)
Many-shot (4K)52.845.3(±1.7)22.7(±1.1)84.3(±0.3)53.4(±0.3)86.0(±0.2)24.6(±0.2)53.1(±1.5)
SITE50.745.9(±0.9)21.8(±1.2)83.2(±0.4)51.5(±0.3)85.4(±0.4)17.6(±0.3)49.7(±0.6)
ICV51.956.5(±1.3)21.0(±0.4)81.2(±0.5)52.8(±0.3)85.5(±0.3)19.0(±0.4)47.6(±0.7)
LTV42.023.8(±5.9)20.6(±0.9)80.0(±1.2)51.1(±0.6)84.7(±0.1)18.3(±1.4)15.8(±3.9)
AP53.756.0(±0.7)22.1(±1.3)83.0(±0.3)53.0(±0.2)85.7(±0.3)23.5(±0.1)52.6(±0.7)
Mistral-7B-Instruct-v0.3
Zero-shot45.725.6(±0.6)18.1(±0.8)75.2(±0.7)51.0(±0.5)84.0(±0.1)20.4(±0.2)45.3(±0.7)
LoRA49.835.4(±2.8)21.4(±0.9)80.1(±0.5)51.0(±0.2)85.0(±0.1)25.6(±0.9)50.0(±1.1)
Many-shot (1K)54.554.1(±0.6)22.8(±0.6)81.5(±0.6)53.0(±0.3)85.7(±0.2)25.8(±1.2)58.4(±0.7)
SITE50.441.7(±4.0)20.5(±0.4)78.2(±0.2)52.1(±0.3)84.8(±0.4)20.9(±0.4)54.8(±0.9)
ICV46.025.8(±0.5)19.1(±0.4)75.5(±0.8)51.0(±0.5)84.0(±0.1)21.0(±0.3)45.4(±0.9)
LTV37.921.0(±2.3)10.7(±3.1)54.4(±1.7)50.0(±2.2)82.6(±1.0)17.5(±4.7)29.9(±4.6)
AP54.053.5(±2.6)23.1(±0.8)80.4(±0.1)53.0(±0.1)85.4(±0.2)24.8(±0.8)57.8(±0.8)
Many-shot (2K)54.852.8(±0.7)23.0(±1.6)81.8(±0.3)53.0(±0.1)85.9(±0.2)28.2(±0.8)59.1(±1.2)
SITE50.240.1(±5.9)21.0(±0.5)78.4(±0.4)52.1(±0.3)84.8(±0.3)20.6(±0.4)54.8(±0.6)
ICV46.026.1(±0.5)19.1(±0.2)75.8(±0.5)50.9(±0.5)84.0(±0.2)21.0(±0.3)43.5(±0.8)
LTV38.121.3(±2.4)10.3(±2.9)54.1(±1.7)49.8(±0.7)82.7(±0.7)18.9(±2.8)29.8(±1.4)
AP54.051.9(±0.6)22.5(±1.2)81.0(±0.4)53.0(±0.1)85.6(±0.2)26.7(±0.9)57.4(±0.6)
Many-shot (4K)54.750.9(±1.0)23.4(±1.1)81.5(±0.5)52.9(±0.1)85.9(±0.1)28.5(±0.5)59.8(±1.6)
SITE50.239.9(±6.2)21.1(±0.9)78.3(±0.2)51.9(±0.2)84.8(±0.3)20.5(±0.3)54.6(±0.6)
ICV46.227.1(±0.3)19.1(±0.5)75.7(±0.5)51.0(±0.5)84.0(±0.2)21.0(±0.4)45.2(±0.7)
LTV39.022.3(±2.8)10.9(±2.5)57.2(±2.5)49.5(±0.6)82.5(±0.7)20.5(±0.6)30.1(±3.5)
AP54.352.9(±1.9)22.7(±0.5)80.5(±1.2)52.7(±0.3)85.6(±0.1)26.7(±0.6)58.7(±0.6)
Many-shot (8K)54.952.3(±1.1)23.7(±0.9)81.9(±0.8)53.0(±0.3)86.0(±0.1)28.2(±0.4)58.9(±1.0)
SITE50.440.8(±2.1)21.3(±0.2)78.4(±0.3)52.0(±0.2)84.9(±0.3)20.6(±0.3)54.9(±1.0)
ICV46.126.3(±0.2)19.2(±0.4)75.6(±0.8)51.1(±0.5)84.0(±0.1)21.0(±0.5)45.4(±0.8)
LTV39.221.5(±3.4)11.6(±2.5)58.4(±1.2)49.6(±0.7)82.7(±0.9)20.9(±1.0)29.6(±0.7)
AP54.051.7(±1.2)22.9(±1.9)80.4(±0.7)52.7(±0.1)85.6(±0.1)26.7(±1.0)57.8(±0.6)
Many-shot (16K)54.649.2(±0.9)24.1(±0.6)81.9(±0.3)52.9(±0.1)86.0(±0.1)28.5(±0.5)59.9(±1.3)
SITE50.743.1(±5.9)21.1(±0.3)78.5(±0.1)52.1(±0.2)85.0(±0.3)20.4(±0.3)54.5(±0.4)
ICV46.126.5(±0.5)19.2(±0.5)75.6(±0.9)51.1(±0.4)84.1(±0.1)20.9(±0.3)45.4(±0.7)
LTV39.021.3(±1.5)12.2(±3.7)58.9(±2.2)49.3(±0.3)82.4(±0.5)20.6(±0.4)28.5(±2.6)
AP53.748.8(±4.5)23.5(±0.8)80.6(±0.5)52.5(±0.4)85.6(±0.2)26.8(±0.6)58.1(±0.6)
Qwen3.5-0.8B
Zero-shot35.89.7(±0.6)13.3(±1.4)62.4(±0.5)42.4(±0.2)77.6(±0.4)16.7(±0.7)28.9(±0.1)
LoRA36.89.1(±0.8)14.1(±1.7)64.8(±0.6)43.8(±0.2)78.5(±0.3)16.5(±3.5)29.3(±0.5)
Many-shot (1K)45.133.3(±2.5)17.3(±0.8)73.1(±0.9)47.4(±0.5)80.5(±0.7)13.8(±1.3)50.1(±0.9)
SITE40.619.4(±2.3)15.3(±1.5)67.3(±0.5)45.6(±0.3)79.0(±0.4)17.6(±0.4)39.9(±0.4)
ICV37.719.2(±7.1)13.9(±1.3)63.0(±0.5)43.6(±0.3)78.0(±0.6)17.4(±0.2)28.5(±0.3)
LTV30.74.8(±0.5)10.3(±2.2)54.0(±2.4)41.8(±0.7)75.0(±1.2)15.8(±0.8)13.3(±4.0)
AP44.329.3(±2.3)17.5(±1.5)71.5(±1.9)46.6(±0.6)79.8(±0.4)18.5(±0.2)47.2(±1.6)
Many-shot (2K)45.035.3(±1.8)19.0(±0.7)74.4(±0.9)47.7(±0.1)80.9(±0.3)16.1(±1.3)49.2(±1.2)
SITE40.518.4(±2.2)15.2(±0.9)67.8(±1.0)45.8(±0.5)79.1(±0.5)17.8(±0.6)39.5(±0.4)
ICV37.416.8(±1.4)14.1(±1.5)63.4(±0.3)43.6(±0.4)77.9(±0.4)17.3(±0.4)28.5(±0.4)
LTV29.76.4(±1.2)9.0(±0.7)51.8(±0.8)41.5(±0.6)74.8(±1.1)15.0(±0.8)9.4(±1.3)
AP44.632.7(±1.3)17.3(±1.7)71.9(±1.3)47.0(±0.9)80.0(±0.6)18.4(±0.6)44.9(±0.2)
Many-shot (4K)46.533.4(±1.8)18.3(±1.3)75.5(±0.5)48.0(±0.3)81.4(±0.2)18.2(±1.7)50.5(±1.3)
SITE40.418.9(±1.4)15.0(±1.4)67.6(±0.9)45.6(±0.5)79.0(±0.4)17.7(±0.8)39.0(±0.7)
ICV37.216.3(±1.5)14.0(±1.5)63.5(±0.2)43.4(±0.2)77.8(±0.4)17.3(±0.5)28.5(±0.3)
LTV29.04.1(±1.6)8.8(±1.6)49.5(±1.1)42.0(±1.0)75.3(±1.2)15.0(±0.4)8.6(±0.3)
AP44.528.2(±0.9)18.5(±1.1)73.3(±1.3)46.8(±0.8)79.9(±0.8)18.9(±0.1)45.9(±0.8)
Many-shot (8K)46.534.7(±0.4)19.1(±1.1)76.1(±0.3)47.9(±0.8)81.5(±0.8)17.8(±2.8)48.8(±0.8)
SITE40.619.3(±3.4)15.0(±1.1)68.0(±0.3)45.9(±0.2)79.3(±0.3)17.7(±0.5)39.1(±0.7)
ICV37.316.9(±2.1)14.1(±1.4)63.5(±0.7)43.3(±0.3)77.9(±0.5)17.4(±0.3)28.3(±0.2)
LTV27.94.2(±0.5)7.8(±2.5)48.0(±5.1)40.7(±2.1)74.3(±2.3)14.2(±0.6)7.5(±0.4)
AP44.328.3(±2.0)17.4(±1.2)72.8(±0.7)47.0(±0.8)80.2(±0.4)19.4(±0.5)45.3(±1.4)
Many-shot (16K)46.231.5(±0.9)19.4(±1.1)76.0(±0.6)48.0(±0.2)81.5(±0.1)18.9(±1.8)48.1(±0.6)
SITE40.118.3(±2.8)15.0(±1.1)68.3(±0.6)44.8(±1.2)78.3(±1.1)17.5(±0.2)38.4(±0.8)
ICV37.316.6(±3.0)14.0(±1.2)63.4(±0.5)43.5(±0.4)77.9(±0.5)17.3(±0.4)28.7(±0.8)
LTV27.24.2(±0.3)7.2(±2.3)43.4(±0.2)40.9(±1.1)74.5(±1.2)12.9(±0.5)7.2(±0.2)
AP43.420.1(±3.4)19.5(±0.6)74.5(±0.2)46.8(±0.5)80.3(±0.2)18.9(±0.7)43.7(±2.4)

Table 6. Multi-token generation results under different context lengths, averaged over three independent runs. We report flexible-match accuracy on GSM8K, ROUGE-L F1 and COMET scores on FLORES, and ROUGE-L F1 scores on DailyMail and CommonGen. The best and second-best results in each column within each model and context length are indicated in bold and underline, respectively.

On the additional models, Attention-Patching generally outperforms the evaluated implicit ICL baselines across generation tasks and demonstration-context budgets. Averaged across the five context budgets on Mistral-7B-Instruct-v0.3, Attention-Patching achieves 51.8 accuracy on GSM8K, compared with 41.1 for SITE and 51.9 for explicit many-shot ICL. On Gemma-2-2B-it, Attention-Patching exceeds many-shot ICL on GSM8K while maintaining comparable performance on FLORES. On Qwen3.5-0.8B, Attention-Patching generally outperforms these baselines and achieves competitive performance relative to explicit many-shot ICL on some tasks. These results suggest that the learned patches remain effective across different models.

Amortized Inference Efficiency

To further evaluate the trade-off between calibration costs and inference efficiency, we conduct a break-even analysis comparing AP with PrefixKV Caching on GSM8K using Llama-3.2-3B-Instruct with a fixed generation length of 512 tokens. We measure wall-clock time across 500 queries under context budgets ranging from 1K to 16K tokens. The break-even point is defined as the number of queries after which AP achieves lower cumulative wall-clock time than explicit ICL.

As shown in Figure 7, when activation collection is excluded, the ridge regression step alone incurs negligible cost, making AP advantageous from the first query across all evaluated context budgets. When the full calibration cost, including activation collection and ridge regression, is considered, AP reaches the break-even point after approximately 25 queries at 8K and 9 queries at 16K. For shorter contexts (1K–4K), more queries are required to amortize the offline cost due to smaller per-query inference-time savings.

Break-even analysis plots comparing AP and PrefixKV Caching

Figure 7. Break-even analysis of AP vs. PrefixKV Caching. Left: Wall-clock time for 500 queries across different context budgets. Right: Break-even points with and without activation collection costs.

Additional Ablation Studies

Effect of Calibration Set Size

To examine the sensitivity of Attention-Patching to calibration set size, we compare its performance with LoRA and Thought Patching under different data budgets. We consider 5, 15 and 25 examples per class.

As shown in Figure 8 and Figure 9, Attention-Patching exhibits a clear advantage over LoRA and Thought Patching (TP) in the low-data regime. With only 5 examples per class, Attention-Patching achieves higher average accuracy than both baselines across all five evaluated models, while remaining competitive with the implicit ICL baselines reported in Table 1 and Table 5. This advantage over LoRA and TP is maintained as the calibration set size increases to 15 and 25 examples per class. These results suggest that Attention-Patching effectively captures task-specific behaviors induced by demonstrations using a small calibration set, without requiring backpropagation through the language model.

Calibration set size effects across three language models

Figure 8. Effect of calibration set size on Llama-3.2-3B-Instruct, Gemma-2-27b-it, and Qwen3.5-0.8B. We report average accuracy across 12 classification benchmarks for LoRA, Thought Patching (TP), and Attention-Patching with 5, 15, and 25 examples per class.

Calibration set size effects across two language models

Figure 9. Effect of calibration set size on Gemma-2-2b-it and Mistral-7B-Instruct-v0.3. We report average accuracy across 12 classification benchmarks for LoRA, Thought Patching (TP), and Attention-Patching with 5, 15, and 25 examples per class.

Effect of Layer Selection

To examine the contribution of different layer groups, we apply the learned patches to one quarter of the decoder layers at a time and compare their performance with patching all layers. We use the task-specific patch strength selected in the main experiments.

Table 7 evaluates the contribution of different layer groups by applying the learned patches to one quarter of the decoder layers at a time. Patching all layers achieves the highest accuracy of 80.7, outperforming every individual layer group. Based on this result, we apply the learned patches to all decoder layers by default.

Sensitivity to Ridge Regularization

Table 8 examines the sensitivity of Attention-Patching to the ridge coefficient ρ\rho on classification benchmarks. We vary ρ\rho from 1e−31\mathrm{e}{-3} to 1e−11\mathrm{e}{-1}. Based on these results, we adopt ρ=1e−3\rho= 1\mathrm{e}{-3} as the default setting.

Additional Representation Analysis

Layer-wise Structure on Additional Models

We provide additional representation analyses complementing the results presented in § 5.4.

Figure 10 extends the layer-wise analysis of learned attention patches to additional model architectures, examining their magnitude and effective dimensionality through the normalized Frobenius norm and stable rank, respectively.

Layer-wise structure of the learned attention patches across classification benchmarks

Figure 10. Layer-wise structure of the learned attention patches across classification benchmarks. The top row shows the normalized Frobenius norm of the patch weights, while the bottom row shows their stable rank. Each column corresponds to a model architecture, and each curve represents one classification task.

NMSE Comparison

Figure 11 and Figure 12 report the layer-wise normalized mean squared error (NMSE) between the layer-output hidden states produced by each method and those produced by explicit many-shot ICL. The results are evaluated on 500 randomly sampled GSM8K examples and averaged across the evaluated demonstration-context budgets for each model. Across layers, Attention-Patching produces hidden states that are closer to those of explicit ICL than either zero-shot inference or ICV. The reduced representational distance to explicit ICL suggests that the learned patches recover aspects of its internal activation patterns, providing further evidence that Attention-Patching captures contextual adaptation beyond the final output predictions.

Layer-wise NMSE plots for Llama-3.2-3B-Instruct, Gemma-2-27b-it, and Qwen3.5-0.8B

Figure 11. Layer-wise NMSE of hidden states relative to many-shot ICL, averaged over 500 GSM8K samples and context lengths. Lower values indicate greater representational similarity.

Layer-wise NMSE plots for Gemma-2-2b-it and Mistral-7B-Instruct-v0.3

Figure 12. Layer-wise NMSE of hidden states relative to many-shot ICL, averaged over 500 GSM8K samples and context lengths. Lower values indicate greater representational similarity.

Table 7. Layer-group ablation of Attention-Patching on Llama-3.2-3B-Instruct across 12 classification benchmarks. We divide the decoder layers into four contiguous groups of equal size, where Q1 and Q4 denote the earliest and latest layer groups, respectively. “All” applies patches to every decoder layer.

GroupAGSST-2TRECCSQAPIQASST-5MRMRPCCBCOPACREAKAI2SciEAvg.
None58.890.862.076.675.633.889.066.967.994.079.287.073.5
Q166.891.967.276.175.831.389.666.561.892.869.886.973.0
Q272.490.574.776.575.336.989.067.365.494.083.786.376.0
Q363.389.861.576.575.634.589.267.662.593.678.687.373.3
Q456.790.657.276.375.634.789.467.964.694.075.986.872.5
All85.893.083.976.275.846.791.168.779.693.286.087.780.7

Table 8. Effect of the ridge coefficient ρ\rho on Llama-3.2-3B-Instruct. We report average accuracy across 12 classification benchmarks.

ρ\rhoAGSST-2TRECCSQAPIQASST-5MRMRPCCBCOPACREAKAI2SciEAvg.
1e-385.893.083.976.275.846.791.168.779.693.286.087.780.7
1e-279.092.883.276.375.943.491.366.679.394.885.088.079.6
1e-159.392.284.376.175.338.390.866.970.795.685.987.176.9

References

  1. [1]Yonatan Bisk, Rowan Zellers, Ronan Le Bras, Jianfeng Gao, and Yejin Choi. Piqa: Reasoning about physical commonsense in natural language. In Thirty-Fourth AAAI Conference on Artificial Intelligence, 2020.arxiv.org/abs/1911.11641
  2. [2]Tom Brown, Benjamin Mann, Nick Ryder, Melanie Subbiah, Jared D Kaplan, Prafulla Dhariwal, Arvind Neelakantan, Pranav Shyam, Girish Sastry, Amanda Askell, et al. Language models are few-shot learners. Advances in neural information processing systems, 33:1877–1901, 2020.arxiv.org/abs/2005.14165
  3. [3]Wang Cai, Hsiu-Yuan Huang, Zhixiang Wang, and Yunfang Wu. Beyond demonstrations: Dynamic vector construction from latent representations. In Christos Christodoulopoulos, Tanmoy Chakraborty, Carolyn Rose, and Violet Peng (eds.), Proceedings of the 2025 Conference on Empirical Methods in Natural Language Processing, pp. 5842–5857, Suzhou, China, November 2025. Association for Computational Linguistics. ISBN 979-8-89176-332-6. doi: 10.18653/v1/2025.emnlp-main.297. URL https://aclanthology.org/2025.emnlp-main.297/.DOI
  4. [4]Xingwu Chen, Lei Zhao, and Difan Zou. How transformers utilize multi-head attention in in-context learning? a case study on sparse linear regression. In The Thirty-eighth Annual Conference on Neural Information Processing Systems, 2024. URL https://openreview.net/forum?id=fG8TukiXa5.arxiv.org/abs/2408.04532
  5. [5]Peter Clark, Isaac Cowhey, Oren Etzioni, Tushar Khot, Ashish Sabharwal, Carissa Schoenick, and Oyvind Tafjord. Think you have solved question answering? try arc, the ai2 reasoning challenge. arXiv:1803.05457v1, 2018.arxiv.org/abs/1803.05457
  6. [7]Marie-Catherine de Marneffe, Christopher D. Manning, Joakim Nivre, and Daniel Zeman. Universal Dependencies. Computational Linguistics, 47(2):255–308, June 2021. doi: 10.1162/coli_a_00402. URL https://aclanthology.org/2021.cl-2.11/.
  7. [8]Benoit Dherin, Michael Munn, Hanna Mazzawi, Michael Wunder, and Javier Gonzalvo. Learning without training: The implicit dynamics of in-context learning. arXiv preprint arXiv:2507.16003, 2025.arxiv.org/abs/2507.16003
  8. [9]William B. Dolan and Chris Brockett. Automatically constructing a corpus of sentential paraphrases. In Proceedings of the Third International Workshop on Paraphrasing (IWP2005), 2005. URL https://aclanthology.org/I05-5002/.
  9. [10]Naman Goyal, Cynthia Gao, Vishrav Chaudhary, Peng-Jen Chen, Guillaume Wenzek, Da Ju, Sanjana Krishnan, Marc’Aurelio Ranzato, Francisco Guzmán, and Angela Fan. The flores-101 evaluation benchmark for low-resource and multilingual machine translation. Transactions of the Association for Computational Linguistics, 10:522–538, 2022.arxiv.org/abs/2106.03193
  10. [11]Aaron Grattafiori, Abhimanyu Dubey, Abhinav Jauhri, Abhinav Pandey, Abhishek Kadian, Ahmad Al-Dahle, Aiesha Letman, Akhil Mathur, Alan Schelten, Alex Vaughan, et al. The llama 3 herd of models. arXiv preprint arXiv:2407.21783, 2024.arxiv.org/abs/2407.21783
  11. [12]Yaru Hao, Yutao Sun, Li Dong, Zhixiong Han, Yuxian Gu, and Furu Wei. Structured prompting: Scaling in-context learning to 1,000 examples. arXiv preprint arXiv:2212.06713, 2022.arxiv.org/abs/2212.06713
  12. [13]Roee Hendel, Mor Geva, and Amir Globerson. In-context learning creates task vectors. In Houda Bouamor, Juan Pino, and Kalika Bali (eds.), Findings of the Association for Computational Linguistics: EMNLP 2023, pp. 9318–9333, Singapore, December 2023. Association for Computational Linguistics. doi: 10.18653/v1/2023.findings-emnlp.624. URL https://aclanthology.org/2023.findings-emnlp.624/.DOI
  13. [14]Edward J Hu, yelong shen, Phillip Wallis, Zeyuan Allen-Zhu, Yuanzhi Li, Shean Wang, Lu Wang, and Weizhu Chen. LoRA: Low-rank adaptation of large language models. In International Conference on Learning Representations, 2022. URL https://openreview.net/forum?id=nZeVKeeFYf9.arxiv.org/abs/2106.09685
  14. [15]Albert Q. Jiang, Alexandre Sablayrolles, Arthur Mensch, Chris Bamford, Devendra Singh Chaplot, Diego de las Casas, Florian Bressand, Gianna Lengyel, Guillaume Lample, Lucile Saulnier, Lélio Renard Lavaud, Marie-Anne Lachaux, Pierre Stock, Teven Le Scao, Thibaut Lavril, Thomas Wang, Timothée Lacroix, and William El Sayed. Mistral 7b, 2023. URL https://arxiv.org/abs/2310.06825.
  15. [16]Patrick Kahardipraja, Reduan Achtibat, Thomas Wiegand, Wojciech Samek, and Sebastian Lapuschkin. The atlas of in-context learning: How attention heads shape in-context retrieval augmentation. In The Thirty-ninth Annual Conference on Neural Information Processing Systems, 2025. URL https://openreview.net/forum?id=5h9mS87Pyt.arxiv.org/abs/2505.15807
  16. [17]Jihoon Kwon, Jiwon Choi, and Jy-vong Sohn. Distributional alignment as a criterion for designing task vectors in in-context learning. arXiv preprint arXiv:2605.20730, 2026.arxiv.org/abs/2605.20730
  17. [18]Jiaqian Li, Yanshu Li, Ligong Han, Ruxiang Tang, and W enchya Wang. Train once, reuse everywhere: Generalizable implicit ICL by routing attention. In Forty-third International Conference on Machine Learning, 2026. URL https://openreview.net/forum?id=Gb2mqvRRa0.arxiv.org/abs/2509.22854
  18. [19]Tianle Li, Ge Zhang, Quy Duc Do, Xiang Yue, and Wenhu Chen. Long-context LLMs struggle with long in-context learning. Transactions on Machine Learning Research, 2025a. ISSN 2835-8856. URL https://openreview.net/forum?id=Cw2x1g0e46.arxiv.org/abs/2404.02060
  19. [20]Xin Li and Dan Roth. Learning question classifiers. In COLING 2002: The 19th International Conference on Computational Linguistics, 2002. URL https://aclanthology.org/C02-1150/.
  20. [21]Zhuowei Li, Zihao Xu, Ligong Han, Yunhe Gao, Song Wen, Di Liu, Hao Wang, and Dimitris Metaxas. Implicit in-context learning. In International Conference on Learning Representations, volume 2025, pp. 101644–101666, 2025b.arxiv.org/abs/2405.14660
  21. [22]Bill Yuchen Lin, Wangchunshu Zhou, Ming Shen, Pei Zhou, Chandra Bhagavatula, Yejin Choi, and Xiang Ren. CommonGen: A constrained text generation challenge for generative commonsense reasoning. In Trevor Cohn, Yulan He, and Yang Liu (eds.), Findings of the Association for Computational Linguistics: EMNLP 2020, pp. 1823–1840, Online, November 2020. Association for Computational Linguistics. doi: 10.18653/v1/2020.findings-emnlp.165. URL https://aclanthology.org/2020.findings-emnlp.165/.DOI
  22. [23]Chin-Yew Lin. ROUGE: A package for automatic evaluation of summaries. In Text Summarization Branches Out, pp. 74–81, Barcelona, Spain, July 2004. Association for Computational Linguistics. URL https://aclanthology.org/W04-1013/.
  23. [24]Sheng Liu, Haotian Ye, Lei Xing, and James Y. Zou. In-context vectors: Making in context learning more effective and controllable through latent space steering. In Forty-first International Conference on Machine Learning, 2024. URL https://openreview.net/forum?id=dJTChKgv3a.arxiv.org/abs/2311.06668
  24. [25]Yiting Liu and Zhi-Hong Deng. Iterative vectors: In-context gradient steering without back-propagation. In Forty-second International Conference on Machine Learning, 2025. URL https://openreview.net/forum?id=1v3XERcMyP.
  25. [26]Hanna Mazzawi, Benoit Dherin, Michael Munn, Adrian Goldwaser, Michael Wunder, and Javier Gonzalvo. Transmuting prompts into weights, 2026. URL https://arxiv.org/abs/2510.08734.
  26. [27]Sewon Min, Xinxi Lyu, Ari Holtzman, Mikel Artetxe, Mike Lewis, Hannaneh Hajishirzi, and Luke Zettlemoyer. Rethinking the role of demonstrations: What makes in-context learning work? In Yoav Goldberg, Zornitsa Kozareva, and Yue Zhang (eds.), Proceedings of the 2022 Conference on Empirical Methods in Natural Language Processing, pp. 11048–11064, Abu Dhabi, United Arab Emirates, December 2022. Association for Computational Linguistics. doi: 10.18653/v1/2022.emnlp-main.759. URL https://aclanthology.org/2022.emnlp-main.759/.DOI
  27. [28]Catherine Olsson, Nelson Elhage, Neel Nanda, Nicholas Joseph, Nova DasSarma, Tom Henighan, Ben Mann, Amanda Askell, Yuntao Bai, Anna Chen, et al. In-context learning and induction heads. arXiv preprint arXiv:2209.11895, 2022.arxiv.org/abs/2209.11895
  28. [29]Yasumasa Onoe, Michael JQ Zhang, Eunsol Choi, and Greg Durrett. CREAK: A dataset for commonsense reasoning over entity knowledge. In Thirty-fifth Conference on Neural Information Processing Systems Datasets and Benchmarks Track (Round 2), 2021. URL https://openreview.net/forum?id=mbW_GT3ZN-.arxiv.org/abs/2109.01653
  29. [30]Bo Pang and Lillian Lee. Seeing stars: Exploiting class relationships for sentiment categorization with respect to rating scales. In Kevin Knight, Hwee Tou Ng, and Kemal Oflazer (eds.), Proceedings of the 43rd Annual Meeting of the Association for Computational Linguistics (ACL’05), pp. 115–124, Ann Arbor, Michigan, June 2005. Association for Computational Linguistics. doi: 10.3115/1219840.1219855. URL https://aclanthology.org/P05-1015/.DOI
  30. [31]Jungwon Park, Jimyeong Kim, Changin Choi, and Wonjong Rhee. Soft head selection for injecting ICL-derived task embeddings. In Maria Liakata, Viviane P. Moreira, Jiajun Zhang, and David Jurgens (eds.), Findings of the Association for Computational Linguistics: ACL 2026, pp. 27161–27214, San Diego, California, United States, July 2026. Association for Computational Linguistics. ISBN 979-8-89176-395-1. doi: 10.18653/v1/2026.findings-acl.1355. URL https://aclanthology.org/2026.findings-acl.1355/.DOI
  31. [32]Qwen Team. Qwen3.5: Towards native multimodal agents, February 2026. URL https://qwen.ai/blog?id=qwen3.5.
  32. [33]Ricardo Rei, Craig Stewart, Ana C Farinha, and Alon Lavie. COMET: A neural framework for MT evaluation. In Bonnie Webber, Trevor Cohn, Yulan He, and Yang Liu (eds.), Proceedings of the 2020 Conference on Empirical Methods in Natural Language Processing (EMNLP), pp. 2685–2702, Online, November 2020. Association for Computational Linguistics. doi: 10.18653/v1/2020.emnlp-main.213. URL https://aclanthology.org/2020.emnlp-main.213/.DOI
  33. [34]Nina Rimsky, Nick Gabrieli, Julian Schulz, Meg Tong, Evan Hubinger, and Alexander Turner. Steering llama 2 via contrastive activation addition. In Lun-Wei Ku, Andre Martins, and Vivek Srikumar (eds.), Proceedings of the 62nd Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers), pp. 15504–15522, Bangkok, Thailand, August 2024. Association for Computational Linguistics. doi: 10.18653/v1/2024.acl-long.828. URL https://aclanthology.org/2024.acl-long.828/.DOI
  34. [35]Melissa Roemmele, Cosmin Adrian Bejan, and Andrew S. Gordon. Choice of Plausible Alternatives: An Evaluation of Commonsense Causal Reasoning. In AAAI Spring Symposium on Logical Formalizations of Commonsense Reasoning, Stanford University, March 2011. URL http://ict.usc.edu/pubs/Choice%20of%20Plausible%20Alternatives-%20An%20Evaluation%20of%20Commonsense%20Causal%20Reasoning.pdf.
  35. [36]Baturay Saglam, Xinyang Hu, Zhuoran Yang, Dionysis Kalogerias, and Amin Karbasi. Learning task representations from in-context learning. In Wanxiang Che, Joyce Nabende, Ekaterina Shutova, and Mohammad Taher Pilehvar (eds.), Findings of the Association for Computational Linguistics: ACL 2025, pp. 6634–6663, Vienna, Austria, July 2025. Association for Computational Linguistics. ISBN 979-8-89176-256-5. doi: 10.18653/v1/2025.findings-acl.345. URL https://aclanthology.org/2025.findings-acl.345/.DOI
  36. [37]Stephanie Schoch and Yangfeng Ji. The good, the bad, and the debatable: A survey on the impacts of data for in-context learning. In Christos Christodoulopoulos, Tanmoy Chakraborty, Carolyn Rose, and Violet Peng (eds.), Proceedings of the 2025 Conference on Empirical Methods in Natural Language Processing, pp. 29798–29812, Suzhou, China, November 2025. Association for Computational Linguistics. ISBN 979-8-89176-332-6. doi: 10.18653/v1/2025.emnlp-main.1514. URL https://aclanthology.org/2025.emnlp-main.1514/.DOI
  37. [39]Richard Socher, Alex Perelygin, Jean Wu, Jason Chuang, Christopher D. Manning, Andrew Ng, and Christopher Potts. Recursive deep models for semantic compositionality over a sentiment treebank. In Proceedings of the 2013 Conference on Empirical Methods in Natural Language Processing, pp. 1631–1642, Seattle, Washington, USA, October 2013. Association for Computational Linguistics. URL https://www.aclweb.org/anthology/D13-1170.DOI
  38. [40]Gemma Team, Morgane Riviere, Shreya Pathak, Pier Giuseppe Sessa, Cassidy Hardin, Surya Bhupatiraju, Léonard Hussenot, Thomas Mesnard, Bobak Shahriari, Alexandre Ramé, Johan Ferret, Peter Liu, Pouya Tafti, Abe Friesen, Michelle Casbon, Sabela Ramos, Ravin Kumar, Charline Le Lan, Sammy Jerome, Anton Tsitsulin, Nino Vieillard, Piotr Stanczyk, Sertan Girgin, Nikola Momchev, Matt Hoffman, Shantanu Thakoor, Jean-Bastien Grill, Behnam Neyshabur, Olivier Bachem, Alanna Walton, Aliksei Severyn, Alicia Parrish, Aliya Ahmad, Allen Hutchinson, Alvin Abdagic, Amanda Carl, Amy Shen, Andy Brock, Andy Coenen, Anthony Laforge, Antonia Paterson, Ben Bastian, Bilal Piot, Bo Wu, Brandon Royal, Charlie Chen, Chintu Kumar, Chris Perry, Chris Welty, Christopher A. Choquette-Choo, Danila Sinopalnikov, David Weinberger, Dimple Vijaykumar, Dominika Rogozińska, Dustin Herbison, Elisa Bandy, Emma Wang, Eric Noland, Erica Moreira, Evan Senter, Evgenii Eltys hev, Francesco Visin, Gabriel Rasskin, Gary Wei, Glenn Cameron, Gus Martins, Hadi Hashemi, Hanna Klimczak-Plucińska, Harleen Batra, Harsh Dhand, Ivan Nardini, Jacinda Mein, Jack Zhou, James Svensson, Jeff Stanway, Jetha Chan, Jin Peng Zhou, Joana Carrasqueira, Joana Iliazi, Jocelyn Becker, Joe Fernandez, Joost van Amersfoort, Josh Gordon, Josh Lipschultz, Josh Newlan, Ju yeong Ji, Kareem Mohamed, Kartikeya Badola, Kat Black, Katie Millican, Keelin McDonell, Kelvin Nguyen, Kiranbir Sodhia, Kish Greene, Lars Lowe Sjoesund, Lauren Usui, Laurent Sifre, Lena Heuermann, Leticia Lago, Lilly McNealus, Livio Baldini Soares, Logan Kilpatrick, Lucas Dixon, Luciano Martins, Machel Reid, Manvinder Singh, Mark Iverson, Martin Görner, Mat Velloso, Mateo Wirth, Matt Davidow, Matt Miller, Matthew Rahz, Matthew Watson, Meg Risdal, Mehran Kazemi, Michael Moynihan, Ming Zhang, Minsuk Kahng, Minwoo Park, Mofí Rahman, Mohit Khatwani, Natalie Dao, Nenshad Bardolwallila, Nesh Devanathan, Neta Dumai, Nilay Chauhan, Oscar Wahltinez, Pankil Botarda, Parker Barnes, Paul Barham, Paul Michel, Pengchong Jin, Petko Georgiev, Phil Culliton, Pradeep Kuppala, Ramona Comanescu, Ramona Merhej, Reena Jana, Reza Ardeshir Rokni, Rishabh Agarwal, Ryan Mullins, Samaneh Saadat, Sara McCarthy, Sarah Cogan, Sarah Perrin, Sébastien M. R. Arnold, Sebastian Krause, Shengyang Dai, Shruti Garg, Shruti Sheth, Sue Ronstrom, Susan Chan, Timothy Jordan, Ting Yu, Tom Eccles, Tom Hennigan, Tomas Kocisky, Tulsee Doshi, Vihan Jain, Vikas Yadav, Vilobh Meshram, Vishal Dharmadhikari, Warren Barkley, Wei Wei, Wenming Ye, Woohyun Han, Woosuk Kwon, Xiang Xu, Zhe Shen, Zhitao Gong, Zichuan Wei, Victor Cotruta, Phoebe Kirk, Anand Rao, Minh Giang, Ludovic Peran, Tris Warkentin, Eli Collins, Joelle Barral, Zoubin Ghahramani, Raia Hadsell, D. Sculley, Jeanine Banks, Anca Dragan, Slav Petrov, Oriol Vinyals, Jeff Dean, Demis Hassabis, Koray Kavukcuoglu, Clement Farabet, Elena Buchatskaya, Sebastian Borgeaud, Noah Fediel, Armand Joulin, Kathleen Kenealy, Robert Dadashi, and Alek Andreev. Gemma 2: Improving open language models at a practical size, 2024. URL https://arxiv.org/abs/2408.00118.
  39. [41]Eric Todd, Millicent Li, Arnab Sen Sharma, Aaron Mueller, Byron Wallace, and David Bau. Function vectors in large language models. In International conference on learning representations, volume 2024, pp. 17282–17333, 2024.arxiv.org/abs/2310.15213
  40. [42]Johannes Von Oswald, Eyvind Niklasson, Ettore Randazzo, João Sacramento, Alexander Mordvintsev, Andrey Zhmoginov, and Max Vladymyrov. Transformers learn in-context by gradient descent. In International Conference on Machine Learning, pp. 35151–35174. PMLR, 2023.arxiv.org/abs/2212.07677
  41. [43]Aaron T Wang, William Convertino, Xiang Cheng, Ricardo Henao, and Lawrence Carin. On understanding attention-based in-context learning for categorical data. In Forty-second International Conference on Machine Learning, 2025. URL https://openreview.net/forum?id=7Daf4TtMx9.arxiv.org/abs/2405.17248
  42. [44]Noam Wies, Yoav Levine, and Amnon Shashua. The learnability of in-context learning. In Thirty-seventh Conference on Neural Information Processing Systems, 2023. URL https://openreview.net/forum?id=f3JNQd7CHM.arxiv.org/abs/2303.07895
  43. [45]Kayo Yin and Jacob Steinhardt. Which attention heads matter for in-context learning? In Forty-second International Conference on Machine Learning, 2025. URL https://openreview.net/forum?id=C7XmEByCFv.arxiv.org/abs/2502.14010
  44. [46]Kaiyi Zhang, Ang Lv, Yuhan Chen, Hansen Ha, Tao Xu, and Rui Yan. Batch-icl: Effective, efficient, and order-agnostic in-context learning. In Findings of the Association for Computational Linguistics: ACL 2024, pp. 10728–10739, 2024.arxiv.org/abs/2401.06469
  45. [47]Xiang Zhang, Junbo Zhao, and Yann LeCun. Character-level convolutional networks for text classification. Advances in neural information processing systems, 28, 2015.arxiv.org/abs/1509.01626

Paper details

vlnc:W_pzyfye6z
Version
v1 · latest
Published
Fresh — added to the Hub within the last 30 days
Added
License
CC BY 4.0
Usage

views · 11

downloads · 0

A view counts once per browser per day, a download each time the PDF is requested.

  • Computer Science

generative AI tools

View statement
Looking for related papers…
Contents