Abstract
In-context learning (ICL) has demonstrated significant potential in enhancing the capabilities of large language models (LLMs) during inference. It's well-established that ICL heavily relies on selecting effective demonstrations to generate outputs that better align with the expected results. As for demonstration selection, previous approaches have typically relied on intuitive metrics to evaluate the effectiveness of demonstrations, which often results in limited robustness and poor cross-model generalization capabilities. To tackle these challenges, we propose a novel method, Demonstration VAlidation (D.Va), which integrates a demonstration validation perspective into this field. By introducing the demonstration validation mechanism, our method effectively identifies demonstrations that are both effective and highly generalizable. D.Va surpasses all existing demonstration selection techniques across both natural language understanding (NLU) and natural language generation (NLG) tasks. Additionally, we demonstrate the robustness and generalizability of our approach across various language models with different retrieval models.
Introduction
Large Language Models (LLMs) have revolutionized natural language processing through In-Context Learning (ICL), a paradigm where models perform tasks by observing a few examples provided in the prompt. Despite its success, ICL is highly sensitive to the choice and ordering of these demonstrations. Selecting the wrong examples can lead to significant performance degradation.
Existing selection strategies generally fall into two categories: data-dependent methods (e.g., similarity-based retrieval) and self-adaptive methods (e.g., model-based scoring). However, these methods often suffer from the "Ground Truth Gap"—the inability to know the correct answer for a test query during inference—and poor cross-model generalization, where examples chosen for one model fail to benefit another. To address these issues, we introduce D.Va (Demonstration VAlidation), a framework that "test-drives" demonstrations on proxy examples to ensure their effectiveness before final inference.
The D.Va Framework
D.Va utilizes a three-stage "select-then-validate" pipeline designed to bridge the ground truth gap and improve selection robustness.
1. Candidate Retrieval
The process begins with a standard retriever (such as BM25 or Sentence-BERT) to identify a pool of potential demonstrations from the training set based on their similarity to the test query.
2. Demonstration Validation
This stage is the core innovation of D.Va. Since the ground truth for the test query is unknown, D.Va employs a validation anchor—the most similar example from the training set for which the answer is known.
- The Test Drive: Each candidate demonstration is evaluated by its ability to help the LLM predict the correct answer for the validation anchor.
- Preference-Based Calibration: Because the validation anchor is not identical to the test query, D.Va introduces a calibration term ($\epsilon$). This term uses a Bradley-Terry model to measure the LLM's relative preference between the test input and the validation input, effectively "de-biasing" the validation score.
- Scoring: A final score is assigned to each candidate by balancing the validation performance and the calibration term using a hyperparameter $\lambda$.
3. Inference
The highest-scoring demonstrations are re-ranked and included in the prompt for the final inference on the test query.
Experimental Setup
We evaluated D.Va across a comprehensive suite of benchmarks spanning Natural Language Understanding (NLU) and Natural Language Generation (NLG):
- NLU Tasks: Topic classification (Trec, AgNews), sentiment analysis (SST-2, SST-5), question answering (Commonsense QA), and natural language inference (SNLI, MNLI, QNLI).
- NLG Tasks: Machine translation (Flores200), reading comprehension (SQuAD v2), and dialogue summarization (SamSum).
Testing was conducted across various model architectures, including the Llama-3.1 and Llama-3.2 series, to assess performance and cross-model transferability.
Key Results and Insights
State-of-the-Art Performance
D.Va consistently outperformed existing baselines such as TopK, MDL, and ConE. On Llama-3.2-1B, D.Va achieved an average improvement of 2.60% over the next best method across all datasets. The method proved robust regardless of the underlying retriever used (e.g., BM25 vs. bge-m3).
Cross-Model Generalization
A significant finding is D.Va's ability to generalize across models. We observed that a small, computationally inexpensive model (like Llama-3.2-1B) can be used to perform the validation and selection process for a much larger model (like Llama-3.1-8B). The performance drop in this "small-to-large" transfer was less than 0.30%, suggesting that D.Va can be implemented cost-effectively in production environments.
Scaling and Efficiency
Unlike many selection methods that plateau, D.Va’s performance scales positively as the number of in-context shots increases (from 1 to 16). While the validation stage introduces a forward-pass overhead, it remains significantly more efficient than complex methods like Minimum Description Length (MDL) while yielding superior accuracy.
Conclusion
D.Va introduces a robust validation mechanism to the demonstration selection process, effectively bridging the gap between retrieval and inference. By simulating performance on known anchors and applying preference-based calibration, D.Va ensures that the selected examples are truly beneficial to the model. Future work will explore the integration of D.Va into the model training phase and its scalability to models exceeding 70B parameters.
Summary updated