Papers
Topics
Authors
Recent
Search
2000 character limit reached

Local Perplexity Ranking for Robust LLM Inference

Updated 17 April 2026
  • Local Perplexity Ranking is an in-context denoising strategy that replaces noisy candidate demonstrations with lower-perplexity, semantically similar examples.
  • It decomposes sequence perplexity into inherent and matching components to effectively identify label mismatches in text generation tasks.
  • Empirical evaluations show significant performance gains on benchmarks like SCIQ while offering efficiency improvements over global ranking methods.

Local Perplexity Ranking (LPR) is an in-context denoising strategy for LLM inference that improves robustness to noisy demonstrations in text generation tasks. LPR systematically replaces candidate demonstrations that are likely mislabeled with semantically similar neighbors exhibiting lower perplexity, thereby reducing the prevalence of mismatched input–output pairs in prompt construction. This approach is grounded in a local decomposition of perplexity into inherent and matching components, utilizes semantic neighborhood retrieval, and achieves significant empirical gains on a range of noisy text generation benchmarks (Gao et al., 2024).

1. Perplexity Decomposition and Motivation

In the context of sequence modeling, LPR adopts the standard sequence perplexity definition for a concatenated input–output pair z=(x,y)\bm{z} = (\bm{x}, \bm{y}) with z|\bm{z}| tokens under model pθp_\theta: Perplexity(z)=exp(1zi=1zlogpθ(ziz<i)).\mathrm{Perplexity}(\bm{z}) = \exp\left( -\frac{1}{|\bm{z}|} \sum_{i=1}^{|\bm{z}|} \log p_\theta(z_i \mid z_{<i}) \right). Empirically, Perplexity(z)\mathrm{Perplexity}(\bm{z}) is elevated for demonstrations containing incorrect (noisy) output y~\tilde y for input x\bm{x}. To explain the informativeness of this signal, perplexity is conceptually decomposed as

Perplexity=Inherent Perplexity+Matching Perplexity,\mathrm{Perplexity} = \mathrm{Inherent~Perplexity} + \mathrm{Matching~Perplexity},

where the inherent component captures the base “difficulty” of a given input–output pair (approximately constant for semantically similar queries), and the matching component reflects the penalty for label–input mismatch. Local comparison within semantic neighborhoods thus enables the detection of anomalously high perplexity that is specifically attributable to noisy labels.

2. LPR Algorithm: Formal Procedure

Given a test input xtest\bm{x}_{\text{test}}, a noisy candidate pool C~={(xj,y~j)}j=1M\widetilde{\bm{C}} = \{(\bm{x}_j, \tilde y_j)\}_{j=1}^M, and a base retrieval strategy z|\bm{z}|0 (e.g., Random, TopK by similarity, DPP for diversity), LPR augments selection as follows:

  1. Select initial z|\bm{z}|1 candidates z|\bm{z}|2.
  2. For every candidate z|\bm{z}|3, compute the text embedding z|\bm{z}|4 and sequence perplexity.
  3. For each z|\bm{z}|5 in z|\bm{z}|6:
    • Compute cosine similarity to all other candidates.
    • Identify the z|\bm{z}|7 nearest neighbors z|\bm{z}|8 in embedding space (excluding z|\bm{z}|9).
    • Form a local cluster pθp_\theta0.
    • Sort pθp_\theta1 by perplexity, resulting in ranking pθp_\theta2 for each member.
    • If the normalized rank pθp_\theta3 (candidate is among the bottom pθp_\theta4 fraction by perplexity), replace pθp_\theta5 with the top neighbor pθp_\theta6 among pθp_\theta7 for which pθp_\theta8.
  4. Return the cleaned demonstration set pθp_\theta9.

