In-Context Learning (ICL) allows Large Language Models (LLMs) to solve new tasks simply by providing a few examples in the prompt. However, LLMs are notoriously "picky": choosing the wrong examples can lead to a massive drop in accuracy. This paper introduces Example Gisting, a method to train specialized encoders that compress task-specific information into a few "gist tokens" via an attention bottleneck. By using these compressed representations to score and select examples (GistScore), the authors achieve state-of-the-art ICL performance—beating standard retrievers by 20% and specialized methods by 5%—while running up to 1,000 times faster than the strongest training-free baselines.
The Example Selection Problem
Currently, researchers usually select examples using one of two sub-optimal ways:
- Off-the-shelf retrievers (like BM25 or SBERT): These are fast but look for surface-level keyword overlap or general semantic similarity, often missing the specific "logic" or "reasoning pattern" required for a task.
- LLM-in-the-loop methods: These use the LLM itself to score examples. While accurate, they are computationally expensive, slow, and often require training a new retriever for every single task.
The authors identify a "missing middle": the need for a retriever that understands task-specific "salience" (what actually matters for the task) but remains fast enough for real-time inference.
Methods: Example Gisting and GistScore
The authors propose Example Gisting, which utilizes an attention bottleneck to compress task knowledge.
- The Bottleneck: They take an encoder-decoder model (like Flan-T5) and insert a small number of special "gist tokens" between the input and the output. During training, the model is forced to predict the output while only being allowed to "look" at the input through these gist tokens. This forces the gist tokens to act as a highly compressed "summary" of the task-relevant features.
- GistScore: Once trained, the encoder produces gist token embeddings for both the test input and all candidate examples. The GistScore is a metric that calculates the similarity between these compressed embeddings to find the most relevant examples.
- Two Flavors:
- GS[F] (Finetuned): A model finetuned on a specific dataset.
- GS[M] (Multi-task): A single model trained on a massive collection of tasks (FLAN-2022) that can generalize to entirely new, unseen tasks out-of-the-box.
Key Insights
- Bottlenecks are Feature Extractors: By restricting information flow, the model is forced to discard "noise" (like specific names or dates) and keep "signal" (like the fact that a sentence is a contradiction or a question is about a date).
- One Token is Often Enough: For many classification tasks, a single gist token captures enough information to select perfect examples. However, for complex tasks like Semantic Parsing, using more gist tokens (up to 15) significantly improves performance because the "salient features" are more structural and complex.
- Selection Precision is King: For classification, the primary driver of ICL success is "selection precision"—picking examples that have the same label as the test input. GistScore is exceptionally good at implicitly "guessing" the label of the test input to find matching examples.
- Generalization to the Unseen: The multi-task model (GS[M]) successfully selected high-quality examples for tasks it was never trained on, outperforming off-the-shelf retrievers.
Key Results
The researchers evaluated their approach across 21 datasets spanning 9 diverse categories (including NLI, Paraphrase Detection, Question Answering, and Semantic Parsing). They found:
- Accuracy Gains: The finetuned GistScore (GS[F]) achieved a 20% absolute gain over SBERT and a 5% gain over the previous best-in-class methods (like CEIL or EPR).
- Massive Speedup: Compared to BSR (BERTScore-Recall), which is the strongest training-free baseline, GistScore is three orders of magnitude faster. It can score thousands of examples in milliseconds because it only compares a few gist tokens rather than every token in a long text.
- Cross-LLM Compatibility: While the gist models were trained using Flan-T5, the examples they selected improved the performance of 8 different "inference" LLMs, including LLaMA, Mistral, and GPT-Neo.
Limitations and Future Work
- The "Label Bias" Artifact: In classification tasks, the model's success is heavily tied to picking examples with the same label. It remains an open question whether ICL can be improved further by selecting examples that are "informative" beyond just having the correct label.
- Training Data Dependency: While the multi-task model generalizes well, its performance is still bounded by the diversity of the FLAN-2022 collection.
- Future Directions: The authors suggest applying "gisting" to Retrieval-Augmented Generation (RAG), where the bottleneck could help retrieve more relevant documents for long-form generation tasks.
Summary updated