arXiv:2610.11399cs.AIOct 2026

Manuscript Offprint

arXiv:2610.11399

Estimating great expectations under autoregressive language models with potentials

Francesco I. Re, Shubhangi Ghosh, Tim Vieira, Ryan Cotterell

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

ABSTRACT

Many applications of language models hinge not on individual samples but on the expectation of a test functional under the model. Estimating such expectations reliably can be computationally expensive. In this paper, we show how to make estimation more efficient by exploiting the next-token conditional probabilities which are available as a by-product of sampling. We do so through potentials: real-valued functions on prefixes that decompose the test functional additively. We construct an estimator whose variance depends on the chosen potential, and derive conditions under which a potential reduces this variance. We then develop practical potentials for several estimands and applications, and demonstrate substantial variance reductions across several estimands at comparable computational cost.

Code Repository

1 INTRODUCTION

A language model is a probability distribution over strings. The most common application of such a model is to generate free-form text from a prompt (Radford et al., 2019; Brown et al., 2020). However, for some applications, the quantity of interest is not the sample itself but rather the expectation of a test functional under the model. For instance,

• In reinforcement learning from human feedback, proximal policy optimization (PPO; Schulman et al., 2017) regularizes the policy by penalizing its Kullback–Leibler divergence from a reference model (Christiano et al., 2017; Stiennon et al., 2020; Ouyang et al., 2022), a divergence that is itself an expectation under the policy.

• In AI safety, one is often interested in the probability that a model emits a harmful or otherwise undesirable output (Jones et al., 2025; Angell et al., 2026).

• In distillation, one fits a simpler surrogate, such as an n-gram model, to a large language model by matching expectations such as the cross-entropy under the teacher (Hinton et al., 2015; Agarwal et al., 2024).

• In language-model watermarking, one may be interested in the probability that a generated text is detected as watermarked; that can be viewed as an expectation under the model’s distribution (Kirchenbauer et al., 2023).

• In interpretability, distributional functionals quantify how much a given context shifts a model’s predictions (Pezeshkpour, 2023; Du et al., 2024; Stoehr et al., 2024).

More precisely, given a language model p and a test function f, we wish to compute the expectation of f under p. Unless p and f exhibit exploitable structure 1^{1}, this expectation must be approximated. Monte Carlo methods offer a well known approach: sample strings, evaluate f on them, and average the results. Drawing independent strings directly from p yields the standard Monte Carlo estimator; drawing instead from a proposal distribution and reweighting by the corresponding likelihood ratio yields importance sampling. These estimators are unbiased but can have high variance, so achieving a desired level of precision may require generating many samples at substantial computational cost.

1^{1}When p is a probabilistic finite-state automaton (Rabin, 1963) or a probabilistic context-free grammar (Booth & Thompson, 1973) and f is additively decomposable, one can compute such expectations with dynamic programming (Eisner, 2002; Li & Eisner, 2009; Zmigrod et al., 2021).

In this paper, we introduce a variance-reduction framework that exploits the next-token distributions computed as a by-product of sampling. The idea is to write f as an additive decomposition of token-level increments along the string and to replace each increment with its conditional expectation given the prefix, taken over the next token. Applied to an existing unbiased estimator, this procedure always preserves unbiasedness while making the variance depend on the decomposition. The choice of decomposition is thus the central design choice in the framework.

For a given f, we parametrize the family of its additive decompositions using potentials: real-valued functions on prefixes. We borrow this construction from potential-based reward shaping in reinforcement learning, where potentials redistribute rewards along a trajectory to facilitate learning (Ng et al., 1999). Here, we repurpose potentials to redistribute the function value over marginalizable token level increments and refer to the resulting estimator as the potential estimator.

We first show that there exists an oracle potential yielding a zero-variance estimator. Since it is generally intractable, we derive an exact criterion for when an arbitrary potential reduces variance. We then use the oracle potential to guide potential design: when f has known additive structure, we use components of the oracle potential that can be computed directly from f; for arbitrary functions over strings, we approximate the oracle potential by learning it from samples. In general, given a set of candidate potentials, we introduce a potential-selection procedure that preserves unbiasedness while using the full sample.

Our experiments demonstrate substantial gains in statistical efficiency across four applications and several estimands. For losses and divergences, simple potentials reduce variance in all tested configurations, yielding up to 17×17\times the effective sample size of Monte Carlo. Their gradient counterparts also improve on Monte Carlo in every evaluated comparison, with variance reductions of up to 89%. For expected n-gram counts and frequencies, our estimator produces even larger gains: about 99% lower variance than Monte Carlo after accounting for computational cost (median over targets with lower estimation uncertainty). For non-additive event probabilities, approximations to the oracle potential are also effective: our estimator reduces the variance of watermark-detection estimates by a median 36%, while learned potentials selected through nested cross-fitting reduce the variance of the importance-sampling estimator introduced by (Dorman et al., 2026) by a median 12%. In the latter experiment, this corresponds to approximately 900,000 additional baseline generations. Overall, our results establish potential design as a practical strategy for improving expectation estimates after sampling, across both direct Monte Carlo and importance sampling. We discuss related work in App. A.

References (42)