Se²: Sequential Example Selection for In-Context Learning

Haoyu Liu, Jianfeng Liu, Shaohan Huang, Yuefeng Zhan, Hao Sun, Weiwei Deng, Furu Wei, Qi Zhang

Abstract

The remarkable capability of large language models (LLMs) for in-context learning (ICL) needs to be activated by demonstration examples. Prior work has extensively explored the selection of examples for ICL, predominantly following the “select then organize” paradigm. However, such approaches often neglect the internal relationships between examples and exhibit an inconsistency between training and inference. In this paper, we formulate the problem as a Sequential Selection problem and introduce Se², a sequential-aware method that leverages the LLM’s feedback on varying context, aiding in capturing inter-relationships and sequential information among examples, significantly enriching the contextuality and relevance of ICL prompts. Meanwhile, we utilize beam search to seek and construct example sequences, enhancing both quality and diversity. Extensive experiments across 23 NLP tasks from 8 distinct categories illustrate that Se² markedly surpasses competitive baselines and achieves 42% relative improvement over random selection. Further in-depth analysis shows the effectiveness of proposed strategies, highlighting Se²‘s exceptional stability and adaptability across various scenarios.

Introduction: Moving Beyond "Select then Organize"

Large Language Models (LLMs) have revolutionized NLP through In-Context Learning (ICL), where they perform tasks based on a few demonstration examples. However, the performance of ICL is highly sensitive to the choice and ordering of these examples. Most existing selection methods follow a two-step "select then organize" paradigm: first, they retrieve a set of top-K similar examples independently, and then they attempt to find an optimal order.

Comparison of the traditional 'Select then Organize' paradigm versus the proposed 'Sequential Select' approach.

The authors argue that this paradigm is fundamentally flawed because it ignores the internal relationships between examples. A demonstration that is helpful in isolation might be redundant or even detrimental when paired with others. There is a "consistency gap" between independent selection and sequential usage. Se² addresses this by treating example selection as a sequential decision process.

Methodology: The Se² Framework

Se² reformulates example selection as a task of picking the next best example given the current context (the test input plus any previously selected demonstrations).

1. Sequential-Aware Scoring

Instead of relying solely on static semantic similarity, Se² uses the LLM itself to provide feedback. For Natural Language Understanding (NLU) tasks, it uses conditional likelihood to score how much a candidate example improves the model's confidence. For Natural Language Generation (NLG) tasks, it uses metrics like ROUGE to evaluate the quality of the generated output when a specific example is included.

2. Training the Sequential Retriever

The framework uses these scores to train a bi-encoder (initialized with BERT) using an InfoNCE loss. The objective is to maximize the similarity between the embedding of the current context and the embedding of the most beneficial next example. This allows the retriever to become "sequential-aware," learning to identify synergistic examples.

During deployment, Se² avoids greedy selection, which might lead to local optima. Instead, it employs beam search to maintain multiple candidate sequences. This allows the model to explore sequences that might start with a less obvious first example but result in a more effective overall demonstration set.

Experimental Evaluation

The researchers evaluated Se² on a comprehensive benchmark of 23 NLP tasks across 8 categories, including paraphrase detection, common reasoning, NLI, story generation, data-to-text, question answering, sentiment analysis, and text summarization.

Key Results and Analysis

Se² demonstrated significant performance gains and robustness compared to both random selection and state-of-the-art baselines like BM25, SBERT, and UPRISE.

Performance comparison between random selection and Se² across four diverse tasks, demonstrating higher mean performance and lower variance.

Quantitative Improvements

  • Relative Gains: Se² achieved a 42% relative improvement over random selection and a 25% improvement over the previous state-of-the-art universal retriever, UPRISE.
  • Stability: As shown in the violin plots, Se² not only achieves higher average scores but also exhibits much lower variance than random selection. This indicates that Se² consistently finds high-quality demonstration sequences, reducing the "prompt engineering" luck factor.
  • Scaling and Transferability: The method scales well with the number of shots and shows remarkable transferability. A retriever trained using feedback from a small model (GPT-Neo 2.7B) performed exceptionally well when used with larger models like LLaMA2-7B.

Qualitative Insights

Case studies revealed that Se² often selects examples that create a logical "conceptual progression." For instance, in scientific reasoning tasks, the selected examples might move from foundational facts to complex applications, effectively providing a high-level "Chain-of-Thought" structure for the LLM to follow.

Conclusion and Future Directions

Se² represents a significant shift in how we approach in-context learning by acknowledging the importance of sequential dependencies between examples. While the current implementation faces some computational overhead during the initial scoring phase and is constrained by the context windows of the feedback models, it sets a new standard for automated prompt optimization. Future work will explore more efficient scoring mechanisms and the use of modern decoder-only architectures for the retriever to further enhance performance.

Summary updated

BibTeX
@inproceedings{liu2024se,
  author = {Haoyu Liu and Jianfeng Liu and Shaohan Huang and Yuefeng Zhan and Hao Sun and Weiwei Deng and Furu Wei and Qi Zhang},
  title = {{Se²: Sequential Example Selection for In-Context Learning}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2024},
  url = {https://openreview.net/forum?id=gMNf7sylip},
}
Figure