Self-Improving In-Context Learning

Baturay Saglam, Dionysis KalogeriasarXiv 2026

TL;DR

This paper introduces a test-time calibration method that improves in-context learning (ICL) by optimizing the continuous embeddings of a fixed prompt without updating model parameters or generating new tokens. By maximizing a self-supervised confidence proxy derived from the model's own log-probabilities on prompt demonstrations via zeroth-order optimization, the approach consistently enhances downstream performance across both classification and free-form generation tasks.

What Problem Does This Paper Address?

Large Language Models (LLMs) excel at in-context learning (ICL)—learning new tasks simply by conditioning on a few input-output examples in the prompt. However, ICL is notoriously fragile. Minor changes, such as reordering identical demonstrations or altering the prompt format, can cause a model's accuracy to plummet from state-of-the-art to near-random.

Existing test-time solutions generally fall into three buckets: selecting better examples, reordering them, or calibrating output probabilities after the fact. However, these methods suffer from structural limitations: they often scale poorly (combinatorial explosion during permutation searches) or require a predefined, finite label set, which restricts their use strictly to classification tasks. This paper addresses the need for a task-agnostic, self-contained method to stabilize and improve ICL at inference time.

Methods

Instead of tweaking discrete tokens, the authors propose intervening directly on the continuous prompt embedding matrix that the model conditions on.

The core of the method relies on a novel, self-supervised ICL-confidence proxy ($f(X)$). This scalar value ranges between 0 and 1 and is computed from a single teacher-forced forward pass over the prompt demonstrations (requiring no token generation). The proxy balances three key components:

  1. Per-demonstration absolute confidence: The length-normalized average log-probability of the true tokens in each demonstrated output.
  2. Pooled robustness: A tail-risk measure (Value-at-Risk at a 0.1 quantile level) across all demonstration tokens to penalize instances where a few outlier tokens have very low probabilities.
  3. Information gain across demonstrations: A metric tracking whether the model becomes progressively more confident as it processes later demonstrations in the sequence.

To maximize this proxy at test time, the authors use zeroth-order (ZO) optimization via a finite-difference estimator. They apply random Gaussian perturbations to the demonstration embeddings, evaluate the proxy, estimate the gradient direction, and iteratively update the continuous embeddings. To prevent the embeddings from drifting into out-of-distribution spaces, they incorporate lightweight regularization mechanisms: gradient clipping, a cosine similarity constraint, and an initial proxy gate that skips optimization if the initial signal is too flat.

Datasets

The method was evaluated on ICLEval, a specialized benchmark designed to isolate a model's pure ICL capability from its pretraining factual knowledge. ICLEval replaces real-world entities with random hash strings, ensuring that the model can only solve the task by inferring the rules directly from the provided in-context examples.

The benchmark spans 12 distinct tasks (totaling 2,040 samples) categorized into:

  • Exact Copying: String Completion and Dictionary Search.
  • Rule Learning: Format Check, Format Cloning, Format Conversion, Order Check, Order Adjustment, Duplication Check, De-Duplication, Count & Navigation, Relation Analysis, and List Mapping.

Key Insights and Ideas

  • Log-Probabilities as an Optimization Surface: A key "aha" moment is that a model's internal confidence on its own prompt demonstrations provides a highly reliable gradient signal for downstream query accuracy.
  • Breaking the Classification Barrier: Because the confidence proxy is computed entirely from the provided demonstrations rather than a predefined label space, this method is fully task-agnostic. It works identically for open-ended text generation and format conversion as it does for standard classification.
  • Surfacing Latent Capabilities: The optimization process does not inject new knowledge into the model; rather, it reshapes the prompt representation to better activate and utilize the model's existing, underutilized latent capabilities.

Key Results

The authors evaluated their method across several model architectures and scales, including Llama 3.1-8B, Qwen3-4B, and Gemma 2-2B.

  • Consistent Improvements: Across all models, the calibration method either matched or strictly improved base-model accuracy on every single task, never causing performance degradation.
  • Substantial Gains in Rule Learning: The method achieved massive relative accuracy boosts on complex rule-following tasks. For instance, Llama 3.1-8B saw a +122.2% relative improvement on Format Check, while Gemma 2-2B achieved a +300% relative boost on Relation Analysis.
  • Baseline Outperformance: The approach consistently outperformed classification-specific baselines like Contextual Calibration (CC), Domain-Conditional PMI (DC-PMI), and DEmO on the majority of tasks, despite the baselines having access to task-specific constraints.

The complete breakdown of per-task exact-match accuracy across the three models is detailed below:

Per-task exact-match accuracy on ICLEval

Limitations and Future Work

The authors note a few practical limitations:

  • Prior Knowledge Requirements: The method assumes that the exact token positions of the output spans within the prompt demonstrations are known, and that the exemplar labels provided are correct.
  • Prompt Length Constraints: It has not yet been validated on prompts containing fewer than three demonstrations.
  • Computational Overhead: Because the proxy is non-stationary, conservative learning rates are required, leading to an optimization process that takes roughly 10 to 60 seconds per sample on standard hardware (though this could be mitigated with highly optimized inference stacks like vLLM).

Future Directions: A natural next step is combining this continuous embedding calibration with existing discrete methods—such as running this optimization on top of a prompt that has already been pre-sorted by a demonstration ordering algorithm.

Summary updated

BibTeX
@misc{saglam2026self,
  author = {Baturay Saglam and Dionysis Kalogerias},
  title = {{Self-Improving In-Context Learning}},
  year = {2026},
  eprint = {2605.23180},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2605.23180},
}
Figure