mlsanityData to 14 Oct 2026

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

arXiv 2508.19999 ↗First posted 27 Aug 2025cs.LG cs.AI cs.CLcited by 8

Not on the map. Why?

Abstract (arXiv)

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× on models with up to 34 billion parameters, and outperform existing selection methods based on input embeddings by 11% on average.

Key facts. Cited by 8 papers in the map (data through 14 Oct 2026). Builds on 31 of its 39 references that are in the map. First posted on arXiv 27 Aug 2025.

Builds on

31 of 39 references.

References · 31

  1. 2020Language Models are Few-Shot Learnerscited by 32,419
  2. 2018GLUE: A Multi-Task Benchmark and Analysis Platform for Natural Language Understandingcited by 4,899
  3. 2017Understanding Black-box Predictions via Influence Functionscited by 1,741
  4. 2020Don't Stop Pretraining: Adapt Language Models to Domains and Taskscited by 1,565
  5. 2022Rethinking the Role of Demonstrations: What Makes In-Context Learning Work?cited by 1,434
  6. 2020Gradient Surgery for Multi-Task Learningcited by 1,256
  7. 2021What Makes Good In-Context Examples for GPT-3?cited by 1,195
  8. 2021Learning to Prompt for Continual Learningcited by 944
  9. 2022A Survey on In-context Learningcited by 721
  10. 2022What Can Transformers Learn In-Context? A Case Study of Simple Function Classescited by 715
  11. 2023Trained Transformers Learn Linear Models In-Contextcited by 337
  12. 2024A Survey on Data Selection for Language Modelscited by 236
19 more
  1. 2021Efficiently Identifying Task Groupings for Multi-Task Learningcited by 222
  2. 2022Rethinking with Retrieval: Faithful Large Language Model Inferencecited by 145
  3. 2024In-Context Learning with Long-Context Models: An In-Depth Explorationcited by 128
  4. 2020Understanding and Improving Information Transfer in Multi-Task Learningcited by 114
  5. 2023How Many Pretraining Tasks Are Needed for In-Context Learning of Linear Regression?cited by 96
  6. 2024Revisiting Demonstration Selection Strategies in In-Context Learningcited by 58
  7. 2022Robust Fine-Tuning of Deep Neural Networks with Hessian-based Generalization Guaranteescited by 34
  8. 2024Parallel Structures in Pre-training Data Yield In-Context Learningcited by 26
  9. 2025From Few to Many: Self-Improving Many-Shot Reasoners Through Iterative Optimization and Generationcited by 21
  10. 2024Scalable Multitask Learning Using Gradient-based Estimation of Task Affinitycited by 20
  11. 2023Boosting Multitask Learning on Graphs through Higher-Order Task Affinitiescited by 15
  12. 2023Noise Stability Optimization for Finding Flat Minima: A Hessian-based Regularization Approachcited by 14
  13. 2024Scalable Fine-tuning from Multiple Data Sources: A First-Order Approximation Approachcited by 13
  14. 2024Toward In-Context Teaching: Adapting Examples to Students' Misconceptionscited by 12
  15. 2025Efficient Ensemble for Fine-tuning Language Models on Multiple Datasetscited by 10
  16. 2024Divide, Reweight, and Conquer: A Logit Arithmetic Approach for In-Context Learningcited by 9
  17. 2023Exploring Demonstration Ensembling for In-context Learningcited by 8
  18. 2025Compute-Optimal LLMs Provably Generalize Better With Scalecited by 5
  19. 2024Dynamic Uncertainty Ranking: Enhancing Retrieval-Augmented In-Context Learning for Long-Tail Knowledge in LLMscited by 3

Built on by

Cited by year (2026 to 14 Oct)

Citing papers per year: 2025: 3; 2026: 5.

8 papers.

Similar, not cited

Close in wording, no citation either way

  1. 2026Meta-Sel: Efficient Demonstration Selection for In-Context Learning via Supervised Meta-Learning
  2. 2024Demonstration Selection for In-Context Learning via Reinforcement Learning
  3. 2023In-Context Learning with Iterative Demonstration Selection
  4. 2024Demonstration Notebook: Finding the Most Suited In-Context Learning Example from Interactions
  5. 2025Efficient and Effective In-context Demonstration Selection with Coreset
  6. 2022Can In-context Learners Learn a Reasoning Concept from Demonstrations?
  7. 2025Unraveling Indirect In-Context Learning Using Influence Functions
  8. 2023Dr.ICL: Demonstration-Retrieved In-context Learning