More Samples or More Prompt Inputs? Exploring Effective In-Context Sampling for LLM Few-Shot Prompt Engineering

Bingsheng Yao, Guiming Chen, Ruishi Zou, Yuxuan Lu, Jiachen Li, Shao Zhang, Sijia Liu, James A. Hendler, Dakuo Wang · DOI

Abstract

In-Context Learning (ICL) has become a standard method for adapting Large Language Models (LLMs) to specific tasks using a few examples. However, ICL performance is highly sensitive to example selection and ordering. This paper proposes In-Context Sampling (ICS), a simple yet effective paradigm that shifts the focus from finding a single optimal prompt to aggregating results from multiple prompt variations. By generating $k$ different prompts from a candidate pool and using a majority vote for the final prediction, ICS achieves significant improvements in accuracy and robustness across diverse reasoning tasks.

Introduction

The effectiveness of In-Context Learning (ICL) is often hindered by its brittleness; minor changes in the prompt can lead to significant fluctuations in model performance. Traditional research has focused on optimizing the selection of examples for a single prompt. This work explores an alternative: leveraging multiple prompt inputs to create a "committee" of predictions. The proposed In-Context Sampling (ICS) framework aims to mitigate the variance of ICL and squeeze more reliable performance out of existing LLMs.

Methodology: The In-Context Sampling (ICS) Paradigm

The ICS framework operates through a three-step pipeline designed to maximize the utility of available labeled data:

  1. Sample: A pool of $n$ representative demonstration candidates is selected from unlabeled data. Labels are then acquired from an oracle or a high-performing teacher model.
  2. Augment: For each test instance $x$, $k$ distinct prompt inputs are constructed. Each prompt contains a unique combination of examples sampled from the $n$ candidates.
  3. Vote: The LLM processes all $k$ prompts independently. A majority vote or "committee" approach is used to determine the final, most confident prediction ($label_{final}x$).
The In-Context Sampling (ICS) pipeline, illustrating the sampling, augmentation, and voting stages.

Beyond simple random selection, the researchers explored various strategies for selecting examples, including Diversity (representing the data space via clustering), Similarity (matching the training distribution), and a Hybrid approach.

Experimental Setup

The ICS paradigm was evaluated on five challenging datasets:

  • Natural Language Inference (NLI): e-SNLI, Multi-NLI, and ANLI.
  • Domain-Specific NLI: Contract-NLI (legal domain).
  • Commonsense Reasoning: CommonsenseQA (CQA).

Experiments were conducted using three prominent open-source models: FlanT5-XL, Mistral-7B, and Mixtral-8x7B.

Key Results and Discussion

ICS consistently outperformed traditional few-shot ICL across all tested models and datasets. For Mistral-7B and Mixtral-8x7B, the average accuracy improvement exceeded 5%.

The "Committee" Effect and Robustness

The primary driver of ICS's success is the aggregation of "opinions" across different contexts. By providing various sets of examples, the model receives diverse implicit guidance, and the majority vote effectively filters out noise. This process significantly reduces output variance, making LLM behavior more predictable.

Impact of Sample Size and Prompt Variations

The study found that while increasing the candidate pool size ($n$) beyond 100 samples yields diminishing returns, increasing the number of prompt variations ($k$) continues to improve performance up to a certain threshold.

Accuracy comparison for ANLI and Contract-NLI datasets across different values of k, showing consistent gains for ICS over baseline.

Task Difficulty and Model Knowledge

An interesting finding was "difficulty inversion": the largest relative gains from ICS were observed on easier tasks (e.g., e-SNLI), while gains on highly complex tasks (e.g., ANLI) were smaller but still consistent. Furthermore, ICS cannot fully compensate for a lack of underlying domain knowledge; models that struggled with specific domains (like legal text in Contract-NLI) continued to do so regardless of the prompting strategy.

Conclusion and Future Work

In-Context Sampling offers a robust alternative to traditional prompt engineering by leveraging multiple inputs to stabilize and enhance LLM performance. While the increased inference cost is a notable trade-off, the consistent accuracy gains make it a compelling strategy for high-stakes applications. Future research will focus on optimizing the computational efficiency of ICS and exploring more sophisticated voting mechanisms based on internal model confidence scores.

Summary updated

BibTeX
@inproceedings{yao2024more,
  author = {Bingsheng Yao and Guiming Chen and Ruishi Zou and Yuxuan Lu and Jiachen Li and Shao Zhang and Sijia Liu and James A. Hendler and Dakuo Wang},
  title = {{More Samples or More Prompt Inputs? Exploring Effective In-Context Sampling for LLM Few-Shot Prompt Engineering}},
  booktitle = {Conference of the North American Chapter of the Association for Computational Linguistics},
  year = {2024},
  doi = {10.18653/v1/2024.findings-naacl.115},
}
Figure