Language models learn a task from a handful of worked examples placed in the prompt. Choosing those examples by semantic similarity to the question helps a great deal. Packing many of them into one long prompt does not: the model's attention spreads thin, and one misleading example can derail the whole answer. We propose a different arrangement. Each retrieved example is paired with the question in its own short, separate prompt. The model runs all of these prompts side by side, and at every generated token their next-token predictions are combined into one choice that is appended to every path. The combination weights are not fixed. Each path's weight rises or falls according to how well that path has predicted the tokens actually chosen so far. A demonstration that pulls the model toward an irrelevant entity or a wrong method should therefore lose influence within a few tokens rather than corrupting the full answer.
A single tempering exponent $\lambda$ controls this weighting. It interpolates between the two classic ways of ensembling sequence models. At $\lambda=0$, predictions are averaged afresh at every step ("product-of-expectations"). At $\lambda=1$, whole-sequence probabilities are averaged, which is an exact Bayesian mixture over paths ("expectation-of-products"). We conjecture that intermediate $\lambda$ is what makes retrieval-based prompting robust when the example pool contains distracting material. If so, this would also explain a tension in the literature: max-style selection beats averaging for demonstration ensembles on classification, while step-wise averaging beats selection for free-form generation.
Core Claim
Let $d_1,\dots,d_k$ be the top-$k$ retrieved demonstrations for query $x$, plus an optional demonstration-free path $d_0$. Let $p_i(\cdot \mid y_{<t})$ be the model's next-token distribution under prompt $(d_i, x)$ after the shared prefix $y_{<t}$. We decode from
$$ q_t(v) = \sum_{i} w_{i,t}\, p_i(v \mid y_{<t}), \qquad w_{i,t} \propto \pi_i \prod_{s<t} p_i(y_s \mid y_{<s})^{\lambda}, $$
where $\pi_i$ is a prior weight (uniform, or a softmax of query–demonstration cosine similarity) and $\lambda \ge 0$ is the tempering exponent. At $\lambda=1$, $q_t$ is exactly the next-token distribution of the sequence-level mixture $\sum_i \pi_i \prod_t p_i(y_t \mid y_{<t})$. At $\lambda=0$ it is fixed token-level averaging. As $\lambda\to\infty$ it approaches committing to the single best-scoring path, the decoding analogue of max ensembling.
The claim has two parts. Under clean retrieval pools, all settings perform similarly and beat concatenation. Under contaminated pools, accuracy is unimodal in $\lambda$ with an interior maximum, and the running weights $w_{i,t}$ identify contaminated demonstrations without any separate relevance model. Each extreme has a predictable failure. At $\lambda=0$, distractor paths keep voting at every step. At large $\lambda$, the mixture commits early to whichever path happened to predict the first few formatting tokens best, which reproduces the snowballing errors that token-level ensembling was meant to avoid.
Relation to Prior Work
Three papers already split demonstrations into independent passes and pool the results, but all of them pool class-label probabilities once at the end. DENSE partitions demonstrations into buckets and combines label distributions with product, mixture, or similarity-weighted max operators. NBCE merges window log-probabilities under a naive-Bayes assumption with entropy-based pooling, and its authors note that this assumption limits it on sequential reasoning. Parallel Ensemble takes a weighted sum of label logits. These papers motivate the isolation idea. They do not synchronize tokens during generation, they do not test noisy pools, and they treat the choice among operators as a menu rather than a single continuum.
Parallel Context Windows instead masks attention across windows within one forward pass. Yang et al. show that this degrades chain-of-thought on HotpotQA, attributing much of the damage to reused position indices. That finding constrains our design. Our paths are ordinary, correctly positioned prompts that share only the generated continuation. Whether this sidesteps the chain-of-thought deterioration is one of our tests, not an assumption.
The fusion mechanics come from token-level ensembling. Integrative Decoding sums logits across parallel paths seeded by the model's own sampled drafts. Test-time augmentation averages over paraphrased inputs. EVA and GAC fuse heterogeneous models. All four use fixed, equal-weight fusion, and their paths carry no external, possibly adversarial evidence. Our paths are conditioned on retrieved external demonstrations of uneven quality, which is why fixed weights become the problem.
Malinin and Gales supply the conceptual split between product-of-expectations and expectation-of-products and show token-level disagreement detects anomalous inputs. We reuse that split as the endpoints of $\lambda$ and test whether path disagreement detects bad demonstrations. HARP triggers extra passes from next-token entropy but perturbs a single context rather than weighting external ones.
On the noise side, Wang et al. show that coherent irrelevant insertions cut accuracy by roughly 45% and that "ignore irrelevant text" instructions fail. Zhou et al. and Elazar et al. document that more concatenated demonstrations can hurt. These motivate the regime. Distraction-aware answer selection and Superposition Prompting prune or rescore whole documents before or after generation, which we treat as competitors.
Research Program
We first build the decoder. The $k+1$ prompts are prefilled once as a batch, so each path's key-value cache is computed a single time. After each fused token is chosen, it is appended to all paths. The per-token cost is therefore a batch of $k+1$ short sequences rather than one long one, and we report processed tokens and wall-clock time for every method.
We then build contaminated retrieval pools. For GSM8K and CommonsenseQA with written-out rationales, the pool is the training split. Contamination comes in two kinds, inserted at rates of 0%, 25%, 50%, and 75% among the retrieved top-$k$. The first kind is near-duplicate demonstrations with plausible but wrong rationales. The second is clean demonstrations padded with semantically coherent irrelevant text, generated in the style of Wang et al.'s perturbations. For HotpotQA we use demonstrations with chain-of-thought, following Yang et al.'s setup, and the same contamination.
Models are Llama-3.1-8B and a roughly 70B open model, so that results can be compared against the Llama-scale numbers in the file. We sweep $\lambda \in \{0, 0.1, 0.3, 0.5, 1, 3\}$ with $k \in \{4, 8, 16\}$. Two side variants are tested: uniform versus similarity-based priors $\pi_i$, and including versus excluding the demonstration-free path $d_0$, which acts as an anchor when most demonstrations are bad. $\lambda$ is tuned on a held-out development split per task and then frozen.
Baselines
The naive reference points are zero-shot prompting and SBERT top-$k$ retrieval concatenated into one prompt with greedy decoding, in the style of LM-BFF. Concatenation uses the same retrieved set, with $k$ tuned separately. This last point matters because concatenation's best $k$ may be small.
The strongest existing demonstration ensemble is DENSE weighted max. Since DENSE only pools labels, we adapt it to generation: each bucket generates a full answer, and the answer with the highest similarity-weighted sequence likelihood is selected. DENSE reports a 2.4-point average gain over concatenation with GPT-J in 6-shot classification. On HotpotQA, the reference is Yang et al.'s sequential 18-shot chain-of-thought result of 35.8 EM for LLaMA-33B, against 32.5 EM under PCW. We rerun both the sequential and parallel settings on our models rather than quoting across model families. For GSM8K with retrieved demonstrations, no reported result was found on Lacuna. The nearest figure is EVA's 42.91 exact match from a four-model ensemble, which is a different setting.
The strongest decoding-side competitors are self-consistency majority voting and Integrative Decoding, which reports +11.2% on TruthfulQA. Both run with the same number of parallel sequences, the same demonstration prompt (concatenated top-$k$), and a matched token budget. We also run NBCE's pooling operator applied step-wise, which tests whether its prior subtraction substitutes for adaptive weights. Finally, we run a pre-filter baseline: top-$k$ demonstrations are rescored by query likelihood in the manner of Cho et al., or by an LLM relevance judgment, and the survivors are then concatenated.
The key ablation is the $\lambda$ sweep itself. $\lambda=0$ is isolation plus fixed fusion, so the gap between the best $\lambda$ and $\lambda=0$ isolates the contribution of adaptive weighting. The gap between $\lambda=0$ and concatenation isolates the contribution of isolation. Beating the field means two things. Under 50% contamination, the best fixed $\lambda$ must exceed both the best-tuned concatenation and the pre-filter baseline by at least three points at matched compute. And it must not fall more than one point below them on clean pools.
Why not just…?
Why not just concatenate the top one or two demonstrations? On clean pools this is a real threat. Few, highly similar demonstrations avoid attention dilution, and Margatina et al. show that similarity selection alone carries most of the gain. Its weakness is that a contaminated top-1 is a single point of failure. The contamination sweep measures exactly this. If tuned small-$k$ concatenation matches our method under 50% contamination, the core claim is wrong.
Why not filter bad demonstrations before generating? Pre-filtering with query-likelihood scores or a relevance judge is cheaper and is our strongest competitor in spirit. The open question is whether a demonstration's harm can be seen before generation. A rationale with a plausible but wrong method may score as highly relevant. We run the filter as a baseline and as a front end to our decoder. We also report how well each signal (filter score versus final path weight $w_{i,T}$) separates contaminated from clean demonstrations, measured as the area under the ROC curve.
Why not ordinary self-consistency? Voting needs a short, closed answer and cannot correct a path mid-reasoning. Integrative Decoding and EVA both report gains from token-level fusion over sequence-level selection. More importantly, every sample in self-consistency sees the same distracted prompt, so votes are correlated in exactly the failure mode we target. Matched-budget runs settle this directly.
Why not Parallel Context Windows? Yang et al. already show it harms multi-hop chain-of-thought, and a simpler parallel ensemble beats it on classification. We include it on HotpotQA only to check whether our correctly positioned paths avoid that loss.
Decisive Checks
Three results would establish the claim. First, under contamination, accuracy as a function of $\lambda$ peaks strictly between 0 and 1 on at least two of the three tasks. Second, the ordering of $\lambda=0$ versus $\lambda=1$ reverses between clean and heavily contaminated pools, which would explain the averaging-versus-max tension at a single knob. Third, final path weights flag contaminated demonstrations with clearly higher ROC-AUC than the pre-filter scores.
Two outcomes would count against it. If performance is flat in $\lambda$, adaptive weighting is unnecessary and the result reduces to an extension of fixed token-level fusion to demonstrations. If the method collapses whenever contaminated paths are the majority even with the $d_0$ anchor, then consensus reinforcement limits it, and we will report that breakdown point explicitly.
References
- Exploring Demonstration Ensembling for In-context Learning
- Naive Bayes-based Context Extension for Large Language Models
- Revisiting Parallel Context Windows: A Frustratingly Simple Alternative and Chain-of-Thought Deterioration
- Parallel Context Windows for Large Language Models
- Integrative Decoding: Improving Factuality via Implicit Self-consistency
- Efficient Test-Time Scaling for Small Vision-Language Models
- Bridging the Gap between Different Vocabularies for LLM Ensemble
- Breaking the Ceiling of the LLM Community by Treating Token Generation as a Classification for Ensembling
- Uncertainty in Structured Prediction.
- HARP: Hesitation-Aware Reframing in Transformer Inference Pass
- Breaking Focus: Contextual Distraction Curse in Large Language Models
- RiOT: Efficient Prompt Refinement with Residual Optimization Tree
- Measuring and Improving Attentiveness to Partial Inputs with Counterfactuals
- Improving Zero-shot Reader by Reducing Distractions from Irrelevant Documents in Open-Domain Question Answering
- Superposition Prompting: Improving and Accelerating Retrieval-Augmented Generation
- Making Pre-trained Language Models Better Few-shot Learners
- Active Learning Principles for In-Context Learning with Large Language Models