Default hyperparameters are Perplexity(z)=exp(1zi=1zlogpθ(ziz<i)).\mathrm{Perplexity}(\bm{z}) = \exp\left( -\frac{1}{|\bm{z}|} \sum_{i=1}^{|\bm{z}|} \log p_\theta(z_i \mid z_{<i}) \right).0 and Perplexity(z)=exp(1zi=1zlogpθ(ziz<i)).\mathrm{Perplexity}(\bm{z}) = \exp\left( -\frac{1}{|\bm{z}|} \sum_{i=1}^{|\bm{z}|} \log p_\theta(z_i \mid z_{<i}) \right).1, i.e., bottom 50% is eligible for replacement.

3. Semantic Similarity and Neighbor Retrieval

LPR relies on semantic clustering in the joint input–output space. Each example Perplexity(z)=exp(1zi=1zlogpθ(ziz<i)).\mathrm{Perplexity}(\bm{z}) = \exp\left( -\frac{1}{|\bm{z}|} \sum_{i=1}^{|\bm{z}|} \log p_\theta(z_i \mid z_{<i}) \right).2 is mapped to a fixed-size text embedding Perplexity(z)=exp(1zi=1zlogpθ(ziz<i)).\mathrm{Perplexity}(\bm{z}) = \exp\left( -\frac{1}{|\bm{z}|} \sum_{i=1}^{|\bm{z}|} \log p_\theta(z_i \mid z_{<i}) \right).3 via a sentence encoder (BERT-base in the implementation; SBERT-compatible). The cosine similarity metric,

Perplexity(z)=exp(1zi=1zlogpθ(ziz<i)).\mathrm{Perplexity}(\bm{z}) = \exp\left( -\frac{1}{|\bm{z}|} \sum_{i=1}^{|\bm{z}|} \log p_\theta(z_i \mid z_{<i}) \right).4

is used to compute nearest neighbors. LPR performs ranking and substitution exclusively among the local semantic cluster, facilitating effective denoising without altering the global distributional properties of retrieved demonstrations.

4. Hyperparameters, Selection, and Ranking Criteria

The main parameters for LPR are the neighborhood size Perplexity(z)=exp(1zi=1zlogpθ(ziz<i)).\mathrm{Perplexity}(\bm{z}) = \exp\left( -\frac{1}{|\bm{z}|} \sum_{i=1}^{|\bm{z}|} \log p_\theta(z_i \mid z_{<i}) \right).5 and replacement threshold Perplexity(z)=exp(1zi=1zlogpθ(ziz<i)).\mathrm{Perplexity}(\bm{z}) = \exp\left( -\frac{1}{|\bm{z}|} \sum_{i=1}^{|\bm{z}|} \log p_\theta(z_i \mid z_{<i}) \right).6. Within each cluster of Perplexity(z)=exp(1zi=1zlogpθ(ziz<i)).\mathrm{Perplexity}(\bm{z}) = \exp\left( -\frac{1}{|\bm{z}|} \sum_{i=1}^{|\bm{z}|} \log p_\theta(z_i \mid z_{<i}) \right).7 elements, demonstrations are ranked by ascending perplexity; the relative position (normalized rank) determines replacement eligibility. The clustering and ranking are independent of the specific choice of initial retrieval method, and cached computations enable efficient scaling over candidate pools.

Hyperparameter Default Value Functional Role
Perplexity(z)=exp(1zi=1zlogpθ(ziz<i)).\mathrm{Perplexity}(\bm{z}) = \exp\left( -\frac{1}{|\bm{z}|} \sum_{i=1}^{|\bm{z}|} \log p_\theta(z_i \mid z_{<i}) \right).8 4 Size of local neighbor set
Perplexity(z)=exp(1zi=1zlogpθ(ziz<i)).\mathrm{Perplexity}(\bm{z}) = \exp\left( -\frac{1}{|\bm{z}|} \sum_{i=1}^{|\bm{z}|} \log p_\theta(z_i \mid z_{<i}) \right).9 0.5 Replacement threshold (bottom fraction)
Encoder BERT-base-uncased Semantic retrieval in Perplexity(z)\mathrm{Perplexity}(\bm{z})0
Retrieval (e.g.) TopK, DPP Base method for initial candidate selection

5. Experimental Protocol and Evaluation

