How Many Demonstrations Do You Need for In-context Learning? (2023)

Abstract: Large language models (LLMs) are capable to perform complex reasoning by in-context learning (ICL) when provided with a few input-output demonstrations (demos) and more powerful when intermediate reasoning steps (chain of thoughts (CoT)) of the demos are given. Is it necessary to use multi-demo in ICL? In this paper, we study ICL using fewer demos for each test query on the tasks in (Wei et al., 2022). Surprisingly, we do not observe significant degradation when using only one randomly chosen demo. To study this phenomenon, for each test query, we categorize demos into “positive demos” leading to the correct answer, and “negative demos” resulting in wrong answers. Our analysis reveals an inherent bias in those widely studied datasets and the redundancy of demos: most demos are positive for a majority of test queries, which explains the good performance of ICL with one random demo. Moreover, ICL (with and w/o CoT) using only one positive demo significantly outperforms multi-demo ICL adopted by most previous works, indicating the weakness of LLMs in finding positive demo(s) for input queries, which is difficult to evaluate on the biased datasets. Furthermore, we observe a counterintuitive behavior of ICL using multi-demo, i.e., its accuracy degrades(improves) when given more positive(negative) demos. This implies that ICL can be easily misguided by interference among demos and their spurious correlations. Our analyses highlight several fundamental challenges that need to be addressed in LLMs training, ICL, and benchmark design.

## introduction the recent race of large language models (llms) @xcite @xcite shows that the capability of reasoning can be significantly improved with the scaling of model size. one of the most remarkable behaviors observed in llms is in-context learning (icl) @xcite , which provides llms with human-written instruction and a few exemplars or demonstrations (demos), along with the input queries. however, conventional few-shot prompting performs poorly on complex reasoning tasks @xcite . recently, an effective icl strategy for complex reasoning tasks, including arithmetic reasoning, commonsense reasoning, and symbolic reasoning, is to elaborate the intermediate reasoning step in each demo @xcite , namely chain-of-thoughts (cot) prompting. icl relies on human engineering and expertise in designing demo questions, intermediate reasoning steps, and final answers so the llm can generalize them to a variety of unseen queries. however, it is inefficient and impractical to design demos for different queries but a fixed set of demos might not cover all the possible queries. in addition, adding demos (especially in cot prompting) significantly increases input tokens, which are costly and may exceed the maximum input length of llms. to provide better demos for efficient icl and save human efforts, a very recent line of work studies automatic prompting @xcite @xcite , which leverage llms to select demo questions and construct their answers and cots for icl. they save human labor on creating demos but do not address several fundamental questions in icl, e.g., how many demos are necessary for icl? can llms in icl figure out which demo(s) is more useful to each test query? does icl leverage all the demos or mainly rely on a few of them to resolve each test query? can llms in icl combine the strengths of multiple demos to improve the answers? in this paper, we take the first step toward better understanding the effect of multiple demos in icl through a series of empirical studies on the demos and benchmarks widely used in cot prompting @xcite , which covers a diverse set of reasoning tasks. in particular, we investigate how the icl (with and w/o cot) performance changes when varying the number of demos and the impact of each demo on different test queries. we start with an extreme case of icl using only one demo randomly chosen for each query. surprisingly, compared to the default 8 (or 7)-demo icl in previous work, we do not observe a significant drop in the test accuracy. but does this imply that multiple demos are unnecessary to icl? to study this phenomenon, we take a closer look at the proportion of positive demos (i.e., the demos leading to correct answers in one demo icl) for each test query. statistics on all the datasets reveal a widely existing bias of easy queries, i.e., most demos are positive for a majority of queries, for which one (random) demo is all they need. that being said, how does icl perform on the test queries with fewer positive demos? unfortunately, though provided with some positive demos, icl fails to produce correct answers for many of them. we verify this by evaluating icl with one positive demo, which significantly outperforms the widely used multi-demo icl. this exposes a weakness of llms, i.e., they are not good at identifying the positive demo(s) and ignoring the negative ones for each query in multi-demo icl, even when more details such as cot are given. our further analysis reveals another deeper reason for this. specifically, we start from icl with one positive (negative) demo but adding more positive (negative) demos results in a counterintuitive degradation (improvement) of icl accuracy, indicating a negative impact of the interference or spurious correlation among demos on the llms. therefore, multiple demos might provide more information than a single demo but the current llms and icl methods cannot fully exploit them and filter out misleading interference. ## related work in-context learning (icl). in-context learning (icl) provides an efficient strategy to perform downstream task adaptations on pretrained llms @xcite . by prepending taskspecific instructions and some demos to each test query, the llm is able to accomplish highly specified tasks. recent work in icl focuses on automatically determining the prompts, e.g., training a dense retriever to allocate semantically similar training examples @xcite for each test query @xcite , estimating the llm's bias for better learning calibration parameters @xcite , etc. ## one-demo prompting it is common to use multiple demos in icl, e.g., manual-cot @xcite relies on humans to create a few demos for different tasks as shown in when we can filter out negative demos (defined in section 4.2) for each test query, one demo icl significantly outperforms the widely used multi-demo icl. we provide an in-depth analysis of the reasons behind these phenomena and they reveal some fundamental issues of llms and benchmarks. ## discussion in-context learning (icl) plays an important role in the ecosystem of llms. recent llms are capable of directly generating customized outputs by following the demos appended to input. however, it is not clear how many demos suffice to produce high-quality answers. in this paper, for the first time, we study the performance of icl (with or without cot prompting) under different numbers of demos and provide an in-depth investigation of the observations across several widely used benchmark datasets. in particular, we found that randomly selecting one single demo barely hurts the performance while increasing the demos merely brings marginal improvement. we then study how many demos can lead to correct answers in the one-demo icl for each sample and analyze its statistics over all samples in widely used benchmark datasets. the statistics reveal a widely existing dataset bias that easy samples with many positive demos dominate the datasets, which explains the high accuracy of icl with one random demo. it also exposes a weakness of llms in distinguishing negative/positive demos in icl. moreover, we found that only one positive demo is sufficient to significantly outperform multi-demo icl, while saving a great amount of cost. furthermore, we study the contribution and interference of cross-demo correlations to icl by investigating how the accuracy changes as we add more positive (negative) demos to the prompt. surprisingly, adding positive demos reduces the accuracy while adding negative demos brings improvement, indicating a problematic interpretation and exploitation of the cross-demo correlations by llms in icl. our analyses highlight several fundamental challenges that need to be addressed in the future, e.g., how to design less biased benchmarks and more diverse demos that can be used to better evaluate llms' capability of distinguishing positive demos from the negative ones; how to improve the efficiency and effectiveness of multi-demo usage in icl; how to avoid the harmful interference caused by cross-demo correlations and meanwhile leverage them to improve the icl performance on hard samples with fewer positive demos; how to select positive demos for a given query, etc.