Selecting Demonstrations for Many-Shot In-Context Learning via Gradient Matching

In-Context Learning (ICL) empowers Large Language Models (LLMs) for rapid task adaptation without Fine-Tuning (FT), but its reliance on demonstration selection remains a critical challenge.While many-shot ICL shows promising performance through scaled demonstrations, the selection method for many-shot demonstrations remains limited to random selection in existing work.Since the conventional instance-level retrieval is not suitable for manyshot scenarios, we hypothesize that the data requirements for in-context learning and finetuning are analogous.To this end, we introduce a novel gradient matching approach that selects demonstrations by aligning fine-tuning gradients between the entire training set of the target task and the selected examples, so as to approach the learning effect on the entire training set within the selected examples.Through gradient matching on relatively small models, e.g., Qwen2.5-3B or Llama3-8B, our method consistently outperforms random selection on larger LLMs from 4-shot to 128-shot scenarios across 9 diverse datasets.For instance, it surpasses random selection by 4% on Qwen2.5-72B and Llama3-70B, and by around 2% on 5 closedsource LLMs.This work unlocks more reliable and effective many-shot ICL, paving the way for its broader application.

Authors

Publication Details

Published
2025-01-01
DOI
https://doi.org/10.18653/v1/2025.findings-acl.608
Primary Topic
Domain Adaptation and Few-Shot Learning
Type
article
Field-Weighted Citation Impact
0.00

Funders

Controls
|||
ALL TIME
JAN
FEB
MAR
APR
MAY
JUN
JUL
AUG
SEP
OCT
article

Selecting Demonstrations for Many-Shot In-Context Learning via Gradient Matching

Chenghua Lin, Rumei Li, Jianfei Zhang, Wenge Rong et al.
Domain Adaptation and Few-Shot Learning
article

Selecting Demonstrations for Many-Shot In-Context Learning via Gradient Matching

Chenghua Lin, Rumei Li, Jianfei Zhang, Wenge Rong, Jun Bai, Yanmeng Wang, Bei Li
article en

Abstract

In-Context Learning (ICL) empowers Large Language Models (LLMs) for rapid task adaptation without Fine-Tuning (FT), but its reliance on demonstration selection remains a critical challenge.While many-shot ICL shows promising performance through scaled demonstrations, the selection method for many-shot demonstrations remains limited to random selection in existing work.Since the conventional instance-level retrieval is not suitable for manyshot scenarios, we hypothesize that the data requirements for in-context learning and finetuning are analogous.To this end, we introduce a novel gradient matching approach that selects demonstrations by aligning fine-tuning gradients between the entire training set of the target task and the selected examples, so as to approach the learning effect on the entire training set within the selected examples.Through gradient matching on relatively small models, e.g., Qwen2.5-3B or Llama3-8B, our method consistently outperforms random selection on larger LLMs from 4-shot to 128-shot scenarios across 9 diverse datasets.For instance, it surpasses random selection by 4% on Qwen2.5-72B and Llama3-70B, and by around 2% on 5 closedsource LLMs.This work unlocks more reliable and effective many-shot ICL, paving the way for its broader application.

National Natural Science Foundation of China
Openalex Percentile: Top 90%
Domain Adaptation and Few-Shot Learning
AI Navigator

Ask Laika to Summarize, Analyze, and Connect papers live on the map.

Summarize Papers & Methodologies

Extract key findings, datasets, and comparative methods across publications.

Benchmark Rankings & Visual Analytics

Rank top research institutions, authors, funders, topics, and journals by Field-Weighted Citation Impact (FWCI) and paper volume with instant charts.

Connect Distant Disciplines

Bridge topological clusters on the map to find hidden collaborative intersections.