arXiv:2507.16217cs.CLcs.AI2025-07中稿 · COLM被引 2

优化大量示范样本的选取,显著降低推理成本并提升效果。

Towards Compute-Optimal Many-Shot In-Context Learning

  • 结合相似性匹配与缓存随机样例,提升示范选择效率。
  • 采用聚类中心筛选样例,性能超越随机选择,最高降本90%。
  • 可灵活调节策略比例,兼顾精度与计算开销,适合实际部署。

长上下文大语言模型可处理高达数百万标记的输入,在上下文学习(ICL)中意味着可在提示中使用数百甚至数千个示范样本,实现多示例学习。实践中,由于推理成本高、缓存复用优势以及随机选取在规模下表现相近,常采用固定随机示范集。本文提出两种简单高效的示范选择策略:第一种将少量基于测试样本相似性选取的示范与大量缓存的随机示范结合;第二种通过k-means聚类生成测试样本表示的中心点,替代随机示范。在Gemini Pro和Flash模型上对多个数据集的实验表明,所提方法持续优于随机选择,性能达或超过最优现有方法,同时支持缓存机制,推理成本最高降低一个数量级。还发现可根据不同标准调整示范比例,平衡性能与开销,适用于真实场景的多示例学习。

原文摘要 · Abstract (English)

Long-context large language models (LLMs) are able to process inputs containing up to several million tokens. In the scope of in-context learning (ICL), this translates into using hundreds/thousands of demonstrations in the input prompt, enabling many-shot ICL. In practice, a fixed set of demonstrations is often selected at random in many-shot settings due to (1) high inference costs, (2) the benefits of caching and reusing computations, and (3) the similar performance offered by this strategy compared to others when scaled. In this work, we propose two straightforward strategies for demonstration selection in many-shot ICL that improve performance with minimal computational overhead. Our first method combines a small number of demonstrations, selected based on their similarity to each test sample, with a disproportionately larger set of random demonstrations that are cached. The second strategy improves the first by replacing random demonstrations with those selected using centroids derived from test sample representations via k-means clustering. Our experiments with Gemini Pro and Flash across several datasets indicate that our strategies consistently outperform random selection and surpass or match the most performant selection approach while supporting caching and reducing inference cost by up to an order of magnitude. We also show that adjusting the proportion of demonstrations selected based on different criteria can balance performance and inference cost in many-shot ICL.

上下文学习推理优化示范选择缓存机制

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