TL;DR
The paper introduces InfICL, a novel and cost-effective method for selecting the best few-shot demonstrations for In-Context Learning (ICL) using gradient-based influence functions. Instead of performing computationally expensive LLM fine-tuning or retraining, InfICL calculates influence scores using a simple local classifier trained on frozen LLM embeddings. This approach consistently outperforms state-of-the-art selection methods across various datasets and model sizes while reducing execution latency from days to minutes.
What Problem Does This Paper Address?
Large Language Models (LLMs) possess a remarkable ability called In-Context Learning (ICL), where they learn to perform a task simply by looking at a few examples (demonstrations) provided in the prompt, without any gradient updates. However, ICL is notoriously sensitive: picking the wrong demonstrations can tank a model's performance.
Current selection methods fall into two camps, both with major drawbacks:
- Similarity-based methods (e.g., RICES): These select examples that are closest to the test query in the embedding space. While fast, they don't necessarily pick the most informative or "influential" examples for the model's underlying reasoning.
- Retraining-based influence methods: These evaluate an example's worth by repeatedly retraining models with and without specific subsets of data. While accurate, doing this with LLMs requires an astronomical number of API calls or forward passes, making it completely impractical for real-world use.
The authors bridge this gap by creating a method that captures the deep data-dynamics of influence functions without the crippling computational overhead.
Methods
The authors propose InfICL (Influence-based In-Context Learning), which leverages gradient-based influence functions to identify which training samples will most effectively minimize validation loss.
To keep the process cheap and fast, InfICL follows a clever proxy pipeline:
- Embedding Generation: A smaller, local LLM is used as a frozen feature extractor to generate embeddings for all training and validation sentences.
- Proxy Classifier: The authors train a simple, lightweight three-layer fully connected neural network on these embeddings.
- Influence Analysis: Using this proxy classifier, they calculate the gradient-based influence score of each training sample against the validation set. They use the LiSSA algorithm to efficiently approximate the inverse Hessian-Vector Product (iHVP), avoiding heavy matrix inversions.
- Balanced Selection: The training samples with the highest positive influence scores from each class are selected to form the final demonstration set ($K$ shots).
- Inference: These optimal demonstrations are prepended to the test case and sent to a larger, powerful external LLM for final inference.
The authors also extend InfICL to a Personalized Demonstration Selection variant, which combines a sample's global influence score with its cosine similarity to the specific test case.
Datasets
The method was evaluated on three widely used text classification benchmarks:
- CoLA (Corpus of Linguistic Acceptability): Evaluating grammatical acceptability (binary).
- RTE (Recognizing Textual Entailment): Determining if a hypothesis can be inferred from a premise (binary).
- SST2 (Stanford Sentiment Tree-bank version 2): Movie review sentiment analysis (binary).
No new benchmarks were introduced. The exact data splits used for training, validation, and testing are detailed below:
Key Insights and Ideas
- Proxy Transferability: One of the most surprising findings is that influence scores calculated on a simple neural network trained on frozen embeddings transfer remarkably well to giant, completely different external LLMs performing ICL.
- The Value of Sparse Clusters: Influence functions naturally assign higher scores to training points located in "sparse clusters" (i.e., unique or atypical examples). In dense clusters, removing an example doesn't matter because plenty of similar examples fill the gap. InfICL excels because it intentionally selects these rare, highly informative examples as demonstrations.
- Positive Influence Matters Most: By explicitly testing different tiers of influence scores (top positive, middle, and top negative), the authors confirmed that examples that actively reduce validation loss (top positive) yield the highest ICL accuracy.
Key Results
The authors evaluated InfICL against non-influence baselines (Zero-shot, Random, RICES) and retraining-based influence baselines (Influence, CondAcc, Data Models) across multiple model families (Llama-2-7B/13B/70B, OPT-6.7B).
- Superior Accuracy: InfICL consistently outperformed Zero-shot, Random, and similarity-based RICES across almost all datasets and model sizes. Student's t-tests confirmed that InfICL's performance gains were statistically significant in 20 out of 24 tested scenarios.
- Massive Efficiency Gains: Compared to other influence-based selection techniques, InfICL's speedup is massive. For a 4-shot setup on the CoLA dataset using Llama-2-7B:
- InfICL: ~10 minutes
- Influence: 3.5 hours
- CondAcc / Data Models: Over 80 hours
Limitations and Future Work
Despite its strong empirical performance, the authors note a prominent theoretical limitation: ICL does not actually update model weights, whereas gradient-based influence functions inherently assume a gradient-descent learning paradigm. While the proxy method works well in practice, a rigorous theoretical framework is still needed to fully explain why gradient-based influence maps so cleanly to in-context learning dynamics.
For future work, the authors plan to scale InfICL to Large Vision-Language Models (LVMs) and evaluate its efficacy on more complex tasks, such as massive multitask language understanding.
Summary updated