NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Generative Calibration for In-context Learning

Zhongtao Jiang, Yuanzhe Zhang, Cao Liu, Jun Zhao, Kang Liu · DOI

Abstract

In-context learning (ICL) allows large language models (LLMs) to perform tasks with only a few examples, yet this capability is notoriously sensitive to prompt configurations, such as example ordering and templates. This paper identifies "label shift"—a biased preference for certain labels induced by the prompt—as the primary cause of this instability. We introduce Generative Calibration (GC), a method that leverages the LLM’s generative capacity to estimate and nullify this bias. By using Monte-Carlo sampling to generate synthetic inputs, GC provides a data-driven estimate of the model's internal label prior, leading to significant gains in accuracy and stability across diverse tasks and model scales.

Introduction

Large Language Models (LLMs) have revolutionized NLP through In-Context Learning (ICL), where the model learns to perform a task simply by processing a few-shot prompt. However, ICL is often described as a "mixed blessing." While it can achieve state-of-the-art performance, it is "pathogenically sensitive" to the specific choice of examples, the prompt template, and even the order in which examples are presented. A simple reordering of the same three examples can swing a model's performance from high accuracy to random chance.

Previous attempts to stabilize ICL through calibration have relied on heuristic "context-free" strings, such as "N/A" or "[MASK]", to estimate the model's bias. However, these strings are often out-of-distribution for the model, and the model may possess its own internal biases toward the placeholder strings themselves. This paper proposes a more principled approach: using the model's own generative distribution to understand and correct its predictive shifts.

The Ranking Paradox

The authors' investigation begins with a surprising empirical discovery regarding how LLMs fail. By analyzing performance across various prompts, they found that while the Macro-F1 score (a measure of classification accuracy) varies wildly, the AUROC (Area Under the Receiver Operating Characteristic curve) remains remarkably high and stable.

This "Ranking Paradox" suggests that LLMs are actually quite proficient at ranking—they correctly assign higher probabilities to the true label relative to other samples. The failure occurs at the decision threshold. The model's "label conditional" $p(x|y)$ (how it perceives the input given a label) is often accurate, but its "label marginal" $p(y)$ (its prior bias toward a specific label) is broken by the prompt. For instance, a model might predict "Positive" for every input simply because the last example in the prompt was positive, even if it correctly recognizes that some inputs are "more positive" than others.

Generative Calibration (GC)

To address this label shift, the authors introduce Generative Calibration (GC). The core idea is to use the LLM's generative power to "zero out" its own biases. The process follows three steps:

  1. Monte-Carlo Sampling: Instead of using a static, out-of-distribution string like "N/A," the LLM is used to generate $L$ new synthetic input sequences ($x$) based on the provided few-shot prompt. This ensures the calibration data remains in-distribution.
  2. Marginal Estimation: The model calculates the average predictive distribution over these $L$ generated sequences. This provides an unbiased estimate of the model's internal label bias, denoted as $\hat{p}(y)$.
  3. Adjustment: The final prediction is calibrated by dividing the raw probability by this estimated bias: $q(y|x) \propto p(y|x) / \hat{p}(y)$.

By essentially dividing out the model's "preference" for certain labels, GC restores a neutral decision boundary.

Experimental Results

The researchers conducted an exhaustive evaluation across 12 text classification tasks (including sentiment analysis, topic classification, and natural language inference) using 12 different LLMs ranging from GPT2-Large (774M) to LLaMA (33B).

Performance and Stability

GC consistently outperformed both vanilla ICL and existing state-of-the-art calibration methods. Key findings include:

  • Accuracy Gains: GC improved Macro-F1 by up to 27% absolute for smaller models like GPT2-Large. For larger models like LLaMA-33B, it maintained a 7-9% lead over other calibration techniques.
  • Robustness to Ordering: GC dramatically reduced the variance caused by example ordering. On the AGNews dataset, the standard deviation of performance plummeted from 0.25 to 0.03.
  • Efficiency: Smaller models using GC often "punched up," with a 1.5B parameter GPT2-XL model outperforming a 30B parameter OPT model that relied on standard ICL.

Conclusion and Limitations

Generative Calibration offers a lightweight ($O(L+N)$ complexity) and effective solution to the instability of in-context learning. By using the model's generative capacity to fix its discriminative capacity, the authors provide a more theoretically grounded way to handle prompt-induced bias.

However, the method currently assumes a uniform true data distribution ($q(y)$), meaning it assumes classes are balanced in the real world. In scenarios with heavy class imbalance, this assumption may fail. Future work remains to estimate the true label marginal from limited data to further refine calibration for imbalanced real-world datasets. Nonetheless, GC represents a significant step toward making LLMs more reliable and less sensitive to the nuances of prompt engineering.

Summary updated

BibTeX
@inproceedings{jiang2023generative,
  author = {Zhongtao Jiang and Yuanzhe Zhang and Cao Liu and Jun Zhao and Kang Liu},
  title = {{Generative Calibration for In-context Learning}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2023},
  doi = {10.18653/v1/2023.findings-emnlp.152},
}
Figure