Abstract
Large pretrained language models (LLMs) have demonstrated remarkable In-Context Learning (ICL) capabilities, allowing them to perform unseen tasks simply by conditioning on a prompt containing a few input-output demonstrations. However, ICL performance is notoriously brittle and heavily dependent on the quality of the selected in-context examples. Existing selection methods rely on simple heuristics that choose examples individually, often leading to sub-optimal, redundant prompts. To address this, researchers propose CEIL (Compositional Exemplars for In-context Learning), a framework that formulates example selection as an end-to-end subset selection problem. By leveraging Determinantal Point Processes (DPPs) and contrastive learning, CEIL identifies diverse, non-redundant, and highly relevant exemplars that significantly boost LLM performance across a wide range of NLP benchmarks.
The Challenge: The Brittleness of Singleton Retrieval
While ICL is powerful, it is highly sensitive to the choice and ordering of prompt examples. A poor selection can cause an LLM's performance to plummet from state-of-the-art to near-random guessing.
Most traditional methods for selecting these examples are "singleton-based." They compare the test input against a training set and retrieve the top-$K$ most similar examples one by one, typically using metrics like BM25 or BERT embeddings. The fundamental flaw in this approach is that it ignores how the examples interact with one another. Retrieving the top three most similar examples often yields three nearly identical demonstrations. This redundancy wastes the LLM's strictly limited context window and fails to cover the full logical complexity of the task at hand.
The CEIL Framework: Optimizing the Set
CEIL shifts the paradigm from picking the best individual examples to finding the optimal composition of examples. It treats exemplar selection as a subset selection problem, built on four key pillars:
- Modeling with Determinantal Point Processes (DPPs): CEIL utilizes DPPs, a probabilistic framework uniquely suited to model the trade-off between relevance (how well an example matches the input) and diversity (how distinct the examples are from each other). Geometrically, a DPP assigns higher probabilities to sets of vectors that span a larger volume, naturally penalizing redundancy.
- Conditional Kernel: The framework introduces a learnable "conditional" kernel for the DPP. This allows the model to dynamically adjust the balance between relevance and diversity based on the specific nuances of the test input.
- Contrastive Learning (LLMs as Teachers): To train the BERT-based retriever, CEIL employs a contrastive loss mechanism. It scores different subsets of examples based on how much they help a frozen LLM (such as GPT-Neo) predict the correct answer. The retriever is trained to assign higher probabilities to the subsets that the LLM "prefers," effectively distilling the LLM's internal logic into a smaller, efficient retrieval model.
- Efficient Inference: Because finding the absolute best subset is an NP-hard problem, CEIL utilizes a greedy Maximum A Posteriori (MAP) inference algorithm. This ensures a near-optimal set of examples can be found efficiently in polynomial time.
Experimental Scope
The researchers rigorously evaluated CEIL on 12 datasets spanning 7 distinct NLP tasks:
- Classification: Sentiment Analysis (SST-5), Paraphrase Detection (MRPC), Natural Language Inference (MNLI, QNLI), and Commonsense Reasoning (CMSQA, HellaSwag).
- Generation: Open-domain Question Answering (WebQs), Code Generation (GeoQuery, NL2Bash), and Semantic Parsing (Break, MTOP, SMCalFlow).
Notably, the evaluation included compositional splits (such as TMCD and Length splits in GeoQuery) to test the model's ability to handle complex, multi-step logic.
Key Findings and Insights
- State-of-the-Art Performance: CEIL consistently outperformed all baselines—including Random, BM25, TopK-BERT, and EPR—across nearly every dataset tested.
- Massive Gains in Logical Reasoning: On Natural Language Inference (NLI) tasks, CEIL delivered absolute accuracy improvements of over 20% compared to learning-free retrieval methods.
- Compositional Mastery: In semantic parsing tasks (translating text into code or logic), CEIL demonstrated a superior ability to "compose" different examples to solve complex queries, particularly shining on the challenging SMCalFlow-CS benchmark.
- High Transferability: A fascinating insight is that a CEIL retriever trained using a relatively small model (GPT-Neo 2.7B) transfers remarkably well to massive models like Codex (175B). This suggests that the properties defining a "good example set" are somewhat universal across different LLM architectures.
- Efficiency Through Compactness: CEIL is so effective at curating informative subsets that it achieves high performance with significantly fewer exemplars. For example, CEIL using just 4 examples can outperform standard retrievers using 32, saving substantial compute and token costs.
Limitations and Future Directions
While CEIL represents a major step forward for prompt engineering, it currently requires task-specific training; a retriever must be trained individually for each new task. Additionally, generating the training data involves running an LLM over many different subsets to obtain preference scores, which incurs a high offline computational cost.
Looking ahead, the authors propose moving toward multitask-tuning. By training on a diverse mixture of tasks, future iterations of CEIL could yield a single, unified retriever capable of selecting optimal exemplars for entirely unseen tasks without requiring further task-specific training.
Summary updated