Estimating the Probabilities of Rare Outputs in Language Models

## Abstract

Abstract We consider the problem of low probability estimation : given a machine learning model and a formally-specified input distribution, how can we estimate the probability of a binary property of the model’s output, even when that probability is too small to estimate by random sampling? This problem is motivated by the need to improve worst-case performance, which distribution shift can make much more likely. We study low probability estimation in the context of argmax sampling from small transformer language models. We compare two types of methods: importance sampling, which involves searching for inputs giving rise to the rare output, and activation extrapolation, which involves extrapolating a probability distribution fit to the model’s logits. We find that importance sampling outperforms activation extrapolation, but both outperform naive sampling. Finally, we explain how minimizing the probability estimate of an undesirable behavior generalizes adversarial training, and argue that new methods for low probability estimation are needed to provide stronger guarantees about worst-case performance.

## 1 Introduction

Modern ML systems undergo black-box optimization to minimize a loss function on samples drawn from a training distribution. Although models produced in this way perform desirably on average over this distribution, they can still produce highly undesirable outputs on very rare inputs. This is a problem, because these rare inputs can become much more likely in the presence of distribution shift, especially one chosen adversarially, such as with large language model “jailbreaks” (Carlini et al., ; Wei et al., ).

Preventing such highly undesirable outputs is a notoriously challenging problem. The most common remedy is adversarial training, in which inputs that produce these undesirable outputs are searched for and used as additional training data (Goodfellow et al., ; Madry, ), but the transfer between different search methods is generally weak (Kang et al., ; Wei et al., ). In this work, we propose the more modest goal of simply estimating the probability that an input drawn from some distribution will produce a certain kind of output, which has been considered before in the context of computer vision in Webb et al. (). We will show that even this intermediate goal is challenging, but successful methods could enable new ways of preventing undesirable outputs by minimizing their estimated probability.

To advance work on this problem, we study low probability estimation in the context of small transformer language models. We consider various formally-defined input distributions in which each input token is sampled independently, and develop methods for estimating the probability that a particular target token will have the largest output logit. We constrain the computational budget of our methods and obtain ground truth probabilities by random sampling using a much larger computational budget. The target tokens are chosen to have ground truth probabilities between $10^{-9}$ and $10^{-5}$, which are too small for random sampling to produce a good estimate under the constrained computational budget.

In this context, we study two types of methods:

- •
Importance sampling. We define a new input distribution under which the rare event is much more likely, sample from that distribution, and re-weight samples to obtain an unbiased estimate for the original distribution. Our Independent Token Gradient Importance Sampling (ITGIS) method treats token positions independently and uses gradients to obtain this new input distribution, while our Metropolis–Hastings Importance Sampling (MHIS) method uses a Markov chain Monte Carlo algorithm to sample from a distribution with non-independent tokens.
- •
Activation extrapolation. We use random samples to fit a probability distribution to the model’s logits, and extrapolate into the tails of this distribution to produce a probability estimate. Our Quadratic Logit Decomposition (QLD) method applies a presumption of independence to the empirical distribution of logits, motivated by Christiano et al. (), and our Gaussian Logit Difference (GLD) method is a simple baseline that fits a Gaussian to the difference between the maximum logit and target logit.

In our setting, both types of methods outperform random sampling, and importance sampling tends to outperform activation extrapolation. Nevertheless, we remain interested in activation extrapolation and similar approaches because they produce new methods for reducing the probabilities of rare outputs, whereas importance sampling essentially recovers standard adversarial training.

The remainder of the paper is structured as follows. In Section 2, we formally define the problem of low probability estimation, both in general and in our language model setting. In Section 3, we describe our four methods in more detail. In Sections 4 and 5, we describe the models and input distributions on which we test our methods and convey our experimental findings. Finally, in Sections 6, 7 and 8, we discuss the limitations and implications of our results, related work, and future directions.

Figure: Figure 1: Left: To evaluate the performance of our low probability estimation methods, we compare their estimates against ground-truth probabilities obtained by brute-force sampling with a larger computational budget. Right: The estimates of Metropolis–Hastings Importance Sampling on the icl input distribution and 4-layer model, after a fit has been applied. Each point represents a different target token.
Refer to caption: extracted/5932674/figures/fig1.png

## 2 Problem Statement

Given an input space $\mathcal{X}$, an output space $\mathcal{Y}$, an input distribution $\mathcal{D}\in\Delta(\mathcal{X})$, a model $M:\mathcal{X}\to\mathcal{Y}$, and a formal boolean property of model outputs $C:\mathcal{Y}\to\{0,1\}$, low probability estimation is the problem of efficiently estimating

$$ $\Pr_{{\textnormal{x}}\sim\mathcal{D}}[C(M({\textnormal{x}}))=1].$ $$

We sometimes refer to the event $C(M({\textnormal{x}}))=1$ as the “target behavior”, or just “the behavior.” If the probability of the behavior large enough (say, larger than $1/n$), it is easy to estimate by drawing $n$ independent samples from $\mathcal{X}$ and using the sample mean of $C(M({\textnormal{x}}))$. However, if the probability is significantly smaller than $1/n$, this sample mean is almost always 0 0, making it uninformative at distinguishing between small probabilities like $10^{-10}$ and $10^{-20}$.

### 2.1 Our setting

In this paper, we study low probability estimation in the setting of argmax sampling from language models with single-token behaviors. Let $M:\mathcal{V}^{*}\to\mathcal{V}$ be a transformer language model that predicts the next token given a string of previous tokens, where $\mathcal{V}$ is the token vocabulary. Note that we sample at temperature 0 0, so $M$ is deterministic. Given a distribution $\mathcal{D}$ over $\mathcal{V}^{*}$ and a target token $t\in\mathcal{V}$, the low probability estimation problem for single-token behaviors is the task of estimating

$$ $\Pr_{{\mathbf{x}}\sim\mathcal{D}}[M({\mathbf{x}})=t].$ $$

Letting $M_{i}({\mathbf{x}})$ be the logit the model assigns to token $i\in\mathcal{V}$, this can also be written as:

$$ $\Pr_{{\mathbf{x}}\sim\mathcal{D}}[M_{t}({\mathbf{x}})>M_{i}({\mathbf{x}})\quad \forall i\neq t].$ $$

In general, $\mathcal{D}$ can be any distribution that can be formally specified. However, in this paper we focus only on distributions $\mathcal{D}$ with independent tokens. That is, we specify an input length $k$ and token distributions $\mathcal{D}_{1},\dots,\mathcal{D}_{k}\in\Delta(\mathcal{V})$, then write $\mathcal{D}$ as the product $\mathcal{D}_{1}\times\dots\times\mathcal{D}_{k}$. Table 1 shows the $8$ distributions that were tested, with tokens colored for clarity. To prevent overfitting, the methods were only run on the first four distributions during development, and they were finalized before testing on the last four distributions. The results were qualitatively the same on both halves of the split.

