arXiv:2508.19999cs.LGcs.AI2025-08EMNLP被引 9

用梯度估算快速选出最合适的示例,提升上下文学习效率

Linear-Time Demonstration Selection for In-Context Learning via Gradient Estimation

  • 基于输出对输入嵌入的梯度进行一阶近似,快速估算推理结果
  • 在六大数据集上误差低于1%,可将计算量缩小37.7倍
  • 适合需要高效提示调优或思维链推理的大模型应用

本文提出一种算法,用于为查询集选择最优的上下文学习示例。给定n个候选示例,如何快速选出k个作为下游推理的条件?该问题广泛应用于提示调优和思维链推理。由于上下文学习中模型权重固定,以往方法依赖词元嵌入相似性。本文提出基于输出在输入嵌入空间梯度的新方法:通过一阶近似估算模型输出,对多个随机采样子集执行此操作,并聚合结果生成每个示例的影响得分,最终选取k个最相关示例。该方法仅需预计算一次模型输出与梯度,实现相对于模型和训练集规模的线性时间复杂度。在多种模型与数据集上的实验表明,该梯度估算的近似误差低于1%。该方法使原本需完整推理的子集选择可提速达37.7倍(支持最多340亿参数模型),且平均性能优于基于输入嵌入相似性的现有方法11%。

原文摘要 · Abstract (English)

This paper introduces an algorithm to select demonstration examples for in-context learning of a query set. Given a set of $n$ examples, how can we quickly select $k$ out of $n$ to best serve as the conditioning for downstream inference? This problem has broad applications in prompt tuning and chain-of-thought reasoning. Since model weights remain fixed during in-context learning, previous work has sought to design methods based on the similarity of token embeddings. This work proposes a new approach based on gradients of the output taken in the input embedding space. Our approach estimates model outputs through a first-order approximation using the gradients. Then, we apply this estimation to multiple randomly sampled subsets. Finally, we aggregate the sampled subset outcomes to form an influence score for each demonstration, and select $k$ most relevant examples. This procedure only requires pre-computing model outputs and gradients once, resulting in a linear-time algorithm relative to model and training set sizes. Extensive experiments across various models and datasets validate the efficiency of our approach. We show that the gradient estimation procedure yields approximations of full inference with less than ${1}\%$ error across six datasets. This allows us to scale up subset selection that would otherwise run full inference by up to ${37.7}\times$ on models with up to $34$ billion parameters, and outperform existing selection methods based on input embeddings by ${11}\%$ on average.

上下文学习梯度估计提示调优高效推理

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。