Enhancing In-context Learning via Linear Probe Calibration

Momin Abbas, Yi Zhou, Parikshit Ram, Nathalie Baracaldo, Horst Samulowitz, Theodoros Salonidis, Tianyi Chen

Abstract

In-context learning (ICL) is a new paradigm for natural language processing that utilizes Generative Pre-trained Transformer (GPT)-like models. This approach uses prompts that include in-context demonstrations to generate the corresponding output for a new query input. However, applying ICL in real cases does not scale with the number of samples, and lacks robustness to different prompt templates and demonstration permutations. In this paper, we first show that GPT-like models using ICL result in unreliable predictions based on a new metric based on Shannon entropy. Then, to solve this problem, we propose a new technique called the Linear Probe Calibration (LinC), a method that calibrates the model’s output probabilities, resulting in reliable predictions and improved performance, while requiring only minimal additional samples (as few as five labeled data samples). LinC significantly enhances the ICL test performance of GPT models on various benchmark datasets, with an average improvement of up to 21%, and up to a 50% improvement in some cases, and significantly boosts the performance of PEFT methods, especially in the low resource regime. Moreover, LinC achieves lower expected calibration error, and is highly robust to varying label proportions, prompt templates, and demonstration permutations.

Introduction

Large Language Models (LLMs) have demonstrated remarkable capabilities in "few-shot" learning through In-context Learning (ICL). By prepending a few labeled demonstrations to a query, models can perform tasks without weight updates. However, ICL faces significant challenges: it is notoriously brittle to prompt formatting and example ordering, limited by context window sizes, and often produces unconfident, high-entropy predictions.

Overview of In-context Learning (ICL) where demonstrations guide the model to predict the sentiment of a test example.

This paper introduces Linear Probe Calibration (LinC), a lightweight method designed to address these reliability issues. LinC learns a simple linear transformation to calibrate an LLM's output probabilities using a handful of extra labeled samples, significantly boosting accuracy and robustness.

Methodology: Linear Probe Calibration (LinC)

LinC operates as a "black-box" calibration layer that interprets the model's output rather than modifying its internal logic. It applies an affine transformation to the original probability vector $p$ produced by the LLM:

$$\hat{p} = \text{softmax}(Ap + b)$$

The parameters $A$ and $b$ are learned via gradient descent using a small validation set (typically 5 to 30 samples). Unlike heuristic-based de-biasing methods, LinC actively trains these parameters to minimize error. Because the transformation is low-dimensional, matching the number of output classes, training is computationally negligible and requires only the output logits, making it compatible with proprietary APIs.

Experimental Setup

The effectiveness of LinC was evaluated using models like GPT-2-XL, GPT-J (6B), and Llama-2 (7B and 13B) across diverse benchmarks:

  • Text Classification: SST-2/5 (Sentiment), AGNews/DBPedia (Topic), TREC (Question type), RTE (Entailment), and Subj (Subjectivity).
  • Tabular Data: Seven non-text datasets from OpenML (e.g., Breast Cancer, Spambase) to assess cross-domain versatility.

Key Insights and Results

Addressing the Entropy Problem

A core finding is that standard ICL often suffers from high Shannon entropy; even when the model picks the right label, it may assign nearly equal probability to incorrect ones. LinC effectively "sharpens" these distributions, shifting the probability mass toward the correct label and reducing uncertainty.

Comparison of entropy distributions between standard GPT and LinC (Ours) across different shot counts, showing how LinC reduces prediction uncertainty.

Performance Gains and Robustness

  • Accuracy: LinC improved ICL performance by an average of 21%, reaching up to a 50% absolute improvement in specific 0-shot scenarios on DBPedia.
  • Sample Efficiency: Peak performance is often reached with as few as 5 additional labeled points, making it a more effective use of data than simply adding more demonstrations to the prompt.
  • Calibration and Robustness: LinC significantly reduces Expected Calibration Error (ECE) and mitigates the variance caused by different prompt templates or demonstration permutations. It effectively "learns away" the biases introduced by specific wording.
  • PEFT Integration: When combined with Parameter-Efficient Fine-Tuning (PEFT) methods like LoRA or Soft Prompt Tuning, LinC provides substantial boosts in low-resource settings.

Conclusion and Future Work

LinC offers a powerful, efficient way to make LLMs more reliable and accurate without requiring access to internal weights. While highly effective for classification, future work remains to extend this calibration to open-ended generative tasks. Additionally, while LinC improves accuracy and confidence, it does not directly address inherent model biases or safety concerns. The quality of calibration also remains dependent on the representativeness of the small validation set used for training.

Summary updated

BibTeX
@inproceedings{abbas2024enhancing,
  author = {Momin Abbas and Yi Zhou and Parikshit Ram and Nathalie Baracaldo and Horst Samulowitz and Theodoros Salonidis and Tianyi Chen},
  title = {{Enhancing In-context Learning via Linear Probe Calibration}},
  booktitle = {International Conference on Artificial Intelligence and Statistics},
  year = {2024},
  url = {https://openreview.net/forum?id=h8q3qIO8Zv},
}
Figure