**Table 1: Input distributions and examples. See Table 2 for more detailed descriptions.**
| Name | Short description | Tokenized example |
| --- | --- | --- |
| hex | Hexadecimal characters | 
aa5acbf6aad468813f94c2fbbff4dc65eadc1553 |
| camel | CamelCase Python tokens | 
LayoutCredServicesVirtualUseTimeInterfaceColorBodyAlRowHeightRepFontAndMetaRequestGroupsOneLabelPasswordAndRaVideoFailedValueGuiTypeMicrosoftSlotDeId |
| colon | Python tokens, ending with ‘:’ | 
            et-=   """]:   ($\backslash$n                     :   Thisc$\backslash$r$\backslash$n                                             (’/$\backslash$nFilereturn$\backslash$n$\backslash$n                     
_’].2default.**1      self(   def’)",: |
| if | Python tokens, starting with ‘ if’ | 
   if:   else,-post$\backslash$n                     $\backslash$n                        2$\backslash$n$\backslash$n5   foundfromout,   self-   node   +=$\backslash$n   $\backslash$n                        =$\backslash$n(   this   ’values(),.(do |
| caps | “He/She screamed:”, followed by caps and punctuation | 
He   screamed:   "ESOTTULEBOV.,WR!!IMITLEER.,ARY...IIESSION |
| english | English words | 
ating.   is   invent   School   not   found   from   cm   an   in   one   to   shooting   everyone   Cor   George   around   responsive   employees   ground   on   stone   various, |
| spanish | Spanish tokens | 
   lo   no   bu   dees   cr   socialjosabiler   m   de   enidadareljd   final   de   v   de   lo   much |
| icl | In-context learning prompt | 
A   for   American   R   for   Return   C   for   crack   T   for   troubles   H   for   house   E   for   equipment   O   for   operating   R   for   reason   Y   for   your   V   for |

## 3 Estimation Methods

We introduce four methods in this section: two importance sampling methods (Independent Token Gradient and Metropolis–Hastings), and two activation extrapolation methods (Quadratic Logit Decomposition and Gaussian Logit Difference). We also compare against the baseline of outputting an optimal constant, which can be thought of as the performance of naive sampling because we only evaluate the methods on tokens with ground truth probabilities less than the reciprocal of the allotted sampling budget (see Section 4).

### 3.1 Importance Sampling Methods

Naive sampling fails to produce good estimates for low probability events because it takes too many samples from $\mathcal{D}$ to observe a positive example. To address this, we can instead draw samples from a different distribution that up-weights regions of input space most likely to produce the behavior of interest. If we re-weight our observations properly, this gives an unbiased estimator for the true probability. This is known as importance sampling, and it enjoys the same advantages that adversarial training has over standard training: by using a narrower input distribution, we can more efficiently discover positive examples of the target behavior.

Formally, let $p({\bm{x}})$ be the probability mass function of $\mathcal{D}$, and let $q({\bm{x}})$ be the PMF of any other distribution. Then

$$ $\Pr_{{\mathbf{x}}\sim p}[M({\mathbf{x}})=t]=\operatorname{\mathbb{E}}_{{ \mathbf{x}}\sim p}[\mathbbm{1}[M({\mathbf{x}})=t]]=\operatorname{\mathbb{E}}_{ {\mathbf{x}}\sim q}\left[\frac{p({\mathbf{x}})}{q({\mathbf{x}})}\mathbbm{1}[M( {\mathbf{x}})=t]\right],$ $$

but the latter may have less variance (and so require fewer samples to get a good estimate).

The following two importance sampling methods take $q({\bm{x}})$ to be a Boltzmann posterior with prior $p({\bm{x}})$. The first defines $q({\bm{x}})$ with independent tokens, while the second defines $q({\bm{x}})$ to have non-independent tokens and so requires a more sophisticated sampling method.

#### 3.1.1 Independent Token Gradient Importance Sampling (ITGIS)

We want $q$ to up-weight tokens that contribute to $t$ being outputted. One way to do this is to continue to treat each input token as independent, but change the probability of tokens according to their average linear contribution to the logit of $t$. Let ${\bm{x}}=({x}_{1},\dots,{x}_{k})\in\mathcal{V}^{k}$ be an input of length $k$, and say that $p({\bm{x}})$ factors as $p_{1}({x}_{1})\cdots p_{k}({x}_{k})$. Then we define $q({\bm{x}})=q_{1}({x}_{1})\cdots q_{k}({x}_{k})$, where

$$ $q_{i}({x}_{i})\propto p_{i}({x}_{i})\cdot\exp\left(\frac{s_{i}({x}_{i})}{T}\right)$ $$

and

$$ $s_{i}({x}_{i})=\operatorname{\mathbb{E}}_{{\mathbf{x}}^{\prime}\sim q}[\nabla_ {{\mathbf{x}}^{\prime}}M_{t}({\mathbf{x}}^{\prime})]_{i,{x}_{i}}.$ $$

$T$ is a temperature parameter, and the gradient is taken by treating ${\mathbf{x}}^{\prime}$ as a one-hot vector in $\mathbb{R}^{k\times|\mathcal{V}|}$. Intuitively, the gradient $\nabla_{{\mathbf{x}}^{\prime}}M_{t}({\mathbf{x}}^{\prime})_{i,{x}_{i}}$ gives us a linear approximation to how much the logit of $t$ would change if we replaced $i$-th token of ${\mathbf{x}}^{\prime}$ with ${x}_{i}$ (up to an additive constant w.r.t. ${x}_{i}$). Thus, $s_{i}$ scores each token value according to its average linear contribution to $M_{t}$, and $q_{i}$ is defined as the Boltzmann distribution with respect to this score function.(^1^11It can be shown that, given a score function $s(x)$ and a prior $p(x)$, the distribution that maximizes $\operatorname{\mathbb{E}}_{{\textnormal{x}}\sim q}[s({\textnormal{x}})]-T\cdot \mathrm{KL}(q\|p)$ is $q(x)\propto p(x)\cdot\exp(s(x)/T)$.)

However, since $s_{i}$ and $q$ are both defined in terms of each other, we can’t calculate $s_{i}$ directly. To overcome this, we construct a sequence of score functions $s_{i}^{(0)},s_{i}^{(1)},\dots$ and associated distributions $q^{(0)},q^{(1)},\dots$ that are adaptively refined with respect to each other (see Appendix B.i for details). Sampling from each $q^{(j)}$ lets us calculate an importance sampling estimate, and the final output of the method is the average value of these estimates across all $j$.

#### 3.1.2 Metropolis–Hastings Importance Sampling (MHIS)

A problem with ITGIS is that the new sampling distribution $q({\bm{x}})$ still treats all tokens as independent, and it only accounts for linear effects of tokens on the target logit. Thus, ITGIS may fail to sample into the most important regions of the input space if the model is sensitive to non-linear interactions between tokens (e.g., if the model’s target logit is only high when the last two tokens of the input are the same as each other).

To remedy this, we can define an importance sampling distribution that doesn’t have independent tokens. We must use a score function that depends on the entire input; the most natural choice is the target logit $M_{t}({\bm{x}})$. We define

$$ $q({\bm{x}})\propto p({\bm{x}})\cdot\exp\left(\frac{M_{t}({\bm{x}})}{T}\right),$ $$

again using a Boltzmann distribution to up-weight regions of input space that are more likely to have positive samples.

Unlike ITGIS, we cannot explicitly compute $q$ because it does not factor into independent distributions over each token. Instead, we use the Metropolis–Hastings algorithm to produce a random walk in input space that has a stationary distribution of $q$.(^2^22Metropolis–Hastings is a Markov Chain Monte Carlo method for sampling from a distribution with an unknown normalizing constant. See Robert () for a description of the algorithm.) To do so, we must define a proposal distribution $\phi({\bm{x}}^{\prime}|{\bm{x}})$ that suggests the next element of the walk. To encourage fast mixing, this proposal distribution should be good at exploring into regions of input space that $q$ weights highly.

Here we take inspiration from Greedy Coordinate Gradient, an algorithm that optimizes a discrete prompt to jailbreak a model using gradients (Zou et al., ). We adapt this optimization procedure into a proposal distribution: to pick a proposed next step ${\mathbf{x}}^{\prime}$ of the walk, we choose a random token position $i$ to replace, compute the gradient of $s({\mathbf{x}})$ with respect to ${\textnormal{x}}_{i}$, then sample a replacement token for position $i$ according to a Boltzmann distribution defined by this gradient (similarly to ITGIS). The final output of the method is the average importance sampling estimate taken after a burn-in period. For a precise description of the algorithm, see Appendix B.ii.

### 3.2 Activation Extrapolation Methods

The importance sampling methods search for explicit examples of inputs that cause the given behavior. This makes their task at least as hard as the adversarial training search problem—if it is difficult to find an ${\bm{x}}\in\mathrm{supp}(\mathcal{D})$ such that $M({\bm{x}})=t$, the importance sampling estimators will likely fail to produce a positive estimate.

We hope to find low probability estimation methods that work even when the search problem for importance sampling is hard. To do this, we introduce activation extrapolation: first fit a distribution to the activations or logits of $M$, then estimate the probability of the output property of interest under this idealized distribution. Our first such method is Quadratic Logit Decomposition, which applies a presumption of independence between uncorrelated subspaces the model’s pre-unembed activations. We also develop Gaussian Logit Difference, which is intended as a simple baseline method.

#### 3.2.1 Quadratic Logit Decomposition (QLD)

Let the random vector ${\mathbf{v}}({\mathbf{x}})\in\mathbb{R}^{d}$ be the activation of the model right before applying the unembed matrix ${\bm{W}}_{U}\in\mathbb{R}^{d\times|\mathcal{V}|}$. That is, ${\mathbf{v}}({\mathbf{x}})\cdot{\bm{W}}_{U}$ represents the model’s output logit vector $M({\mathbf{x}})_{1,\dots,|\mathcal{V}|}$. We first collect $n$ samples of ${\mathbf{v}}$ (call them ${\mathbf{v}}^{(1)},\dots,{\mathbf{v}}^{(n)}$). We then choose some unit direction ${\bm{d}}\in\mathbb{R}^{d}$ (see below), then decompose each ${\mathbf{v}}^{(i)}$ into ${\mathbf{a}}^{(i)}+{\mathbf{b}}^{(i)}$, where ${\mathbf{a}}$ lies in the subspace spanned by ${\bm{d}}$, and ${\mathbf{b}}$ lies in the complementary subspace that is orthogonal in a whitened basis.(^3^33Actually, ${\mathbf{a}}$, ${\mathbf{b}}$, and ${\bm{d}}$ are all defined in the whitened space of ${\mathbf{v}}$; see Appendix B.iii.) This decomposition is chosen such that the random vectors ${\mathbf{a}}$ and ${\mathbf{b}}$ are uncorrelated across the $n$ samples.

Next, by treating the random vectors ${\mathbf{a}}$ and ${\mathbf{b}}$ as independent, we can use our $n$ samples of each to obtain $n^{2}$ “synthetic” samples of ${\mathbf{u}}$. The final output of QLD is the proportion of these synthetic samples that cause $t$ to be outputted:

$$ $\frac{1}{n^{2}}\left|\left\{(i,j)\in[n]^{2}\,\,\,\big{|}\,{\mathbf{a}}^{(i)}+{ \mathbf{b}}^{(j)}\in S\right\}\right|,$ $$

where $S\subseteq\mathbb{R}^{d}$ is the “acceptance region” of activation space corresponding to activations that result in the target logit being highest after unembedding. Despite the fact that there are $n^{2}$ synthetic samples, this proportion can be computed in $\tilde{O}(n)$ time by first sorting the samples ${\mathbf{a}}^{(i)}$. A more complete description of the QLD algorithm can be found in Appendix B.iii.

Choice of direction.  We rely on the following two assumptions for QLD to perform well: 1) ${\mathbf{a}}$ and ${\mathbf{b}}$ are independent, and 2) the contribution towards the output behavior is split roughly equally between these two terms (see Appendix C for more discussion). After some initial experimentation with a variety of candidate directions,(^4^44Other candidate directions included 1) the $t$-th column of ${\bm{W}}_{U}$ pulled back into whitened space and 2) the expectation of $\mathcal{N}(0,\mathrm{Id}_{d})$ conditioned on lying in the whitened acceptance region.) we decided to set ${\bm{d}}$ to be the direction of the shortest vector in whitened space that results in the model outputting $t$. It can also be thought of as the maximum likelihood value of ${\mathbf{v}}$ under a Gaussian prior, conditioned on observing the model output $t$. Appendix D describes the algorithm we use to compute ${\bm{d}}$.

#### 3.2.2 Gaussian Logit Difference

On any given input, we can record the difference $\Delta_{t}:=M_{t}({\mathbf{x}})-\max_{i}M_{i}({\mathbf{x}})$. We wish to estimate the probability that $\Delta_{t}\geq 0$. A natural estimation method, which we view as a simple baseline, is to treat $\Delta_{t}$ as Gaussian by estimating its mean $\mu$ and standard deviation $\sigma$ with samples, then calculate $\Pr[\mathcal{N}(\mu,\sigma^{2})\geq 0]$. In practice, we use a slightly different functional form that captures the Gaussian PDF, which approximates the CDF well in the tails. The output of the Gaussian Logit Difference method is:

$$ $\exp\left(-\left(\frac{a\mu}{\sigma+\epsilon}\right)^{2}+b\right)+c,$ $$

where $a,b,c,$ and $\epsilon$ are parameters that are fit to minimize loss across all target tokens associated with a given distribution (see Section 4.2).

## 4 Experimental Setup

We apply our methods on three models: a 1-layer, a 2-layer, and a 4-layer transformer from Nanda & Bloom (). All models have a hidden dimension of $d=512$, a vocabulary size of $|\mathcal{V}|=48262$, GELU non-linearities (Hendrycks & Gimpel, ), and were trained on the C4 dataset (Raffel et al., ) and CodeParrot (Tunstall et al., ).

For each of the $8$ distributions (listed in Table 1) and for each model, we generate ground-truth token probabilities by running forward passes on $2^{32}$ random samples. We then select a random set of 256 tokens among those with ground-truth probabilities between $10^{-9}$ and $10^{-5}$, and we test all of our methods on these tokens.(^5^55The hex distribution only had $159$ and $135$ such tokens for the $2$- and $4$-layer models, respectively, so we instead used every token that fell into the given range. See Appendix E for more details.)

We give each method a computational budget of $2^{16}$ model calls (see details in Appendix F). This budget was chosen so that naive sampling would almost never result in any positive estimates for the range of token probabilities we test $(2^{16}<10^{5})$, but the theoretical quadratic gains from QLD would still be enough to get signal on the entire range of probabilities $((2^{16})^{2}>10^{9})$.

Our code is available at [https://github.com/alignment-research-center/ low-probability-estimation](https://github.com/alignment-research-center/low-probability-estimation).

### 4.1 Itakura–Saito Loss

We measure the quality of the method with a loss function inspired by the Itakura–Saito divergence (Itakura & Saito, ). If $p$ is the ground-truth probability of a particular target token, then an estimate of $q$ incurs a loss of:

$$ $D_{\mathrm{IS}}(p,q)=\frac{p}{q}-\ln\frac{p}{q}-1.$ $$

Two considerations went into the choice of this loss function. First, Itakura–Saito loss is a proper scoring rule (Buja et al., ). Second, since it only depends on the ratio $p/q$, Itakura–Saito loss is sensitive to small probabilities: if $p=10^{-100}$ and $q=10^{-10}$, then $D_{\mathrm{IS}}(p,q)$ is very large. In contrast, the squared error loss function $(p-q)^{2}$ would be extremely small. Intuitively, this sensitivity is desirable because we care how our methods perform on a wide (as measured in log-space) range of ground-truth probabilities. We don’t want the performance metric to be dominated by a method’s behavior on only the most probable tokens.

For completeness, we also report our results using squared error in log-space (Appendix H), even though this is not a proper scoring rule. The results are qualitatively identical.

### 4.2 Affine Fits

Many methods often report estimates of 0 0, but $D_{\mathrm{IS}}$ is undefined for $q=0$. To address this, we fit a transformation $x\mapsto ax^{c}+b$ to the outputs of each method, where $a,b$ and $c$ are chosen to minimize Itakura–Saito loss. $ax^{c}$ can be thought of an affine transformation in log-space, and adding $b$ prevents values from being too small while barely affecting larger outputs. To ensure that this transformation is not overfitting to the particular set of 256 tokens, we report the leave-one-out cross-validation (LOOCV) loss of each method. We train a separate fit for each (method, input distribution) pair.

Note that the Gaussian Logit Difference method has a special functional form of its fit ($(\mu,\sigma)\mapsto\exp\left(-\left(\frac{a\mu}{\sigma+\epsilon}\right)^{2}+b
\right)+c$ instead of $x\mapsto ax^{c}+b$) but is otherwise evaluated in the same way.

## 5 Results

Figure 2 shows the performance of each method. The relative ordering is clear: both importance sampling methods outperform Quadratic Logit Decomposition, which in turn outperforms Gaussian Logit Difference. GLD is barely better than outputting an optimal constant (which can be interpreted as the performance of naive sampling). Figure 4 shows that there is a fair amount of variation in method performance across the $8$ distributions: some behaviors like hex and icl favor MHIS, while others like spanish heavily favor ITGIS. A more detailed table of results is in Appendix G.

Among the two importance sampling methods, ITGIS does better on smaller models, while MHIS does better on larger models. We believe this is because larger models are less easily approximated as linear functions and are more likely to have complex behaviors arising from inter-token interactions.

Figure 3 displays example scatter plots of ITGIS, MHIS, and QLD estimates before a fit is applied. Each point represents the ground-truth and estimated probability of a different target token. More scatter plots can be found in Appendix J; note that the qualitative performances of the methods can vary significantly on different input distributions. We perform an ablation study on our choice of loss function in Appendix H, in which we score methods based on squared error in log-space instead of Itakura–Saito loss.

Figure: Figure 2: The Itakura–Saito loss of all methods across different model sizes. The solid lines indicate the loss of each method averaged over all $8$ distributions, with bands showing standard error. The colored points indicate the loss on individual distributions, with horizontal jitter added for visibility. Lower is better.
Refer to caption: extracted/5932674/figures/IS_all.png

Figure: Figure 3: Examples of method outputs on two different behaviors and models, before a fit is applied. Estimates of 0 0 are placed at the bottom of each graph for visibility.
Refer to caption: extracted/5932674/figures/unfit_caps_4l.png

Figure: Figure 4: The Itakura–Saito loss of all methods across different distributions, averaged over all $3$ model sizes. Lower is better.
Refer to caption: extracted/5932674/figures/loss_by_dist.png

## 6 Discussion

### 6.1 Distribution shift as motivation

One might ask: if a particular model behavior is so rare that it never arises during training, why would we care about estimating its probability? There are a few reasons. First, some AI systems may be run on many more inputs during the course of deployment than during training. Thus, if a certain model behavior would be so catastrophic that it is unacceptable for it to occur even once in deployment, we cannot rely on training to drive down its probability low enough. Second, there may be distributional shift between training and deployment such that events that occur extremely rarely during training become more likely in deployment. This could occur because of an input chosen adversarially, but it could also occur because of goal misgeneralization (Shah et al., ).

A particularly challenging case is deceptive alignment, the possibility that an ML model would look for clues about whether it is in a training or a deployment environment, and only behave well in training (Hubinger et al., ). To detect whether a model is deceptively aligned, one could craft an input distribution that is “wide enough” to assign some probability mass, even if very small, to any possible deployment-time input, then apply low probability estimation methods to detect if the model would ever perform a catastrophic behavior on this distribution.(^6^66To prevent false positives, this would require a very demanding definition of catastrophe that would be impossible for the model to trigger “by accident.”) For more discussion of this idea, see Xu ().

### 6.2 Relation to red-teaming and adversarial training

Our importance sampling methods for low probability estimation involve finding inputs for which the rare event occurs. This amounts to the well-studied task of “red-teaming”. As long as the required importance sampling ratios can be computed, any method for red-teaming can be turned into an importance sampling method for low probability estimation, as we demonstrate with our adaptation of Greedy Coordinate Gradient into MHIS (Zou et al., ). However, our activation extrapolation methods such as QLD do not correspond to any red-teaming method.

A further reason to be interested in low probability estimation is that it could be used to reduce the probability of the rare event, by optimizing the model to produce a lower estimate. For example, this could be done using gradient descent, if the estimate were a differentiable function of the model’s parameters. For an importance sampling method, this amounts to finding inputs for which the rare event occurs (i.e., red-teaming) and using them as training data, which is essentially the well-known method of adversarial training (Goodfellow et al., ). However, since our activation extrapolation methods do not correspond to any red-teaming method, new activation extrapolation methods potentially provide us with new ways to reduce the probabilities of rare events.

### 6.3 Importance sampling versus activation extrapolation

In our experiments, we found that importance sampling methods outperformed activation extrapolation. Nevertheless, there are theoretical cases in which importance sampling performs worse than other methods. For example, consider a model that outputs the SHA-256 hash of its input: finding any input that gives rise to a particular output is computationally infeasible, yet it is still easy to estimate the probability of a particular output by modeling the output of the hash function as random.

More generally, we are excited about low probability estimation as a concrete problem for which for which it may be necessary to leverage internal model activations. In place of importance sampling, we may be able to use deductive estimates based on a presumption of independence (Christiano et al., ). Our Quadratic Logit Decomposition method is an early proof of concept of this, even though it is outperformed by importance sampling in our setting.

### 6.4 Limitations

There are two main limitations of our experimental setup. First, we only use input distributions that factor into independent tokens. This choice is necessary for the definition of ITGIS. It is also very convenient for the implementation of MHIS, because it gives efficient sampling access to the proposal distribution. To move beyond independent token input distributions, we could define the input distribution to be the output of a separate generative model and adapt some of the current estimation methods appropriately (GLD and QLD are input-agnostic and could be applied in their current form).

Second, we only study model behaviors that consist of a single token sampled at temperature 0 0. This is unrealistic because in practice, if we were concerned about specific single-token outputs, it would be easy to block them with a filter. In contrast, the types of behaviors we actually worry about likely involve long chains of autoregressive generation or interaction with the external world (e.g., when forming and executing a plan). We are excited to see future work extending our setting in this direction.

Nevertheless, it is worth noting that formally-defined distributions and behaviors are more general than they may initially seem. For example, we could formalize the event “$M$ writes buggy code”, as: When $M$’s output is given to GPT-4 along with the prompt “Does this code contain any bugs? Let’s think step by step.”, does GPT-4 end its response with YES?

## 7 Related Work

The problem of low probability estimation was previously considered in the context of computer vision by Webb et al. (), where they propose using an Adaptive Multi-Level Splitting algorithm with Metropolis Hastings. However, they only study the problem in the context of computer vision with continuous input spaces, and their approaches still require finding positive samples, unlike our activation extrapolation methods. Phuong et al. () and Højmark et al. () attempt to estimate the probability that a language model passes certain capability evaluations, even when its success rate is low, though their methods are not directly applicable to our formal setting.

Our importance sampling methods can be viewed as solving a special case of controlled text generation (Zhang et al., ) in which we want to sample from an autoregressive distribution conditioned on a property of the full output (in our case, that the last token is $t$). Yang & Klein () do this by training Future Discriminators to steer model generation towards the desired attribute. Lew et al. () approach the problem with a Sequential Monte Carlo steering approach; however, their infilling algorithm doesn’t provide any benefit over naive sampling when all tokens except the last are independent. These works don’t consider the problem of low probability estimation.

Zhao et al. () focus on the problem of estimating the partition function of an unnormalized target distribution over sequences, which is a more general case of our low probability estimation problem. Their Twisted Sequential Monte Carlo methods can be viewed as more advanced versions of our importance sampling methods. In contrast, in this work we focus on motivating the low probability estimation problem and introducing methods that do not involve searching for positive samples, such as activation extrapolation.

Finally, there is a large body of work applying adversarial training to improve worst-case model performance (Bai et al., ; Goodfellow et al., ; Ilyas et al., ), especially in the context of language models (Madry, ; Liu et al., ). Perez et al. () explores using language models themselves to aid in red-teaming other models. Latent adversarial training (Casper et al., ) generalizes standard adversarial training by optimizing over perturbations in activation space; this means that, like activation extrapolation methods, it can be effective even when the adversarial training search problem over input space is hard.

## 8 Conclusion

In this paper, we introduce the problem of low probability estimation along with four novel estimation methods. We define and collect ground-truth probabilities for $8$ different input distributions, then use them to evaluate the performance of our proposed methods. We find that the two importance sampling-based methods perform the best, with larger models favoring MHIS over ITGIS.

We are excited for future work that extends our empirical setup to non-independent input distributions and output behaviors that involve more than one token. We are also looking forward to future papers that develop more accurate estimation methods, especially methods like QLD that move beyond importance sampling.

## 9 Acknowledgements

Paul Christiano played a significant role in advising the project. We are grateful for intermediate theoretical contributions from David Matolsci and George Robinson. Thanks additionally to Jean-Stanislas Denain and Eric Neyman for feedback on a draft.

## Appendix A Input distributions

**Table 2: Definitions of input distributions.**
| Name | Tokens | Description |
| --- | --- | --- |
| hex | 33 | Tokens that consist solely of hexadecimal characters, weighted by their frequency in long, uniformly-random hexadecimal strings. |
| camel | 33 | Tokens that start with a capital letter, then have only lowercase letters, weighted by their frequency in Python code. |
| colon | 34 | Tokens weighted by frequency in Python code. Always ends with a colon. |
| if | 34 | Tokens weighted by frequency in Python code. Always starts with ‘ if’. |
| caps | 21 | Tokens that consist only of capital letters or punctuation, weighted by frequency in English text. Starts with ‘He screamed: "’ or ‘She screamed: "’. |
| english | 26 | Tokens that consist only of letters and start with a space, as well as punctuation. Weighted by frequency in English text. |
| spanish | 25 | Tokens that consist only of letters and spaces. Weighted by frequency in Spanish text. |
| icl | 29 | A simple in-context learning prompt of the form ‘A for _ R for _ C for _ … Y for _ ? for’, where the underscores are replaced with random tokens that start with the corresponding letter (weighted by frequency in English text), and the ? is replaced with a uniformly random letter. |

## Appendix B Full Estimation Algorithms

### i Algorithm for ITGIS

The algorithm for ITGIS is as follows. Initialize $s_{i}^{(0)}\equiv 0$ for all $i$ and a step counter $j=0$. Then, repeatedly:

- 1.
Increase the step counter $j$ by $1$.
- 2.
Compute the distribution $q^{(j-1)}$ as defined by the previous score function $s_{i}^{(j-1)}$. This can be explicitly computed as a list of $|\mathcal{V}|$ probabilities per token position.
- 3.
Draw a batch of samples from from $q^{(j-1)}$. Use the empirical mean of their gradient to estimate $\hat{s}_{i}^{(j)}(x_{i})=\operatorname{\mathbb{E}}_{{\mathbf{x}}^{\prime}\sim q
^{(j-1)}}[\nabla_{{\mathbf{x}}^{\prime}}M_{t}({\mathbf{x}}^{\prime})]_{i,x_{i}}$ for all $i\in[k],x_{i}\in\mathcal{V}$.
- 4.
Update the next $s_{i}^{(j)}$ for all $i$ according to an exponentially-weighted moving average:
$s_{i}^{(j)}=\frac{\hat{s}_{i}^{(j)}+\alpha\hat{s}_{i}^{(j-1)}+\dots+\alpha^{j-
1}\hat{s}_{i}^{(1)}}{1+\alpha+\alpha^{2}+\dots+\alpha^{j-1}}.$
In practice, we use $\alpha=0.9$.
- 5.
Calculate the average value of the importance sampling estimator $\frac{p({\mathbf{x}})}{q^{(j-1)}({\mathbf{x}})}\mathbbm{1}[M({\mathbf{x}})=t]$ for all samples in this batch.

The final output of the method is the average value of this importance sampling estimator across all batches. The number of batches and samples per batch is specified in Appendix F.

### ii Algorithm for MHIS

We define the proposal distribution $\phi(\cdot|{\mathbf{x}})$ to be the distribution induced by the following procedure:

- 1.
Choose a random token position $i\in[k]$ to modify.
- 2.
Calculate the gradient at that token $[\nabla_{{\mathbf{x}}}M_{t}({\mathbf{x}})]_{i}\in\mathbb{R}^{|\mathcal{V}|}$ (treating ${\mathbf{x}}=({\textnormal{x}}_{1},\dots,{\textnormal{x}}_{k})$ as a one-hot vector in $\mathbb{R}^{k\times|\mathcal{V}|}$). Call this gradient ${\mathbf{g}}$.
- 3.
Sample a replacement token ${\textnormal{x}}^{\prime}_{i}$ from the distribution proportional to
$p_{k}(x^{\prime}_{i})\cdot\exp\left(\frac{{\mathbf{g}}_{x^{\prime}_{i}}}{T}
\right).$
- 4.
Output ${\mathbf{x}}^{\prime}=({\textnormal{x}}_{1},\dots,{\textnormal{x}}^{\prime}_{i
},\dots,{\textnormal{x}}_{k})$.

Note that the transition probability in Metropolis–Hastings only depends on the ratio

$$ $\frac{q({\mathbf{x}}^{\prime})\phi({\mathbf{x}}|{\mathbf{x}}^{\prime})}{q({ \mathbf{x}})\phi({\mathbf{x}}^{\prime}|{\mathbf{x}})}=\frac{p_{i}({\textnormal {x}}_{i}^{\prime})}{p_{i}({\textnormal{x}}_{i})}\cdot\exp\left(\frac{M_{t}({ \mathbf{x}}^{\prime})-M_{t}({\mathbf{x}})}{T}\right)\cdot\frac{\phi({\mathbf{x }}|{\mathbf{x}}^{\prime})}{\phi({\mathbf{x}}^{\prime}|{\mathbf{x}})},$ $$

which is easy to compute given forwards and backwards passes at ${\mathbf{x}}$ and ${\mathbf{x}}^{\prime}$.

We use an initial burn-in period (see Appendix F) for the random walk before recording samples ${\mathbf{x}}^{(1)},\dots,{\mathbf{x}}^{(n)}$. The final output of the method is the empirical importance sampling estimate

$$ $\frac{1}{n}\sum_{j=1}^{n}\frac{p({\mathbf{x}}^{(j)})}{q({\mathbf{x}}^{(j)})} \mathbbm{1}[M({\mathbf{x}}^{(j)})=t].$ $$

This requires computing $q({\mathbf{x}})$, which involves the normalization constant. To save samples, we estimate the normalization constant using the identity:

$$ $\operatorname{\mathbb{E}}_{{\mathbf{x}}\sim p}\left[\exp\left(\frac{M_{t}({ \mathbf{x}})}{T}\right)\right]=\operatorname{\mathbb{E}}_{{\mathbf{x}}\sim q} \left[\exp\left(-\frac{M_{t}({\mathbf{x}})}{T}\right)\right]^{-1}.$ $$

The right-hand side can be estimated using the $n$ samples we already have from (approximately) $q$. In practice, the way we estimate the normalizing constant does not matter much (most of the error comes from other steps).

### iii Algorithm for QLD

Recall that ${\mathbf{v}}({\mathbf{x}})\in\mathbb{R}^{d}$ is the random vector representing the activations of the model right before the unembedding step. After collecting $n$ samples of ${\mathbf{v}}^{(1)},\dots,{\mathbf{v}}^{(n)}$, we compute their empirical mean ${\bm{\mu}}\in\mathbb{R}^{d}$ and covariance ${\bm{\Sigma}}\in\mathbb{R}^{d\times d}$. Then define ${\mathbf{u}}$ to be the whitened version of ${\mathbf{v}}$:

$$ $\displaystyle{\mathbf{u}}$ $\displaystyle:={\bm{A}}^{-1}({\mathbf{v}}-{\bm{\mu}})$ $\displaystyle{\mathbf{v}}$ $\displaystyle={\bm{A}}{\mathbf{u}}+{\bm{\mu}},$ $$

where ${\bm{A}}\in\mathbb{R}^{d\times d}$ is any matrix such that ${\bm{A}}{\bm{A}}^{\top}={\bm{\Sigma}}$. Note that ${\mathbf{u}}$ has mean 0 0 and covariance $\mathrm{Id}_{d}$. From now on, we principally work in this whitened representation of activation space, as it has the convenient property that the ${\mathbf{u}}\cdot{\bm{e}}$ and ${\mathbf{u}}\cdot{\bm{e}}^{\prime}$ are uncorrelated iff ${\bm{e}}$ and ${\bm{e}}^{\prime}$ are orthogonal.

We choose the unit vector ${\bm{d}}\in\mathbb{R}^{n}$ to point in the direction of the shortest accepting vector (Appendix D), then decompose our whitened samples ${\mathbf{u}}^{(1)},\dots,{\mathbf{u}}^{(n)}$ into components parallel and perpendicular to ${\bm{d}}$:

$$ $\displaystyle{\mathbf{a}}^{(i)}$ $\displaystyle:={\bm{d}}{\bm{d}}^{\top}{\mathbf{u}}^{(i)}$ $\displaystyle{\mathbf{b}}^{(i)}$ $\displaystyle:={\mathbf{u}}^{(i)}-{\mathbf{a}}^{(i)}.$ $$

Finally, we output:

$$ $\frac{1}{n^{2}}\left|\left\{(i,j)\in[n]^{2}\,\,\,\big{|}\,{\mathbf{a}}^{(i)}+{ \mathbf{b}}^{(j)}\in S\right\}\right|,$ $$

where

$$ $S:=\left\{{\bm{u}}\in\mathbb{R}^{d}\,\big{|}\,\operatorname{arg\,max}_{i}(({ \bm{A}}{\bm{u}}+{\bm{\mu}})\cdot{\bm{W}}_{U})_{i}=t\right\}.$ $$

This proportion can be computed in $\tilde{O}(n)$ time—we don’t need to explicitly iterate over all $n^{2}$ pairs. By the convexity of the acceptance region $S$, for any fixed ${\mathbf{b}}$ there is a single interval $[\ell,r]$ such that $a\in[\ell,r]\Leftrightarrow a{\bm{d}}+{\mathbf{b}}\in S$. We can efficiently compute the bounds of this interval for every sample ${\mathbf{b}}^{(j)}$ by solving a linear system of inequalities, and then we can calculate how many ${\mathbf{a}}^{(i)}$ fall into each range in $O(\log n)$ time after sorting. Thus, the computational cost of QLD is dominated by running $n$ forwards passes of $M$ to generate the samples ${\mathbf{u}}^{(1)},\dots,{\mathbf{u}}^{(n)}$.

## Appendix C Principles for choosing a decomposition in QLD

In this section, we justify the claim that we rely on the following two assumptions of the decomposition ${\mathbf{u}}={\mathbf{a}}+{\mathbf{b}}$ for QLD to perform well: 1) ${\mathbf{a}}$ and ${\mathbf{b}}$ are independent, and 2) the contribution towards the output behavior is split roughly equally between the two terms.

The first assumption is straightforward: if ${\mathbf{a}}$ and ${\mathbf{b}}$ are not independent, then ${\mathbf{a}}+{\mathbf{b}}^{\prime}$ (where ${\mathbf{b}}^{\prime}$ comes from an i.i.d. copy of ${\mathbf{u}}$) does not have the same distribution as ${\mathbf{u}}$. The failure of this assumption introduces bias into the estimation method. Working in whitened space ensures that ${\mathbf{a}}$ and ${\mathbf{b}}$ are uncorrelated, which is a first step towards independence.

The second assumption—that the contribution to the target behavior is roughly equally split between ${\mathbf{a}}$ and ${\mathbf{b}}$—is necessary for QLD to have an advantage over naive sampling. For purposes of illustration, say that $d=2$ (so that both ${\mathbf{a}}$ and ${\mathbf{b}}$ can be treated as scalars), and that ${\mathbf{a}},{\mathbf{b}}\stackrel{{\scriptstyle\mathrm{iid}}}{{\sim}}\mathcal
{N}(0,1)$. Then, consider three ways that the contribution to the target behavior could be split:

- •
Scenario 1 (no split): The target token is outputted iff ${\mathbf{a}}>10$. In this case, QLD provides no advantage over naive sampling, as the proportion of $({\mathbf{a}}^{(i)},{\mathbf{b}}^{(j)})$ pairs in the acceptance region is exactly the same as the proportion of $({\mathbf{a}}^{(i)},{\mathbf{b}}^{(i)})$ pairs. If $p$ is the probability of the behavior, then $p^{-1}$ samples are required to consistently obtain a positive estimate.
- •
Scenario 2 (even split): The target token is outputted iff ${\mathbf{a}}+{\mathbf{b}}>10\sqrt{2}$. In this case, QLD has a quadratic advantage over naive sampling. It only requires around $p^{-1/2}$ samples for QLD to consistently obtain a positive estimate.
- •
Scenario 3 (uneven split): The target token is outputted iff ${\mathbf{a}}+2{\mathbf{b}}>10\sqrt{5}$. The contribution here is split between ${\mathbf{a}}$ and ${\mathbf{b}}$, though not equally, so QLD’s efficiency falls in between the previous two scenarios. We can calculate that it requires around $p^{-5/9}$ samples for QLD to consistently obtain a positive estimate.(^7^77In general, if the condition is $\alpha{\mathbf{a}}+\sqrt{1-\alpha^{2}}{\mathbf{b}}>10$, it requires roughly $p^{-1/\left(\alpha+\sqrt{1-\alpha^{2}}\right)^{2}}$ samples.)

In practice, the condition for outputting the target token is more complex than a single linear constraint on ${\mathbf{a}}$ and ${\mathbf{b}}$. Nevertheless, these examples motivate the idea that the more evenly we can split contribution between two subspaces, the lower variance our estimator will have.

Given that ${\mathbf{b}}$ has $d-1$ dimensions while ${\mathbf{a}}$ only has $1$, most choices of ${\bm{d}}$ will end up giving ${\mathbf{b}}$ much more influence over the behavior than ${\mathbf{a}}$. This motivates us to identify a particularly important direction with ${\bm{d}}$; in some informal sense we want to find a direction that is “$d/2$ times more important” than the average direction.

## Appendix D Computing the Shortest Accepting Vector

Recall that the acceptance region $S\subseteq\mathbb{R}^{d}$ is the subset of whitened pre-unembed space that results in the model outputting $t$:

$$ $S:=\left\{{\bm{u}}\in\mathbb{R}^{d}\,\big{|}\,\operatorname{arg\,max}_{i}(({ \bm{A}}{\bm{u}}+{\bm{\mu}})\cdot{\bm{W}}_{U})_{i}=t\right\}.$ $$

We define ${\bm{d}}$ to point in the direction of the shortest vector in $S$, i.e., $\operatorname{arg\,min}_{{\bm{u}}\in S}\|{\bm{u}}\|$. This vector can be approximated using an iterative convex projection algorithm.

$S\subseteq\mathbb{R}^{d}$ is an intersection of $|\mathcal{V}-1|$ half-spaces $H_{1},\dots,H_{t-1},H_{t+1},\dots H_{\mathcal{V}}$, where $H_{i}$ represents the set of all activations (in whitened pre-unembed space) that result in the logit on token $t$ being larger than the logit on token $i$.

Given any convex set $C$ (such as a half-plane), the projection of ${\bm{x}}\notin C$ onto $C$ is $\operatorname{arg\,min}_{{\bm{x}}^{\prime}\in C}\|{\bm{x}}-{\bm{x}}^{\prime}\|
_{2}$. Given a collection of convex sets, there exists a simple algorithm for finding a point in their intersection: start with an arbitrary point ${\bm{x}}$, then repeatedly project ${\bm{x}}$ onto a random convex set that does not already contain ${\bm{x}}$. Eventually, this process converges to a point in their intersection (Gubin et al., ).

We apply this method to find an element of $S$. To ensure that it is the shortest element, we also project ${\bm{x}}$ onto balls centered at 0 0 with smaller and smaller radii by multiplying ${\bm{x}}$ by $0.99$. The exact procedure is described in Algorithm 1.(^8^88We found a few minor bugs in our implementation of the $\epsilon$-tolerance in our algorithm after we ran experiments, but we don’t expect them to have affected the results at all.) In practice, it always takes much less than $100\cdot n_{\text{reps}}$ steps for the algorithm to return a value.

Figure: Algorithm 1 Random Constraint Projection

## Appendix E Ground Truth Token Distribution

Figure: Figure 5: The ground truth probabilities of tokens for each distribution and model size, sorted from most to least probable (the height of the curve at position $x$ is the probability of the $x$-th most common token). Any tokens that appeared 0 0 times across all $2^{32}$ samples are not plotted.
Refer to caption: extracted/5932674/figures/gt_distrib.png

## Appendix F Computational Budgets

Each estimation method was given a budget of roughly $2^{16}$ model calls. More specifically:

- •
Independent Token Gradient Importance Sampling uses $2^{8}$ batches of size $2^{8}$, for a total of $2^{16}$ samples. The average gradient is updated after each batch. Note that this method requires backwards passes as well as forwards passes.
- •
Metropolis–Hastings Importance Sampling uses $2^{10}+2^{11}$ batches of size $2^{5}$, for a total of $1.5\cdot 2^{16}$ samples (the batch size indicates the number of independent random walks the method simulates). The first $2^{10}$ batches are used as a burn-in period for the random walk and are discarded, so only $2^{16}$ samples are actually used to calculate the estimate.
- •
Quadratic Logit Decomposition uses $n=2^{16}$ samples of the pre-unembed activation $\bf{v}$. The MLE direction is approximated with $n_{\text{reps}}=200$ iterations of the Random Constraint Projection algorithm (Appendix D); this makes up a trivial fraction of the total compute usage of the method).
- •
Gaussian Logit Difference uses $2^{16}$ samples of the logit difference to estimate $\mu$ and $\sigma$, the mean and standard deviation of the difference between the target logit and the maximum logit. Note that in practice, the $\mu$ and $\sigma$ can be accurately estimated with much fewer than $2^{16}$ samples.

In practice, ITGIS and MHIS take the longest to test because they require separate samples for each target token. In contrast, QLD reuses the same $2^{16}$ samples of $v$ for all $256$ target tokens associated with a given behavior.

## Appendix G All Method Performances

Table 3 shows the Itakura–Saito loss ($p/q-\ln(p/q)-1$) of all estimation methods on all input distributions and model sizes.

**Table 3: Itakura–Saito loss comparison of all methods, distributions, and model sizes.**
| Distribution | Constant | GLD | QLD | ITGIS | MHIS |
| --- | --- | --- | --- | --- | --- |
| hex | $2.5891$ | $2.2163$ | $2.0038$ | $2.0484$ | $1.3960$ |
| camel | $2.5908$ | $2.4419$ | $2.0648$ | $1.1997$ | $2.0187$ |
| colon | $2.7770$ | $2.7091$ | $1.2786$ | $1.2209$ | $1.0267$ |
| if | $2.2424$ | $2.1872$ | $1.2321$ | $1.0916$ | $1.4455$ |
| caps | $2.6619$ | $2.6147$ | $1.9413$ | $1.4788$ | $2.4023$ |
| english | $1.9095$ | $1.8120$ | $1.2409$ | $1.4539$ | $0.7017$ |
| spanish | $2.6079$ | $2.4463$ | $1.5628$ | $1.6396$ | $2.1538$ |
| icl | $2.5467$ | $2.4328$ | $2.2373$ | $0.7992$ | $1.2344$ |
| Average | $2.4906$ | $2.3575$ | $1.6952$ | $1.3665$ | $1.5474$ |

## Appendix H Squared Error in Log-Space

Figure 6 and Table 4 show the method performances when measured using squared error in log-space loss (i.e., $(\log p-\log q)^{2}$) instead of Itakura–Saito loss. The results are qualitatively identical using either metric. Note that we use separate affine fits to minimize each loss function—in Table 4 we naturally report the results of the fit corresponding to squared error in log-space. However, the importance sampling temperatures are not changed between the two metrics (they were tuned while minimizing Itakura–Saito loss).

Figure: Figure 6: The squared error in log-space loss of all methods across different model sizes. The solid lines indicate the loss of each method averaged over all $8$ distributions, with bands indicating standard error. The colored points indicate the loss on individual distributions, with horizontal jitter added for visibility.
Refer to caption: extracted/5932674/figures/MSE_all.png

**Table 4: Squared error in log-space loss comparison of all methods, distributions, and model sizes.**
| Distribution | Constant | GLD | QLD | ITGIS | MHIS |
| --- | --- | --- | --- | --- | --- |
| hex | $6.0093$ | $5.1815$ | $4.4863$ | $3.7179$ | $2.1963$ |
| camel | $7.7295$ | $6.4975$ | $5.8488$ | $1.5156$ | $4.3248$ |
| colon | $6.8554$ | $5.4361$ | $2.1379$ | $2.3549$ | $1.8061$ |
| if | $5.3977$ | $4.9287$ | $2.9356$ | $1.9555$ | $3.2223$ |
| caps | $8.0927$ | $7.5675$ | $4.1349$ | $3.2173$ | $6.5550$ |
| english | $6.0051$ | $5.3220$ | $3.2639$ | $1.8357$ | $1.6395$ |
| spanish | $5.7990$ | $5.5649$ | $2.9740$ | $2.1231$ | $4.2612$ |
| icl | $5.9035$ | $5.6915$ | $4.8023$ | $1.0222$ | $2.3030$ |
| Average | $6.4740$ | $5.7737$ | $3.8230$ | $2.2178$ | $3.2885$ |

## Appendix I Temperature Tuning

Both importance sampling methods require choosing a temperature parameter $T$. To tune $T$, we sweep over $9$ different temperatures from $0.2$ to $5$, uniformly spaced in log-space. We choose the value of $T$ that achieves the lowest loss on 100 randomly chosen tokens with ground-truth probabilities in the range $[10^{-5},10^{-3}]$ to prevent over-fitting. We tune separate temperatures for each distribution, model size, and importance sampling method, shown in Table 5. It is likely that spending more effort to tune these temperatures (e.g., by tuning on more and rarer tokens) would moderately improve the final performances of the importance sampling methods.

**Table 5: Temperatures $T$ used for the different methods.**
|  | 1 layer | 2 layers | 4 layers |  |  |  |
| --- | --- | --- | --- | --- | --- | --- |
| Distribution | ITGIS | MHIS | ITGIS | MHIS | ITGIS | MHIS |
| hex | 1.00 | 0.67 | 1.50 | 0.67 | 5.00 | 0.67 |
| camel | 1.00 | 2.24 | 1.50 | 2.24 | 1.00 | 2.24 |
| colon | 1.00 | 1.00 | 1.00 | 1.50 | 0.67 | 1.00 |
| if | 1.00 | 2.24 | 0.45 | 1.50 | 1.00 | 1.00 |
| caps | 1.50 | 3.34 | 0.45 | 1.50 | 0.67 | 1.00 |
| english | 0.45 | 1.50 | 0.67 | 2.24 | 0.45 | 1.50 |
| spanish | 0.67 | 2.24 | 0.67 | 2.24 | 1.00 | 2.24 |
| icl | 0.45 | 1.00 | 0.30 | 0.67 | 3.34 | 0.67 |

## Appendix J Plots of Method Outputs

Figures 7, 8, and 9 show the outputs of the four methods on all three model sizes, using log-log plots of ground-truth probability vs method output. All graphs show the outputs after the Itakura–Saito fit has been applied (see Section 4.2). The horizontal lines of points reveal the value of the additive constant in the fit; any outputs of 0 0 will all lie on this line after the fit is applied.

Figure: Figure 7: The outputs of methods, after a fit is applied, on all 256 tokens for each distribution on the 1-layer model. The horizontal axis represents the ground-truth token probability, while the vertical axis is the output of the model after a fit.
Refer to caption: extracted/5932674/figures/plots_1l_3x3.png

Figure: Figure 8: The outputs of methods, after a fit is applied, on all 256 tokens for each distribution on the 2-layer model. The horizontal axis represents the ground-truth token probability, while the vertical axis is the output of the model after a fit.
Refer to caption: extracted/5932674/figures/plots_2l_3x3.png

Figure: Figure 9: The outputs of methods, after a fit is applied, on all 256 tokens for each distribution on the 4-layer model. The horizontal axis represents the ground-truth token probability, while the vertical axis is the output of the model after a fit.
Refer to caption: extracted/5932674/figures/plots_4l_3x3.png

## Peer Reviews

confidence: 4
contribution: 4
initial_rating: 10
presentation: 4
questions: - Do you have preliminary thoughts or analysis on how these methods might scale to larger language models?
soundness: 3
strengths: - The paper has a novel framing of low probability estimation as a concrete approach to understanding and improving worst-case model performance.  It is the first paper to explore extrapolation-based methods that don't require finding explicit examples of rare behaviors.


- The best performing method presented in the paper, MHIS, is motivated using existing work in automated redteaming. By adapting the Greedy Coordinate Gradient technique (previously used for finding jailbreaks) into a proposal distribution for Metropolis-Hastings sampling, the paper shows how adversarial attack methods can be leveraged for low-probability estimation.  This innovative connection between adversarial attacks and probability estimation shows how existing attack methods can be repurposed for studying the probability of rare behaviors on the normal input distribution.
summary: This paper studies low-probability estimation - the problem of estimating the probability that model outputs will satisfy a certain criteria on inputs sampled from some distribution. The authors are primarily concerned with models/behaviors where the probability is hard to estimate empirically using unbiased samples from the input distribution, due to the event being rare.

More specifically, the authors study the task of estimating the percentage of inputs on which a transformer model predicts a certain token $t$ as being the most likely next token. Three methods are tested - two importance sampling methods, which leverage gradients with respect to the target logit, and an activation extrapolation method, which uses an empirical distribution over the final hidden states to estimate the probability that $t$ will have the highest logit.

The authors show that importance sampling methods currently dominate activation extrapolation on all tasks, but provide strong arguments for why they might be relevant in more complex models, where finding any particular input that gives rise to a behavior is computationally intractable.
weaknesses: - The models tested are small, and it's unclear whether these methods can be scaled up to actual models of interest.  However, the decision to use smaller models is justified, as it would be otherwise impossible to compute the true probability on all 2^32 input samples, which is necessary for measuring the performance of the methods.


- Given that adversarial training is stated as a part of the motivation for developing low probability estimation methods, there is a gap in the discussion around automated red teaming and adversarial training approaches for language models.  The related works section would benefit from an extended discussion on this area.  This context would help readers better understand how this work relates to and advances existing techniques for improving model robustness.

---

confidence: 2
contribution: 3
initial_rating: 6
presentation: 4
questions: Is there any concrete benefit that the proposed methods add to the overall motivation of minimizing adversarial outputs (ex. based on the activation extrapolation)?
soundness: 3
strengths: I am not familiar with prior work in this domain, but it appears as if the paper introduces novel methods for trying to estimate the probabilities of certain outputs given an input distribution.

Many intuitions are described in prose and are very clear/helpful:
- Why MHIS may be needed, why this is better for higher capacity models
- Why activation extrapolation methods could be better in certain scenarios.
- Why formally defined distribution can be relevant.

The experiments are sound and the results show that the proposed methods are clearly better than the naive sampling baseline.

Graphics are generally clear!
summary: This paper introduces methods for estimating the probability of sampling certain outputs when conditioned on an input distribution in cases where naive sampling is infeasible. Specifically, they introduce four methods (two based on importance sampling and two based on extrapolating model activations) for the special case where the input distribution is independent per token and the output is a single token.
weaknesses: To my understanding, the main motivation described for this problem stems from using these methods to reduce the probability of rare but undesirable outputs. Although a reasonable motivation, there are limited results in this direction because, as the authors point out, doing this for importance sampling reduces to adversarial training, and the activation extrapolation methods are currently worse than the importance sampling methods.
- A more thoroughly description of how you would do this for activation extrapolation methods would be good.

The current problem as formulated is restricted (ie. single token output detection) and not practically useful. However the authors recognize this, and I agree that it is a good first step.

The description of the activation extrapolation methods in the main text could be made more clear, for example the motivation for why the QLD directions could be summarized in the main text (without this, it is hard to understand the method).

Nits:
- Add lines of best fit for figure 1 and 3.

---

confidence: 4
contribution: 2
initial_rating: 3
presentation: 3
questions: Please see the weaknesses.
soundness: 3
strengths: - The paper is well written.
- The paper provides simple methods for low probability estimation in LLMs.
- Empirical results validate the working of their proposed methods (the importance sampling works better as shown by the authors).
summary: This work focus on probability estimation of low probability outputs in LLMs with argmax decoding. The paper explores the use of importance sampling and activation extrapolation for better estimate of these rare output events. The paper also provides experiments showing the relative performance of the various proposed algorithms.
weaknesses: - One major drawback I find is the lack of clear goal of the paper. The paper seems to provide some interesting algorithm for low probability estimation and high level discussion of how they can be used in practice. But there is no clear application or experiment that shows the usefulness of the contribution. I would urge the authors to kindly provide some clear applications and experiments to show its usefulness.

---

confidence: 3
contribution: 3
initial_rating: 6
presentation: 2
questions: In short, I believe this paper to be a good contribution to the community, providing a starting point to address the problem of rare output probability estimation. However, referencing the weaknesses above, I advise to address the following two points:

1) State more clearly that proposed methods are restricted in their applicability to different models and more complex scenario, in particular wrt the need to compute and propagate the gradient of the output probability.

2) detail more clearly the proposed strategies, ideally with pseudo-codes.
soundness: 3
strengths: The paper focuses on an important and, in my opinion, understudied problem of deep learning in general, which is estimating the probability of rare, but potentially catastrophic outputs in deep learning models, and by so doing also capturing the distribution of inputs that would cause them. As stated by the authors correctly, solving this problem is key in advancing adversarial training and even reinforcement learning in many settings.

The approaches tested are principled and thoroughly derived and, while limited in the current applicability (see weaknesses), provide a starting point for further studies and developments of new methods to quantify the probability of rare outputs and all its applications.
summary: The paper studies the problem of estimating the probabilities of rare outputs of transformer models. The authors explore two ways to estimate these probabilities: i) importance sampling and ii) activation extrapolation, which is more novel, but less effective. For each method, they propose two sub-strategies. Results show that importance sampling performs best at estimating the probability of rare outputs and both proposed methods perform better than random sampling.
weaknesses: Two main weaknesses:

1) The methods provided are quite limited in their application to larger models and real-world scenarios, and not just because the authors chose to test with small models, but also because the methods themselves perform computations that restrict their use. Specific points that introduce restrictions to be clarified:
a. The proposed method can only work with target behaviours defined as single token generation, i.e., define specific tokens that are considered rare for the next generation. This is quite limiting, as in language models target/dangerous behaviours are more often associated with semantic meaning of entire sentences and not with a single next token prediction, e.g., alignment for harmfulness.
b. Both methods involve computing the gradient of the rare token generation probability wrt the input tokens/sequence. This reinforces point a. above and further necessitates to have full access to the model, as we need to be able to compute this gradient and propagate it through the model, which is not trivial if the target behaviour is not simply a single specific token or the model is black-box.

2) The technical section describing the two method could be clearer. I suggest converting the point-by-point methods descriptions of supplementary B into pseudo-codes to make it clear what are the exact procedures to implement the different proposed methods and, if possible, put some of them in the main text. In the current form, the methods are given little space and I could not follow them without carefully reading supplementary B.

Meta-review: All four reviewers recognize the importance and novelty of the paper’s core problem: estimating low-probability (rare) outputs of language models on a formally-specified input distribution. This problem is non-trivial and has significant implications for understanding worst-case model behaviors, improving adversarial training, and enhancing the robustness of language models.

Key Strengths:
	1.	Novel Problem Framing: The paper articulates the problem of low probability estimation (LPE) in language models, providing a clear motivation and framing it as a critical step towards mitigating rare but harmful outputs. This viewpoint offers a useful alternative perspective to standard adversarial training.
	2.	Methods and Empirical Results: The authors propose and evaluate multiple approaches—two based on importance sampling and two based on activation extrapolation. Reviewers appreciate the introduction of activation extrapolation as a novel class of methods. Although importance sampling methods currently outperform activation extrapolation, both classes of methods outperform naive random sampling, demonstrating the relevance of the proposed techniques.
	3.	Thorough Empirical Evaluation: The paper grounds its theoretical claims in empirical evaluations on small transformer models, where the exact ground-truth probability of certain outputs can be computed. While this is a simplified setting, the experiments are well-designed, and results show that even these first-step methods significantly improve upon naive baselines.
	4.	Clarity and Presentation Improvements: The authors have addressed reviewers’ requests by adding more discussion (e.g., on Latent Adversarial Training), incorporating pseudocode in the appendix, and clarifying the limitations and potential future directions.

Decision: Accept (Spotlight)