LPR was evaluated on six prominent text generation datasets: NQ (Natural Questions), WebQ (WebQuestions), SQuAD (reading comprehension), SCIQ (science question answering), GeoQuery (SQL code generation), NL2Bash (shell command generation). Noise was injected during training using two regimes:

  • Irrelevant Noise: With probability Perplexity(z)\mathrm{Perplexity}(\bm{z})1, replace the gold answer with a random answer from another instance.
  • Relevant Noise: With probability Perplexity(z)\mathrm{Perplexity}(\bm{z})2, substitute the correct answer with a contextually plausible but incorrect response generated by ChatGPT-4. Noise rates Perplexity(z)\mathrm{Perplexity}(\bm{z})3 were considered.

Experiments utilized greedy and nucleus sampling from the Llama2-7B LLM, with additional evaluations on Llama2-13B, Mistral-7B, and OPT-6.7B. Baselines included Random, standard TopK (cosine similarity on input embeddings), and DPP. Evaluation metrics were Exact Match (EM) for question answering and BLEU for code generation, using bert-base-uncased for retrieval embedding.

6. Quantitative Results and Ablation Studies

LPR demonstrates substantial empirical benefit over baseline retrieval methods under noisy annotation conditions. For example, on SCIQ with 60% irrelevant noise, the TopK baseline yields 29.31% EM versus 48.06% EM for TopK+LPR—an 18.75 percentage-point improvement. Across datasets, LPR consistently delivers Perplexity(z)\mathrm{Perplexity}(\bm{z})4–Perplexity(z)\mathrm{Perplexity}(\bm{z})5 EM gain in high-noise settings.

Ablation on the replacement threshold Perplexity(z)\mathrm{Perplexity}(\bm{z})6 (averaged at 60% noise) found:

  • Perplexity(z)\mathrm{Perplexity}(\bm{z})7: +14.2 EM
  • Perplexity(z)\mathrm{Perplexity}(\bm{z})8: +13.8 EM (default)
  • Perplexity(z)\mathrm{Perplexity}(\bm{z})9: +12.9 EM

Ablation on neighbor count y~\tilde y0:

  • y~\tilde y1: +11.5 EM
  • y~\tilde y2: +13.8 EM (default)
  • y~\tilde y3: +14.0 EM

Comparison with Global Perplexity Ranking (selecting globally lowest-perplexity demonstrations from 100 candidates) shows LPR performs better in clean and low-noise regimes and is approximately y~\tilde y4 faster due to the locality of comparisons. Transfer experiments with Llama2-13B, Mistral-7B, and OPT-6.7B yield consistent gains of y~\tilde y5–y~\tilde y6 EM on 60% noise. LPR also recovers y~\tilde y7–y~\tilde y8 accuracy on text classification tasks (SST-2, AGNews) with label noise, relative to TopK/DPP.

7. Theoretical Insights, Constraints, and Potential Extensions

The principal insight behind LPR is that while noisy labels inflate perplexity, absolute perplexity conflates example difficulty and noise. By restricting comparison to a neighborhood of semantically similar examples—where inherent perplexity is approximately constant—deviations in perplexity more precisely flag label mismatches. Local replacement thus eliminates poor demonstrations while retaining semantic diversity.

Limitations include the assumption that most examples within each semantic neighborhood are correctly labeled; performance degrades as local noise rates exceed 80%. LPR’s empirical effectiveness is not accompanied by a formal theoretical guarantee. Computational overhead is moderate, since most LLM and embedding computations can be cached.

Extensions proposed include adaptive y~\tilde y9 (thresholding based on perplexity gap), soft denoising via weighted neighbor voting, incorporation of alternative “matching” signals such as textual entailment, and theoretical analysis linking matching perplexity to the in-context log-prob gradient (Gao et al., 2024).

Definition Search Book Streamline Icon: https://streamlinehq.com
References (1)

Topic to Video (Beta)

No one has generated a video about this topic yet.

Whiteboard

No one has generated a whiteboard explanation for this topic yet.

Follow Topic

Get notified by email when new papers are published related to Local Perplexity Ranking (LPR).