Comparable Demonstrations Are Important In In-Context Learning: A Novel Perspective On Demonstration Selection

Caoyun Fan, Jidong Tian, Yitian Li, Hao He, Yaohui Jin

TL;DR

Large Language Models (LLMs) often fail at In-Context Learning (ICL) because they latch onto spurious correlations in the few examples provided—a phenomenon called "demonstration bias." This paper introduces Comparable Demonstrations (CDs): pairs of examples where the text is minimally edited to flip the label, forcing the model to ignore the "noise" and focus on the task's true essence.

What Problem Does This Paper Address?

In-Context Learning (ICL) has become the go-to method for adapting LLMs to new tasks without fine-tuning. You simply provide a few examples (demonstrations) in the prompt, and the model "gets it." However, because the number of examples is so small (usually <10), the model can easily induce the wrong "input-label mapping."

For instance, if you show a model two positive movie reviews that happen to both be about romantic films, the model might conclude the task is "identify romantic movies" rather than "identify positive sentiment." The authors call this demonstration bias. While previous research focused on label spaces or semantic similarity, this paper looks at the relationship between the demonstrations themselves.

Methods

The authors propose a novel selection strategy: Comparable Demonstrations (CDs).

Inspired by how humans learn (e.g., showing an infant an apple and a pear to teach them to differentiate fruits), CDs are constructed by taking an original text and minimally editing it to flip its label.

  • Original: "I like this movie, I never get tired of watching it." (Positive)
  • Edited: "I hate this movie, I am very tired of watching it." (Negative)

By providing these "near-miss" pairs, the model is forced to see exactly which words or structures trigger the label change.

To prove that bias exists, the authors used Instruction Induction. They asked the LLM (GPT-3.5-Turbo) to generate a written description of the task based on the provided examples. If the model generated a bad instruction (e.g., "Read the review of comedy..." instead of "Determine sentiment"), it proved the model had a biased understanding of the task.

Datasets

The researchers evaluated their approach across two primary NLP tasks:

  1. Sentiment Analysis: Using IMDb as the In-Distribution (ID) dataset, and Amazon and Yelp reviews as Out-of-Distribution (OOD) datasets.
  2. Natural Language Inference (NLI): Using SNLI (ID) and MNLI (OOD).

They compared four selection strategies: random selection, semantic similarity (nearest neighbor), random CDs, and a hybrid "CDs nearest" approach.

Key Insights and Ideas

  • Demonstration Bias is Real: The "Instruction Induction" experiments revealed that LLMs frequently over-interpret or over-simplify tasks when given random or merely "similar" examples.
  • The "Similarity Trap": Selecting examples based purely on semantic similarity (the standard "nearest neighbor" approach) can actually be detrimental. These examples often contain too much repetitive, task-irrelevant information, which hinders the model from finding the true input-label mapping.
  • CDs as a Task "Highlighter": By showing the model the "difference that makes a difference," CDs effectively eliminate spurious correlations. The model learns that the sentiment isn't about the movie genre or the length of the text, but specific valence-carrying words.
  • Robustness to Shot Count: Unlike standard ICL, which can be extremely sensitive to the number and order of examples, the performance of CDs remains relatively robust as the "shot" count (K=4, 8, 12) increases.

Key Results

  • OOD Superiority: The most significant gains were seen in Out-of-Distribution scenarios. On the Yelp sentiment dataset (8-shot), the "CDs nearest" strategy outperformed the standard "nearest" strategy by 7.6%.
  • Reducing Bias: In the manual evaluation of generated instructions, CDs significantly outperformed other strategies. While random selection and semantic similarity often led to "invalid" or "acceptable but imperfect" instructions, CDs produced "correct and satisfying" instructions at a much higher rate.
  • The Winning Hybrid: The "CDs nearest" strategy—which selects comparable pairs that are also semantically close to the test query—emerged as the most competitive strategy for balancing both ID and OOD performance.

Limitations and Future Work

The authors acknowledge two main hurdles:

  1. Annotation Cost: Creating high-quality CDs currently requires manual editing (the authors used existing Counterfactually-Augmented Data). Automatically generating these pairs reliably is an open challenge.
  2. Complexity of Relationships: This study focused on one-to-one relationships between demonstrations. Future work could explore "many-to-many" relationships to capture even more nuanced task essences.
  3. Task Scope: The current study focused on classification (Sentiment, NLI). Whether this approach scales to more complex reasoning tasks like multi-hop inference or mathematical word problems remains to be seen.

Summary updated

Abstract

In-Context Learning (ICL) is an important paradigm for adapting Large Language Models (LLMs) to downstream tasks through a few demonstrations. Despite the great success of ICL, the limitation of the demonstration number may lead to demonstration bias, i.e. the input-label mapping induced by LLMs misunderstands the task’s essence. Inspired by human experience, we attempt to mitigate such bias through the perspective of the inter-demonstration relationship. Specifically, we construct Comparable Demonstrations (CDs) by minimally editing the texts to flip the corresponding labels, in order to highlight the task’s essence and eliminate potential spurious correlations through the inter-demonstration comparison. Through a series of experiments on CDs, we find that (1) demonstration bias does exist in LLMs, and CDs can significantly reduce such bias; (2) CDs exhibit good performance in ICL, especially in out-of-distribution scenarios. In summary, this study explores the ICL mechanisms from a novel perspective, providing a deeper insight into the demonstration selection strategy for ICL.
BibTeX
@inproceedings{fan2024comparable,
  author = {Caoyun Fan and Jidong Tian and Yitian Li and Hao He and Yaohui Jin},
  title = {{Comparable Demonstrations Are Important In In-Context Learning: A Novel Perspective On Demonstration Selection}},
  booktitle = {IEEE International Conference on Acoustics, Speech and Signal Processing},
  year = {2024},
  doi = {10.1109/icassp48485.2024.10448239},
}

Loading related content...

Figure