Exploring Imbalanced Annotations for Effective In-Context Learning

Hongfu Gao, Feipeng Zhang, Hao Zeng, Deyu Meng, Bingyi Jing, Hongxin Wei · OpenReview

Abstract

Large language models (LLMs) have shown impressive performance on downstream tasks through in-context learning (ICL), which heavily relies on the demonstrations selected from annotated datasets. Existing selection methods may hinge on the distribution of annotated datasets, which can often be long-tailed in real-world scenarios. In this work, we show that imbalanced class distributions in annotated datasets significantly degrade the performance of ICL across various tasks and selection methods. Moreover, traditional rebalance methods fail to ameliorate the issue of class imbalance in ICL. Our method is motivated by decomposing the distributional differences between annotated and test datasets into two-component weights: class-wise weights and conditional bias. The key idea behind our method is to estimate the conditional bias by minimizing the empirical error on a balanced validation dataset and to employ the two-component weights to modify the original scoring functions during selection. Our approach can prevent selecting too many demonstrations from a single class while preserving the effectiveness of the original selection methods. Extensive experiments demonstrate the effectiveness of our method, improving the average accuracy by up to 5.46 on common benchmarks with imbalanced datasets.

Introduction

Large Language Models (LLMs) have revolutionized natural language processing through in-context learning (ICL), where the model performs tasks based on a few demonstrations provided in the prompt. These demonstrations are typically selected from a larger pool of annotated data. However, in real-world scenarios, these annotated datasets often exhibit long-tailed distributions where a few "head" classes dominate, and many "tail" classes are underrepresented.

This study investigates the impact of such imbalanced class distributions on ICL performance. As shown in Figure 1, increasing the imbalance ratio leads to a significant degradation in accuracy across various tasks. Furthermore, traditional rebalancing techniques such as over-sampling or under-sampling fail to mitigate this issue effectively, sometimes even exacerbating the performance drop.

Impact of class imbalance on ICL performance and the failure of traditional rebalancing methods.

Methodology: Reweighting with Conditional Bias (RCB)

The core contribution of this work is the identification of conditional bias as a primary driver of performance degradation in imbalanced ICL. While traditional methods focus on class-wise weights (the frequency of labels), they ignore the fact that the few examples available for rare classes often fail to represent the full feature distribution of those classes.

The researchers propose Reweighting with Conditional Bias (RCB), which decomposes the distributional difference between annotated and test datasets into two components:

  1. Class-wise weights ($w$): Accounting for the frequency of class labels.
  2. Conditional bias ($\beta$): Accounting for the feature distribution shift within each class.

To estimate $\beta$, RCB utilizes a small, balanced validation set and employs Bayesian Optimization to find values that minimize empirical error. During the demonstration selection process, the original similarity scores (e.g., cosine similarity) are modified by a factor of $(w + \beta)$. This ensures that selected examples are not only from the correct classes but are also representative and effective for the specific query.

Analysis of Conditional Bias

The existence of conditional bias is empirically supported by measuring the KL divergence between the feature distributions of different classes. As illustrated in Figure 2, there is a clear mismatch in how features are distributed across classes in imbalanced datasets, which explains why simply increasing the number of rare-class examples (over-sampling) is insufficient if those examples are themselves biased.

KL divergence across different classes, illustrating the conditional bias in imbalanced datasets.

Experimental Results

The effectiveness of RCB was evaluated across multiple benchmarks, including sentiment analysis (Amazon, Yelp) and topic classification (AgNews, Yahoo), as well as naturally imbalanced datasets like Emotion.

Key findings include:

  • Significant Performance Gains: On classification tasks with an imbalance ratio of 100, RCB improved average test accuracy from 46.74% to 52.16%—a significant 5.42% absolute gain.
  • Robustness Across Models: The method proved effective for a wide range of LLMs, including Llama-3-8B, OPT-30B, GPT-3.5-Turbo, and Gemini-2.0-Flash.
  • Efficiency: The optimization process is remarkably fast. For example, on an OPT-6.7B model, the process finished in approximately 2.5 minutes, making it a practical "plug-and-play" addition to existing selection pipelines.

Conclusion

Class imbalance in annotated datasets poses a significant challenge for in-context learning. By accounting for both class weights and conditional bias, the RCB method provides a robust solution that outperforms traditional rebalancing strategies. Future work will explore modeling bias in more data-efficient ways and extending this framework to multimodal contexts.

Summary updated

BibTeX
@misc{gao2025exploring,
  author = {Hongfu Gao and Feipeng Zhang and Hao Zeng and Deyu Meng and Bingyi Jing and Hongxin Wei},
  title = {{Exploring Imbalanced Annotations for Effective In-Context Learning}},
  year = {2025},
  eprint = {2502.04037},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2502.04037},
}
Figure