TL;DR
Instead of just picking the most similar examples for few-shot learning, this paper proposes the Sparse Latent Basis Hypothesis: an effective subset of demonstrations should collectively "reconstruct" the target query's representation. By using a greedy algorithm called Residual Explanation Search (RES), the authors show that selecting for collective complementarity often outperforms standard diversity-based methods, though the "best" selection strategy depends heavily on the task and which layer of the model you use for embeddings.
What Problem Does This Paper Address?
In-context learning (ICL) is notoriously sensitive. If you give a Large Language Model (LLM) the wrong few-shot examples, or even the right examples in the wrong order, performance can crater.
Most researchers currently pick examples using Top-k similarity (find the most similar items) or Maximal Marginal Relevance (MMR) (find similar items that are also different from each other). However, these are "pairwise" heuristics. We still lack a principled understanding of what a subset of examples should provide collectively. Does the model need three versions of the same logic, or three different pieces of a puzzle? This paper moves beyond pairwise metrics to explore a subset-level property: collective reconstruction.
Methods
The authors introduce the Sparse Latent Basis Hypothesis. They posit that a query $q$ can be viewed as a combination of latent requirements, and a good set of exemplars $S$ should act as a "basis" that can linearly reconstruct that query: $q \approx \sum_{x_i \in S} \alpha_i x_i$.
To test this, they use Residual Explanation Search (RES), a diagnostic procedure based on the "Matching Pursuit" algorithm:
- Initialize: Start with the query vector as your "residual."
- Search: Find the exemplar that has the highest alignment (inner product) with the current residual.
- Update: Subtract the projection of that exemplar from the residual.
- Repeat: The next search now looks for an exemplar that explains the remaining part of the query that the first one missed.
They compare RES against BM25 (lexical), Top-k (semantic similarity), and MMR (diversity) across eight different open-weight LLMs (like Llama 3 and Qwen 2.5).
Datasets
The study evaluates performance across seven diverse benchmarks:
- Sentiment/Subjectivity: SST-2, SST-5, and SUBJ.
- Natural Language Inference: QNLI.
- Reasoning (Knowledge-intensive/Math): StrategyQA, AQUA, and MathQA.
Key Insights and Ideas
- Complementarity > Dissimilarity: RES outperformed MMR in 34 out of 56 model-dataset pairs. This suggests that picking examples that "fill in the gaps" of a reconstruction (complementarity) is a more effective signal than simply picking examples that are "different" from each other (dissimilarity).
- The "Surface Topic" Trap: In StrategyQA, all retrieval methods actually performed worse than zero-shot (no examples). Why? The authors found that the queries in StrategyQA often don't contain enough information to point toward the required external facts. Retrieval picks "semantically related" items (e.g., about Apollo missions) that don't actually contain the specific "missing link" needed to solve the logic.
- Layer Matters: The choice of representation space is critical.
- Middle layers of LLMs tend to be more "semantic," making them better suited for simple similarity retrieval (Top-k).
- Last layers are more "prediction-oriented." Interestingly, RES and MMR performed better when using these last-layer representations, suggesting that "diversity" and "residual explanation" are more useful when operating in a space closer to the model's final output.
- Templates Rule Math: For math-heavy tasks (AQUA, MathQA), Top-k and BM25 remained very strong. This is likely because these tasks rely on "reusable templates"—if you find one example with the same formula, you've already won, and "complementarity" adds little extra value.
Key Results
- Sentiment Wins: RES showed its clearest advantage on sentiment tasks (SST-2/5), where queries often have multiple varied cues (e.g., a review that is "action-packed" but "by-the-books"). RES picks examples that cover these different facets.
- Quantitative Edge: RES outperformed random selection in 49/56 pairs.
- Solution Reconstruction: The authors performed a "post-hoc" analysis where they tried to reconstruct the full solution (including reasoning) using the selected examples. They found a high correlation between how well a subset could reconstruct the solution and the actual ICL performance, validating the "latent basis" intuition.
Limitations and Future Work
- The Proxy Assumption: The method relies on the query representation being a good proxy for the task's requirements. As seen in StrategyQA, if the query is "vague" regarding the necessary knowledge, the whole approach struggles.
- Linearity: The authors assume that contextual influences are additive/linear in latent space. While this is a useful diagnostic, the actual mechanism by which LLMs process prompts is likely far more complex.
- Scale: The study focused on 5-shot learning with models up to 8B parameters. Whether these patterns hold for "many-shot" ICL (hundreds of examples) or frontier models (GPT-4, Claude 3) remains an open question.
The authors conclude that there is no "one size fits all" selector; instead, the best strategy is conditional on the task type and the specific representation space being used.
Summary updated