TL;DR
Rather than concatenating all few-shot demonstrations into a single long prompt, Demonstration Ensembling (DENSE) splits examples into smaller subsets ("buckets") and ensembles their predictions. Using similarity-weighted max ensembling, DENSE outperforms standard prompt concatenation on GPT-J by an average of 3.8 points while mitigating context length limits and prompt-order sensitivity.
What Problem Does This Paper Address?
In standard in-context learning (ICL), few-shot demonstrations are chained sequentially into an autoregressive prompt before the query input. This simple approach has three significant pain points:
- No control over example contributions: The model relies purely on its internal attention mechanisms to weight demonstrations, meaning irrelevant or noisy examples can negatively skew predictions.
- Context window bottlenecks: Transformers have fixed context limits. Concatenating many examples (or long-input tasks) quickly exhausts context capacity.
- Severe order sensitivity: LLM predictions are notoriously vulnerable to demonstration ordering, and longer chains of concatenated examples exacerbate this instability.
Methods
The authors propose Demonstration Ensembling (DENSE):
- Bucket Allocation: Partition $n$ demonstrations into $b$ non-empty buckets $\{B_0, \dots, B_{b-1}\}$. The paper tests:
- Sequential allocation (based on initial order).
- Similar-together allocation (using $k$-means clustering on sentence embeddings so each bucket is a semantically coherent group).
- Diverse allocation (using constrained $k$-means to ensure each bucket draws a distinct example from diverse clusters).
- Inference per Bucket: Run the language model separately on each bucket conditioned on the test query $x$ to get per-bucket predicted probabilities $\tilde{p}_i(y|x) = P_{\text{LM}}(y|B_i, x)$.
- Bucket Weighting: Compute normalized importance weights $w_i$ based on the average cosine similarity between a bucket’s examples and the test query $x$ (using embeddings from a fine-tuned MiniLM).
- Aggregation Functions ($\Phi$): Combine predictions using one of three operators:
- Product-of-Experts (PoE): $\prod \tilde{p}_i(y|x)^{w_i}$
- Mixture-of-Experts (MoE): $\sum w_i \tilde{p}_i(y|x)$
- Max Ensembling: $\max_j w_j \tilde{p}_j(y|x)$ (selecting the most confident weighted bucket prediction).
Datasets
The authors evaluated on 7 NLP tasks spanning classification, NLI, and question answering (no new benchmarks were introduced):
- Glue-SST2: Sentiment analysis (Macro F1)
- Medical Questions Pairs: Paraphrase detection (Macro F1)
- Climate Fever: Fact verification (Macro F1)
- SICK: Natural Language Inference (Macro F1)
- Hate speech18: Hate speech detection (Macro F1)
- TweetEval-stance (feminism): Stance detection (Macro F1)
- OpenBookQA: Question answering (Accuracy)
Key Insights and Ideas
- Max pooling beats averaging and multiplying: Max ensembling consistently outperformed both Mixture-of-Experts and Product-of-Experts. Instead of averaging uncertain predictions across buckets, picking the single most confident, similarity-weighted bucket prediction yielded the cleanest signal.
- Smaller buckets can scale better: For max ensembling, performance generally increased as bucket count $b$ increased (i.e., fewer demonstrations per bucket, down to 1 demo per bucket).
- Input similarity weighting is critical: Weighting buckets by their semantic similarity to the test input provided a noticeable performance jump across all ensembling techniques.
- Diversity helps when data scales: Clustering demonstrations showed mixed results overall, but in the 10-shot setting, constructing diverse buckets consistently beat grouping similar demonstrations together.
Key Results
- Max Ensembling vs. Concatenation:
- Unweighted max ensembling beat standard concatenation by 0.8 points on average.
- Adding similarity-based bucket weighting boosted max ensembling to outperform concatenation by an average of 3.8 points across all 7 tasks.
- Averaging/Product operators: Weighted MoE and PoE also outperformed standard concatenation, but trailed max ensembling.
- Order Invariance: Clustering-based allocation naturally eliminates prompt order sensitivity, as bucket allocation becomes invariant to the original demonstration order.
Limitations and Future Work
- Evaluation scale: Experiments were conducted using a single model family/size (GPT-J 6B) and evaluated at relatively small demonstration sizes ($n = 6$ and $n = 10$). Validation on larger modern LLMs (e.g., LLaMA, GPT-4) and higher shot counts is left for future work.
- Clustering gains were mixed: Structuring buckets with $k$-means clustering did not yield significant performance gains over random/sequential partitioning in lower-shot settings.
- Inference overhead: Splitting demonstrations into $b$ separate queries increases the number of forward passes by a factor of $b$, introducing computational trade-offs (though each individual prompt is shorter and runs can be parallelized).
Summary updated