Abstract
In-Context Learning (ICL) has enabled Large Language Models (LLMs) to perform tasks with minimal examples. However, standard ICL approaches struggle with "extreme" classification tasks involving dozens or hundreds of labels, as the limited context window cannot accommodate examples for every class. This paper investigates a Retrieval-Augmented ICL pipeline that dynamically selects relevant examples to populate the prompt. By saturating the context window of off-the-shelf models like LLaMA-2, this method achieves state-of-the-art performance on complex intent classification benchmarks without requiring any fine-tuning.
Introduction
Large Language Models (LLMs) typically excel at few-shot learning by observing a small set of demonstrations within their prompt. While this works well for binary or low-cardinality tasks, it hits a "context wall" in many-label classification. For instance, in banking intent detection with 150 distinct categories, providing even one example per label would exceed the context limits of most current models, leaving no room for the query itself.
Historically, this limitation has forced practitioners to rely on smaller, specialized models fine-tuned on specific datasets. This research challenges that necessity, proposing that a "partial view" of the label space—curated by a retriever—is sufficient for large-scale LLMs to outperform specialized, fine-tuned baselines.
Methodology: Retrieval-Augmented ICL
The authors propose a zero-training pipeline designed to maximize the utility of the LLM's context window. The process consists of five key stages:
- Retrieval: For every incoming query, a pre-trained Sentence-BERT (SBERT) model searches a pool of labeled data to identify the $M$ most semantically similar examples.
- Prompt Saturation: Rather than limiting the prompt to a fixed number of shots (e.g., 5 or 10), the authors "saturate" the context window. They include as many retrieved examples as the model’s limit allows—up to approximately 140 examples for LLaMA-2.
- Least-to-Most (LTM) Ordering: The order of examples in the prompt significantly impacts performance. The study found that placing the most relevant examples closest to the query (at the end of the prompt) yields the best results.
- Inference: The saturated prompt is passed to an off-the-shelf LLM. The study evaluated various models, including the LLaMA and OPT families, ranging from 7B to 175B parameters.
- Label Mapping: To ensure the model remains within the valid label space, a final post-processing step uses the retriever to map the model's generated text to the nearest valid class name.
Experimental Results
The method was evaluated on four challenging benchmarks: BANKING77 (77 classes), HWU64 (64 classes), CLINC150 (150 classes), and GoEmotions (fine-grained sentiment).
Performance Benchmarks
- New State-of-the-Art: LLaMA-2 70B, using the retrieval-augmented ICL approach, set new records across all three intent classification datasets. Notably, it achieved 98.18% accuracy on CLINC150 in a 10-shot setting.
- Outperforming Fine-tuning: On the BANKING77 dataset, this zero-training approach outperformed a fine-tuned DeBERTa-v2-XXLarge by approximately 7.5% in 5-shot scenarios.
- Generalization: The success on the GoEmotions dataset demonstrates that the approach is effective for general text classification beyond intent detection.
Key Insights
The Scaling Law of Context
A critical finding of the research is that the ability to utilize a saturated context window scales with model size. Smaller models (e.g., 7B parameters) often experience performance degradation or plateaus as more examples are added. In contrast, larger models (70B parameters) show a consistent "more is better" trend, effectively processing the full 4K context window to improve accuracy.
The Role of Input-Label Mapping
Contrary to some theories suggesting LLMs only use ICL to recognize the task type, this study proves that the specific input-label correspondences are vital. In ablation studies where labels were shuffled (paired with incorrect examples), performance dropped significantly. This confirms that the model is actively learning the nuances of the many-label space from the provided examples.
Semantic Importance
The research highlights that LLMs rely heavily on their internal knowledge of label names. Obfuscating labels (e.g., replacing "Card Arrival" with "Class 1") leads to a significant drop in performance, particularly in sentiment analysis tasks where the semantic meaning of the emotion is central to the classification.
Limitations and Conclusion
While highly effective, the approach has trade-offs. The primary challenge is the inference cost; running a 70B parameter model for every query is significantly more resource-intensive than using a small, fine-tuned BERT-based model. Additionally, the system struggles with the "neutral" class in sentiment analysis, as retrievers often find it difficult to distinguish neutral statements from specific emotional ones.
In conclusion, retrieval-augmented ICL provides a powerful, training-free alternative for complex classification. By dynamically selecting examples and saturating the context window, off-the-shelf LLMs can overcome the "context wall" and surpass the performance of specialized, fine-tuned models in many-label environments.
Summary updated