← All publications

From predictions to confidence intervals: an empirical study of conformal prediction methods for in-context learning

  • Large Language Models
  • Uncertainty Quantification

We combine conformal prediction with in-context learning to construct prediction intervals for noisy linear regression, using transformer predictions in place of repeated model fits.

Paper AABI 2025

Zhe Huang1, Simone Rossi2, Rui Yuan3, Thomas Hannagan3

  1. PSL Research University
  2. EURECOM
  3. Stellantis

A transformer can learn a regression task from examples in its prompt, while its parameters remain fixed. We use this in-context learning (ICL) ability to construct prediction intervals with conformal prediction. Transformer evaluations replace the repeated regression fits inside full conformal prediction. On synthetic noisy linear regression, the resulting intervals approach the requested 90% coverage and behave similarly to a ridge-based conformal reference, with comparable inference times in our implementation.

Why prediction intervals require candidate responses

A point prediction summarizes an expected response; a prediction interval must also account for noise and limited observations. Full conformal prediction tests possible responses by augmenting the observed context Dn\mathcal D_n with (xn+1,z)(\mathbf x_{n+1},z), fitting a predictor, and ranking its residuals. Repeating this operation across candidate values zz creates a computational burden. A pretrained transformer supplies these predictions by evaluating the augmented context with fixed parameters.

We study tasks τ\tau with dd input features and nn context examples:

yi=xi⊤w(τ)+εi,xi∼U(−a,a)d,w(τ)∼N(0,σ2I),εi∼N(0,σn2).y_i=\mathbf x_i^\top\mathbf w^{(\tau)}+\varepsilon_i, \qquad \mathbf x_i\sim\mathcal U(-a,a)^d, \quad \mathbf w^{(\tau)}\sim\mathcal N(\mathbf 0,\sigma^2\mathbf I), \quad \varepsilon_i\sim\mathcal N(0,\sigma_n^2).

The hyperparameters aa, σ\sigma, and σn\sigma_n control the input range, task variation, and observation noise. We pretrain linear self-attention models to minimize squared error on a query whose response is masked. This setting provides a ridge-regression reference for examining both predictions and uncertainty estimates.

Computing conformal scores with a frozen transformer

At inference, we insert a candidate response zz into the query token. The augmented sequence En+1(z)\mathbf E_{n+1}(z) contains all n+1n+1 input-response pairs. A forward evaluation produces a prediction for every token, yielding the residual scores

y^(z)=fLSA(θ,En+1(z))[d+1,:],R^i(z)=∣yi−y^(z)[i]∣,i=1,…,n,R^n+1(z)=∣z−y^(z)[n+1]∣.\begin{aligned} \widehat{\mathbf y}(z) &=\mathbf f_{\mathrm{LSA}}(\boldsymbol\theta,\mathbf E_{n+1}(z))_{[d+1,:]},\\ \widehat R_i(z)&=|y_i-\widehat{\mathbf y}(z)_{[i]}|,\quad i=1,\ldots,n,\\ \widehat R_{n+1}(z)&=|z-\widehat{\mathbf y}(z)_{[n+1]}|. \end{aligned}
Transformer inference on an augmented context, followed by residual scoring, ranking, and prediction-set construction
The candidate response enters the context alongside the observed labels. Joint predictions supply the residuals used to rank that candidate, replacing a separate regression fit.

The pretrained parameters θ\boldsymbol\theta remain fixed. We convert these residuals into a typicalness value and retain candidates above the miscoverage threshold α\alpha:

π^(z)=1−1n+1∑i=1n+11{R^i(z)≤R^n+1(z)},Γα(xn+1)={z∈R:π^(z)≥α}.\begin{aligned} \widehat\pi(z) &=1-\frac{1}{n+1}\sum_{i=1}^{n+1} \mathbf 1\{\widehat R_i(z)\leq\widehat R_{n+1}(z)\},\\ \Gamma_\alpha(\mathbf x_{n+1}) &=\{z\in\mathbb R:\widehat\pi(z)\geq\alpha\}. \end{aligned}

