Dynamic Uncertainty Ranking: Enhancing In-Context Learning for Long-Tail Knowledge in LLMs

Shuyang Yu, Runxue Bao, Parminder Bhatia, Taha A. Kass-Hout, Jiayu Zhou, Cao Xiao

Abstract: Large language models (LLMs) can learn vast amounts of knowledge from diverse domains during pre-training. However, long-tail knowledge from specialized domains is often scarce and underrepresented, rarely appearing in the models' memorization. Prior work has shown that in-context learning (ICL) with retriever augmentation can help LLMs better capture long-tail knowledge, reducing their reliance on pre-trained data. Despite these advances, we observe that LLM predictions for long-tail questions remain uncertain to variations in retrieved samples. To take advantage of the uncertainty in ICL for guiding LLM predictions toward correct answers on long-tail samples, we propose a reinforcement learning-based dynamic uncertainty ranking method for ICL that accounts for the varying impact of each retrieved sample on LLM predictions. Our approach prioritizes more informative and stable samples while demoting misleading ones, updating rankings based on the feedback from the LLM w.r.t. each retrieved sample. To enhance training efficiency and reduce query costs, we introduce a learnable dynamic ranking threshold, adjusted when the model encounters negative prediction shifts. Experimental results on various question-answering datasets from different domains show that our method outperforms the best baseline by $2.76\%$, with a notable $5.96\%$ boost in accuracy on long-tail questions that elude zero-shot inference.

Introduction

While Large Language Models (LLMs) like GPT-4 demonstrate encyclopedic capabilities, their internal knowledge distribution follows a power law. They excel at common, "head" knowledge but frequently struggle with "long-tail" knowledge—specialized facts from niche domains like medicine, climate science, or specific historical records that are underrepresented in pre-training corpora.

To mitigate this, Retrieval-Augmented Generation (RAG) and In-Context Learning (ICL) are typically employed to provide the model with relevant examples. However, a significant challenge remains: LLM predictions for long-tail queries are highly sensitive to the specific examples retrieved. Standard retrievers, such as BM25, prioritize semantic similarity but fail to account for how a retrieved sample might logically confuse or distract the model. This instability often leads to "negative prediction shifts," where adding more retrieved examples actually degrades the model's performance.

Methodology

We propose Dynamic Uncertainty Ranking (DUR), a framework designed to optimize example selection by prioritizing informativeness and stability over simple text overlap. The framework consists of two primary components: an RL-based retriever and a dynamic budget controller.

RL-Based Retriever Training

Instead of relying on static similarity metrics, we train a BERT-based retriever using the REINFORCE algorithm. The reward signal is derived directly from the LLM's performance on a given query. If a retrieved sample helps the LLM reach the correct answer, the retriever receives a positive reward (+1); conversely, if the sample leads to an incorrect prediction, it receives a negative reward (-1). This ensures the retriever learns to identify examples that are functionally helpful for the LLM's reasoning process.

Overview of the Dynamic Uncertainty Ranking (DUR) framework, illustrating the RL-based retriever training and the dynamic threshold update mechanism.

Dynamic Uncertainty Ranking and Budget Control

To address the diminishing returns of adding more examples, DUR utilizes a learnable dynamic threshold ($\sigma$). Unlike fixed-shot methods that always provide a set number of examples, DUR evaluates the impact of each additional sample. If the system detects a negative prediction shift—where the inclusion of a new sample causes the LLM to flip a previously correct answer to an incorrect one—the threshold $\sigma$ is updated to be more selective. This budget controller acts as a "stop-loss" mechanism, ensuring only high-confidence, stable samples are included in the final prompt.

Experimental Results

The DUR method was evaluated across five diverse datasets: Pubmedqa (biomedical), ethos-national (social science), eval-climate (climate change), T-REx, and NatQA (general knowledge).

Performance on Long-Tail Knowledge

The primary success of DUR is observed in "hard" samples—queries where the LLM fails in a zero-shot setting. The authors found that 87% of uncertain queries were these hard samples. DUR achieved a 5.96% boost in accuracy on these long-tail questions compared to the best baseline, PromptPG. Across all tasks, the average improvement was 2.76%.

Comparison of accuracy across five datasets for easy and hard samples, demonstrating the superior performance of the proposed method (Ours) particularly on hard, long-tail questions.

Computational Efficiency

Beyond accuracy, the dynamic budget controller significantly reduced computational overhead. DUR achieved its performance gains while using only 33.8% to 65.2% of the query shots required by standard fixed-shot methods. This reduction translates directly to lower API costs and reduced inference latency.

Discussion and Conclusion

Our findings suggest that semantic similarity is a poor proxy for the "helpfulness" of an ICL example. By focusing on informativeness and stability through reinforcement learning, DUR effectively navigates the uncertainty gap inherent in long-tail knowledge retrieval. Furthermore, the retriever demonstrated strong transferability, performing well across different domains even when trained on a single dataset.

Future work will address the impact of sample ordering (the "lost in the middle" phenomenon) and extend the DUR framework to more complex generative tasks such as summarization and code generation, where rewards can be calculated using metrics like BLEU or ROUGE.

Summary updated

BibTeX
@inproceedings{yu2025dynamic,
  author = {Shuyang Yu and Runxue Bao and Parminder Bhatia and Taha A. Kass-Hout and Jiayu Zhou and Cao Xiao},
  title = {{Dynamic Uncertainty Ranking: Enhancing In-Context Learning for Long-Tail Knowledge in LLMs}},
  booktitle = {Conference of the North American Chapter of the Association for Computational Linguistics},
  year = {2025},
  doi = {10.18653/v1/2025.naacl-long.453},
}
Figure