Abstract
In-Context Learning (ICL) has emerged as a powerful paradigm for adapting Large Language Models (LLMs) to new tasks without parameter updates. However, the performance of ICL is highly sensitive to the specific examples provided in the prompt. This paper introduces Bayesian in-Context example Selection (ByCS), a novel framework that identifies high-quality examples by maximizing mutual information between the test input and candidate examples. By employing "inverse inference"—evaluating how well a test input can predict a candidate's label—ByCS identifies examples that are logically, rather than just superficially, relevant. Experimental results across text, speech, and visual modalities demonstrate that ByCS consistently outperforms standard retrieval methods, offering significant performance gains and robustness.
Introduction
Large Language Models (LLMs) exhibit a remarkable ability to perform tasks using only a few demonstrations provided in the prompt, a process known as In-Context Learning (ICL). Despite its success, ICL is notoriously brittle; the selection and ordering of examples can lead to drastic fluctuations in model performance. Traditional selection methods, such as $k$-Nearest Neighbors (kNN), rely on surface-level similarity in embedding spaces. These methods often fail to capture the complex, task-specific interactions between the test input and the provided examples.
This research addresses the selection problem by proposing ByCS (Bayesian in-Context example Selection). Instead of asking which examples "look like" the input, ByCS asks which examples share the most mutual information with the input. By leveraging Bayes’ theorem to perform inverse inference, the framework identifies examples that serve as the most effective "teachers" for the model's internal logic.
Methodology
The ByCS Framework
The core of ByCS is a three-step reranking process designed to flip the standard selection logic on its head:
- First-round Inference: The model performs an initial inference on the test input ($X$) to generate a preliminary prediction ($\hat{Y}$).
- Inverse Inference: The system treats the test pair $(X, \hat{Y})$ as the context. It then attempts to predict the label of a candidate example from the datastore. The underlying assumption is that if the test input is a good predictor for a candidate, that candidate will likely be a highly informative example for the test input during standard ICL.
- Score-based Reranking: Candidates are ranked based on the similarity between their predicted labels and their actual ground-truth labels. This similarity is measured using metrics such as the Jaccard coefficient or BERT embeddings.
Computational Optimizations
To ensure the method is scalable to large datasets and real-time applications, the authors introduced two primary optimizations:
- Model Scaling: The inverse inference step can be performed by a smaller, faster model (e.g., using Whisper-small to select examples for Whisper-large). This provides a high-quality selection signal at a fraction of the computational cost.
- Pre-selection: A fast, low-cost algorithm like kNN is used to narrow the initial datastore down to a manageable pool of candidates before the more intensive ByCS reranking is applied.
Experimental Setup
ByCS was evaluated across a diverse set of modalities to test its generalizability:
- Text: Tasks included topic classification (TREC), sentiment analysis (SST2), text-to-SQL generation (Spider), and ASR error correction (HyPoradise).
- Speech: The framework was tested on Automatic Speech Recognition (ASR) for Chinese dialects (RASC863) and African American Language (CORAAL).
- Vision: Visual Question Answering (OKVQA) was used to assess the method's ability to handle tasks requiring external knowledge combined with visual input.
Key Results and Discussion
Performance Gains
ByCS demonstrated superior performance across all tested modalities. In speech tasks, ByCS achieved a 10.25% relative reduction in Word Error Rate (WER) on the RASC863 Chinese dialect dataset compared to the KATE+ baseline. In text classification (TREC), ByCS reached 81.2% accuracy with GPT-3.5-Turbo using only a single example ($k=1$), significantly outperforming random selection (63.5%) and BM25 retrievers.
Cross-Modal Robustness
A significant finding is that the Bayesian logic remains effective regardless of the input type. Whether the model is processing audio snippets, SQL queries, or complex images, the principle of maximizing mutual information through inverse inference holds. In the OKVQA benchmark, ByCS consistently outperformed kNN-based selection when paired with advanced models like Emu2 and GPT-4V.
Efficiency and Model-Awareness
The research highlights that ByCS is "model-aware." Unlike embedding-based retrievers that are static, ByCS adapts to the specific logic of the model being used. Furthermore, the use of smaller models for selection proved highly efficient; using Whisper-small for inverse inference resulted in a 6x speedup with negligible loss in the quality of selected examples.
Limitations and Future Work
While ByCS represents a significant step forward, the authors noted several areas for improvement:
- Independence Assumption: The current framework evaluates each candidate example in isolation, ignoring potential synergies or redundancies between multiple examples in a $k$-shot prompt.
- Short-Answer Sensitivity: The reliance on text similarity for scoring means that tasks with very short, low-entropy labels (e.g., binary "Yes/No") provide a weaker signal for ranking, leading to more modest gains.
- Inference Overhead: Despite optimizations, ByCS requires more computation than simple vector lookups, which may be a factor in latency-sensitive environments.
Future research will focus on modeling the joint interactions between multiple in-context examples to further refine the selection process.
Conclusion
ByCS offers a robust, model-aware alternative to traditional example selection methods in ICL. By shifting the focus from surface similarity to mutual information via inverse inference, the framework significantly enhances the performance of LLMs across text, speech, and vision. This Bayesian approach provides a more principled way to navigate the brittleness of in-context learning, paving the way for more reliable and efficient few-shot adaptation.
Summary updated