The prediction region is defined over real-valued responses and targets marginal coverage P(yn+1∈Γα(xn+1))≥1−α\mathbb P(y_{n+1}\in\Gamma_\alpha(\mathbf x_{n+1}))\geq1-\alpha. Finite-sample validity requires exchangeable context and test data, symmetric score construction, and appropriate treatment of ranks and ties. We use self-attention without a causal mask to preserve the score symmetry. In computation, we evaluate candidates on a finite grid Z\mathcal Z extending 25% of the observed response range beyond each endpoint. The accepted grid values approximate the continuous prediction region; grid resolution and the conversion of accepted values into intervals affect the numerical coverage. Evaluations for different candidates and test inputs are independent and can be batched.

Overlapping ridge and ICL response profiles near a dashed line marking the true response
For one test input and 1,000 trial responses, the ridge and ICL profiles nearly overlap near the true response. This illustrates the candidate-wise agreement used to build prediction sets.

Coverage and computational cost against ridge

We compare CP with ICL with full CP using ridge and with split CP using ridge. Coverage experiments use 1,000 independent runs, each with nn context examples and 100 test points; plots report medians and 95% confidence intervals. At α=0.1\alpha=0.1, full CP with ICL and ridge approach 90% coverage as context grows. Split CP shows greater variation for small contexts.

Coverage versus context size for ICL, full ridge conformal prediction, and split ridge conformal prediction
ICL and full ridge track each other in panel (a); split ridge varies more at small context sizes in panel (b). The dashed line marks 90% target coverage.
ICL conformal coverage versus context size for 15, 30, and 50 input features
Coverage approaches 90% for 15, 30, and 50 features. The shared trend shows consistent coverage behavior across the tested dimensions.

The timing comparison uses the same hardware and optimized, vectorized JAX implementations. At context size 100, median inference times are 0.32 seconds for ICL, 0.42 for full ridge, and 0.41 for split ridge. These measurements cover inference after transformer pretraining.

Runtime table comparing ICL, full ridge, and split ridge at context sizes 50, 100, and 300
Times are medians in seconds, with 95% confidence intervals in parentheses. ICL has comparable inference cost in this setup; pretraining cost is evaluated separately.

We also compare empirical distributions of typicalness values using Wasserstein-1 distance. This measures agreement between rank-based outputs across candidate evaluations. The discrepancy peaks near d/n=1d/n=1, even when coverage remains close to its target.

Wasserstein distance between ICL and ridge typicalness distributions versus the input-dimension-to-context-size ratio
Disagreement peaks near equal input dimension and context size across the tested dimensions. This exposes differences between the methods that coverage alone leaves unresolved.

Shifts from pretraining preserve coverage in the tested tasks

We change the input range aa or weight scale σ\sigma relative to pretraining, where both equal one. Within each inference task, context and test examples still share a distribution. Coverage remains near 90% across the tested shifts, while typicalness agreement with ridge changes non-monotonically.

Four panels showing coverage and Wasserstein distance under changes to input range and regression-weight scale
Coverage stays near its target in panels (a,b), while discrepancy from ridge varies in panels (c,d). Vertical lines mark pretraining settings; the shift occurs between pretraining and inference tasks.

Allocating pretraining compute

To study training cost, we fit 40 models at budgets of 3×10113\times10^{11} and 101210^{12} FLOPs. We model the Wasserstein discrepancy with

f(N,D∣α,β,A,B,E)=E+ANα+BDβ,f(N,D\mid\alpha,\beta,A,B,E) =E+\frac{A}{N^\alpha}+\frac{B}{D^\beta},

where NN counts parameters, DD counts training tokens, and EE is the fitted asymptotic floor. The coefficients AA and BB weight the effects of model size and training data. Here α\alpha and β\beta are scaling exponents, separate from the conformal threshold. The fitted allocation scales as N∝C0.62N\propto C^{0.62} and D∝C0.38D\propto C^{0.38} with compute budget CC. Two additional models at larger budgets land close to the predicted frontier.

Measured Wasserstein discrepancies, fitted compute contours, and two larger-budget models near the predicted frontier
The fitted contours predict a preferred model size at each compute budget. Models trained at 3×10123\times10^{12} and 101310^{13} FLOPs support the extrapolation within this experiment.

The resulting compute allocation reduces the discrepancy from ridge-based conformal scores within this synthetic regression setting. Prediction-set construction then uses the same frozen non-autoregressive transformer for every candidate response.

Our tumor-segmentation study applies conformal calibration to image regions, separating boundary errors from missed components.