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

Generative Calibration for In-context Learning

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

Introduction

In-context learning (ICL) has emerged as a cornerstone of Large Language Model (LLM) utility, allowing models to adapt to new tasks using only a few demonstrations. Despite its power, ICL is notoriously fragile; minor adjustments to prompt templates or the ordering of examples can lead to drastic performance swings. This paper identifies "label shift" in the model's internal probability distribution as the primary driver of this instability. To combat this, the authors propose Generative Calibration (GC), a theoretically grounded method that uses the model's own creative capacity to estimate and correct its inherent biases.

The Problem: Label Shift and Fragility

The sensitivity of ICL is often described as a "mixed blessing." While a model might achieve state-of-the-art results with one specific prompt, a simple reordering of examples can reduce its accuracy to that of random chance. Previous calibration attempts, such as "Contextual Calibration," used heuristic "null" inputs like "N/A" to estimate bias. However, these strings are often out-of-distribution for the model, leading to unreliable corrections.

The AUROC vs. F1 Paradox

A critical insight of this work is the discrepancy between different performance metrics. The researchers found that while Macro-F1 scores—which depend on a fixed decision threshold—fluctuate wildly, the Area Under the Receiver Operating Characteristic (AUROC) remains high and stable across various prompt configurations.

Macro-F1 vs. Macro-AUROC across different prompt configurations.

As shown in the figure above, the high AUROC (often >0.95) indicates that the model's ability to rank examples—its label conditional $p(x|y)$—is actually quite robust. The failure of ICL lies in the label marginal $p(y)$, which becomes heavily biased toward certain classes based on the prompt's context.

Methodology: Generative Calibration

The authors introduce Generative Calibration (GC) to provide a mathematically unbiased estimate of the model's internal label marginals. Unlike previous methods that guess bias using "null" strings, GC samples directly from the model's distribution.

The Generative Calibration (GC) pipeline.

The GC process follows a three-step pipeline:

  1. Estimation via Generation: The LLM is used to generate $L$ (typically 100) synthetic input sequences $x^l$ based on the provided prompt. This uses the model's own generative capacity to explore the space of inputs it expects.
  2. Marginal Calculation: The researchers calculate the average predictive distribution across these 100 generated sequences. This average serves as an estimate of the model's biased label marginal $\hat{p}(y)$.
  3. Correction: The final prediction for a test input is calibrated by dividing the raw output probability by this estimated bias: $q(y|x) \propto p(y|x) / \hat{p}(y)$.

This approach is efficient; while searching for an optimal example order has a complexity of $O(K!)$, GC only requires a one-time generation of $L$ samples ($O(L)$).

Evaluation and Key Results

The method was rigorously tested across 12 text classification tasks (including Sentiment Analysis, Topic Classification, and Natural Language Inference) using 12 different LLMs ranging from 774M to 33B parameters.

  • Significant Performance Boosts: GC consistently outperformed vanilla ICL and state-of-the-art calibration methods. For GPT2-Large, it provided a massive 27% absolute improvement in Macro-F1.
  • Scaling and Stability: GC proved effective across all model sizes. Notably, it allowed smaller models like GPT2-XL (1.5B) to outperform uncalibrated larger models like OPT (30B). It also significantly reduced variance; on the AGNews dataset, the standard deviation of performance was slashed from 0.25 to 0.03.
  • Competitive with Optimization: GC achieved results comparable to or better than complex prompt optimization methods (like KATE or GlobalE) without the need for exhaustive searches.

Conclusion

Generative Calibration provides a theoretically grounded and effective way to stabilize in-context learning. By using the model's own distribution to correct its internal biases, GC allows even smaller models to achieve performance levels previously reserved for much larger architectures, making ICL more reliable for real-world applications.

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