Venue: NAACL 2021

# Limitations of Autoregressive Models and Their Alternatives

 Chu-Cheng Lin\({}^{\sharp*}\) Aaron Jaech\({}^{\flat}\) Xin Li\({}^{\sharp}\) Matthew R. Gormley\({}^{\ddagger}\) Jason Eisner\({}^{\sharp}\)

\({}^{\sharp}\)Department of Computer Science, Johns Hopkins University

\({}^{\flat}\)Facebook AI

\({}^{\natural}\)Machine Learning Department, Carnegie Mellon University

{kitsing,lixints,jason}@cs.jhu.edu ajaech@fb.com mgormley@cs.cmu.edu

Part of this work was done at Facebook AI.

###### Abstract

Standard autoregressive language models perform only polynomial-time computation to compute the probability of the next symbol. While this is attractive, it means they cannot model distributions whose next-symbol probability is _hard_ to compute. Indeed, they cannot even model them well enough to solve associated _easy_ decision problems for which an engineer might want to consult a language model. These limitations apply no matter how much computation and data are used to train the model, unless the model is given access to oracle parameters that grow _superpolynomially_ in sequence length. Thus, simply training larger autoregressive language models is not a panacea for NLP. Alternatives include energy-based models (which give up efficient sampling) and latent-variable autoregressive models (which give up efficient scoring of a given string). Both are powerful enough to escape the above limitations.

## 1 Introduction

Sequence modeling is a core NLP problem. Many sequence models \(\tilde{p}\) are efficient at _scoring strings_: given a string **x**, its score \(\tilde{p}(\textbf{x})\) can be computed in \(O(\text{poly}(|\textbf{x}|))\). For example, an RNN Mikolov et al. (2011) scores **x** in time \(O(|\textbf{x}|)\) while a Transformer Vaswani et al. (2017) does so in time \(O(|\textbf{x}|^{2})\). The score may be an unnormalized probability, and can be used to rank candidate strings.

Many sequence models also make it easy to compute marginal properties of \(\tilde{p}\). They support efficient _sampling_ of strings **x** (which allows unbiased approximation of marginal expectations). And they support efficient computation of the _normalizing constant_\(Z=\sum_{\textbf{x}}\tilde{p}(\textbf{x})\) (or simply guarantee \(Z=1\)) for any value of the model parameters.

How about training? Briefly: If a sequence model can efficiently compute \(\tilde{p}(\textbf{x})\) (and its derivatives with respect to model parameters), then it is efficient to compute parameter updates for noise-contrastive estimation Gutmann and Hyvarinen (2010); Gutmann and Hyvarinen (2012) or score-matching Hyvarinen (2005). If sampling **x** or computing \(Z\) (and its derivatives) is _also_ efficient, then it is efficient to compute parameter updates for ordinary MLE training.

Finally, popular sequence models are _compact_. Usually a fixed-size model is used to score strings **x** of all lengths. More generally, it might be reasonable to use an \(O(\text{poly}(n))\)-sized parameter vector \(\boldsymbol{\theta}_{n}\) when **x** has length \(n\), at least if parameter vectors can be obtained (perhaps from an oracle) for all needed lengths. In this paper, we investigate what can and cannot be achieved with models that are compact in this sense. This setup allows us to discuss the asymptotic behavior of model families.

**Standard autoregressive models** have the form \(p(\textbf{x})=\prod_{t}p(x_{t}\mid\mathbf{s}_{<t})\)1 where each factor is efficient

Figure 1: Valid answers to hard natural language inference problems can be hard to find Munroe (2009), but in many cases can be checked efficiently (the Knapsack problem in the comic). Given a _large enough_ parametric autoregressive model with _correct_ parameters, we can efficiently solve _all_ problem instances with input length \(n\), and efficiently verify the solutions —but the required model size can grow superpolynomially in \(n\). (This allows the model to store precomputed results that we can look up in \(O(n)\) at test time.) A main observation of this paper is that assuming NP \(\not\subseteq\) P/poly, then without such a superpolynomial growth in model size, autoregressive models cannot even be used to verify answers to some problems where polynomial-time verification algorithms do exist.



to compute from a fixed parameter vector. These models satisfy all three of the desiderata above. By using flexible neural network architectures, standard autoregressive models have achieved stellar empirical results in many applications (Oord et al., 2016; Child et al., 2019; Zellers et al., 2019; Brown et al., 2020). However there are still tasks that they have not mastered: _e.g._, it is reported that they struggle at deep logical structure, even when initialized to huge pretrained models (Wang et al., 2019a).

We point out that, unfortunately, there are certain sequence distributions whose unnormalized string probabilities \(\tilde{p}(\mathbf{x})\) are _easy_ to compute individually, yet whose autoregressive factors \(p(x_{t}~{}|~{}\mathbf{x}_{<t})\) are NP-_hard_ to compute or even approximate, or are even _uncomputable_. Thus, standard autoregressive models are _misspecified_ for these distributions (cannot fit them). It does not help much to focus on strings of bounded length, or to enlarge the model: under the common complexity-theoretic assumption \(\text{NP}\not\subseteq\text{P/poly}\), the parameter size \(|\boldsymbol{\theta}_{n}|\) must grow _superpolynomially_ in \(n\) to efficiently approximate the probabilities of all strings of length up to \(n\).

Indeed, one of our main findings is that there exist unweighted languages \(L\in\text{P}\) for which _no_ standard autoregressive model has \(L\) as its support, _i.e._, assigns weight \(>0\) to just the strings \(\mathbf{x}\in L\). This is downright depressing, considering the costs invested in training huge parametric autoregressive models (Bender et al., 2021). Since \(L\in\text{P}\), it is trivial to build an efficient scoring function \(\tilde{p}(\mathbf{x})\) with fixed parameters that has \(L\) as its support -- just not an autoregressive one. The problem holds for _all_ standard autoregressive models, regardless of how much computation and training data are used to learn the model parameters.

That is, for an NP-hard problem, scoring a string \(\mathbf{x}\) under a standard autoregressive model \(p(\mathbf{x})\) cannot be used to _verify_ a witness. Nor can _finding_ a witness be solved by prompting such a model with a description of a problem instance and sampling a continuation \(\mathbf{x}\) of that string. Such problems are abundant in NLP: for example, surface realization under Optimality Theory (Idsardi, 2006), decoding text from an AMR parse (Cai and Knight, 2013), phrase alignment between two sentences (DeNero and Klein, 2008), and in general inference for propositional logic (Cook, 1971), which underlies the NP-hardness of general natural language inference, as in Figure 1. In other words, our results imply that standard autoregressive models do not have the right structure to capture important linguistic regularities: _e.g._, that observed sequences were _in fact_ constructed to be phonologically optimal, expressive of a semantic form, or logically coherent!

Our work is also relevant to autoregressive models of fixed-dimensional vectors, such as NADE (Uria et al., 2016). These can be extended to arbitrary \(n\)-dimensional vectors by providing separate parameters \(\boldsymbol{\theta}_{n}\) for each \(n\). Our constructions imply that for some distributions, \(|\boldsymbol{\theta}_{n}|\) must grow superpolynomially in \(n\), even though this would be not be necessary if the models were not autoregressive.

In the remainder of this paper, we formalize our three desiderata for sequence models. We formalize compact autoregressive models and describe some limitations on their expressiveness. We then show that it can help to choose an alternative model family that relaxes any one of the three desiderata (Table 1).

## 2 Background

### Weighted languages

An **unweighted language**\(L\subseteq V^{*}\) is a set of strings \(\mathbf{x}\) over a finite alphabet \(V\). A **weighted language**\(\tilde{p}\) is a function \(\tilde{p}:V^{*}\rightarrow\mathbb{R}_{\geq 0}\). It may be regarded as specifying an unweighted language \(L=\operatorname{support}(\tilde{p})\triangleq\left\{\mathbf{x}:\tilde{p}( \mathbf{x})\neq 0\right\}\) along with positive weights for the strings in \(L\). We say that a weighted language \(\tilde{p}\) is **normalizable** if its **global normalizing constant**\(Z\triangleq\sum_{\mathbf{x}\in V^{*}}\tilde{p}(\mathbf{x})\) is finite and strictly positive. When \(\tilde{p}\) is normalizable, \(p(\mathbf{x})\triangleq\tilde{p}(\mathbf{x})/Z\) is a probability distribution over \(L\). A **distribution** is any weighted language whose global normalizing constant is 1.

Let \(\hat{\mathbf{x}}\leq\mathbf{x}\) mean that \(\hat{\mathbf{x}}\) is a prefix of \(\mathbf{x}\in V^{*}\) (not necessarily a strict prefix). If \(\tilde{p}\) is normalizable, then \(Z(\hat{\mathbf{x}})\triangleq\sum_{\mathbf{x}\in V^{*}:\hat{\mathbf{x}}\leq \mathbf{x}}\tilde{p}(\mathbf{x})\) is \(\leq Z\) for any \(\hat{\mathbf{x}}\in V^{*}\), yielding a marginal **prefix probability**\(Z(\hat{\mathbf{x}})/Z\). If the prefix \(\hat{\mathbf{x}}\) has positive prefix probability, then it admits a **local conditional probability**\(p(x~{}|~{}\hat{\mathbf{x}})\triangleq Z(\hat{\mathbf{x}}\,x)/Z(\hat{\mathbf{ x}})\) for each symbol \(x\in V\), where the

\begin{table}
\begin{tabular}{l c c c l} \hline \hline Model family & Compact & Efficient & Efficient sampling & Support can be ... \\  & parameters? & scoring? & and normalization? & \\ \hline ELN/ELNCP: Autoregressive models (§3.1) & ✓ & ✓ & ✓ & _some but not all_\(L\in\text{P}\) \\ EC/ECCP: Energy-based models (§4.1) & ✓ & ✓ & ✗ & _all_\(L\in\text{P}\) but _no_\(L\in\text{NPC}\) \\ Lightly marginalized ENCP: Latent-variable autoregressive models (§4.2) & ✓ & ✗ & ✓ & _all_\(L\in\text{NP}\) \\ Lookup models (§4.3) & ✗ & ✓ & ✓ & _anything_ \\ \hline \hline \end{tabular}
\end{table}
Table 1: A feature matrix of parametric model families discussed in this paper. Also see Figure 2 in the appendices.

 

denominator is interpreted as a **local normalizing constant**. This is the conditional probability that if a random string starts with the prefix \({\bf\hat{x}}\), the next symbol is \(x\). There is also a probability \(p\left({\bf\hat{s}}~{}|~{}{\bf\hat{x}}\right)\triangleq 1-\sum_{x\in V}\, p\left(x~{}|~{}{\bf\hat{x}}\right)=\tilde{p}\left({\bf\hat{x}}\right)/Z \left({\bf\hat{x}}\right)\geq 0\) that the string ends immediately after \({\bf\hat{x}}\); the special symbol \({\bf\hat{s}}\not\in V\) represents "end of string."

### Computation for weighted languages

We define a weighted language \(\vec{p}\) to be **computable** if it is defined by a Turing machine (also called \(\vec{p}\)) that maps any \({\bf x}\in V^{*}\) to \(\vec{p}\left({\bf x}\right)\in\mathbb{Q}_{\geq 0}\) in finite time. The Turing machine does not have to compute \(Z\).

While the computable weighted languages allow any computable function as \(\vec{p}\), most architectures for defining weighted languages (RNNs or Transformers) do only a bounded or linear amount of work per input symbol. As a result, they compute \(\vec{p}({\bf x})\) in time \(O\left(\operatorname{poly}(|{\bf x}|)\right)\) (that is, \(\vec{p}\in\text{FP}\)). We refer to such weighted languages as **efficiently computable** (**EC**). This does not imply that the normalized version \(p\) is efficiently computable, since finding the denominator \(Z\) requires summing over all of \(V^{*}\).

If we tried to construct the same normalized distribution \(p\) as in the previous paragraph using a standard autoregressive model, we would model it as a product of local conditional probabilities, \(p\left({\bf x}\right)=(\prod_{t=1}^{|{\bf x}|}p\left(x_{t}~{}|~{}{\bf x}_{<t} \right))p\left({\bf\hat{s}}~{}|~{}{\bf x}\right)\). Most such architectures again do only a bounded or linear amount of work per input symbol. Yet one suspects that this may not always be enough work to do the job: the local conditional probabilities of the original \(\vec{p}\) are expensive to compute (unless \(\vec{p}\) has some special structure making \(Z\left({\bf\hat{x}}\right)\) tractable).

Indeed, the observation of this paper is that for some efficiently computable weighted languages \(\vec{p}\), the local conditional probabilities are expensive to compute or even to approximate well. More precisely, autoregressive models cannot fit the local conditional probabilities unless they are superpolynomial in either their runtime or in their number of parameters (where the parameters may be precomputed at training time). We now explain how to formalize these notions.

### Non-uniform computation

In the machine learning approach to sequence modeling, we usually do not manually design the Turing machine behind \(\vec{p}\). Rather, we design a model \(M\) with _parameters_\(\mathbf{\theta}\). \(M\) is a Turing machine that reads \(\mathbf{\theta}\) and outputs a specialized Turing machine \(\vec{p}_{\mathbf{\theta}}\triangleq M(\mathbf{\theta})\) that can score strings \({\bf x}\) and hence defines a weighted language. Without loss of generality, we will express \(\mathbf{\theta}\) as a string in \(\mathbb{B}^{*}\) (where \(\mathbb{B}\triangleq\{0,1\}\)). For each \(\mathbf{\theta}\), we obtain a potentially different weighted language.

Strings vary in length, and accurate modeling of longer strings may sometimes require more complex computations with more parameters. For example, when \(V\) is a natural language alphabet, a recurrent neural network may require more hidden units to model sentences of the language rather than individual words, and even more units to model whole documents. To accommodate this, we allow an _infinite sequence_ of parameter vectors, which yields an infinite sequence of Turing machines \(\{\vec{p}_{n}~{}|~{}n\in\mathbb{N}\}\) via \(\vec{p}_{n}\triangleq M(\mathbf{\theta}_{n})\). We then define \(\vec{p}_{\mathbf{\Theta}}({\bf x})\triangleq\vec{p}_{|{\bf x}|}({\bf x})\), so a string of length \(n\) is scored by the \(\vec{p}_{n}\) machine. This is known as **non-uniform computation**. Of course, it is legal (and common) for all of the \(\mathbf{\theta}_{n}\) to be equal, or empty, but if desired, we can obtain more power by allowing the number of parameters to grow with \(n\) if needed.

We can now consider _how rapidly_ the parametric and runtime complexity may grow.

* If \(|\mathbf{\theta}_{n}|\) is permitted to grow exponentially, then one can fit _any_ weighted language \(\vec{p}\) (even an uncomputable one).2 Simply use \(\mathbf{\theta}_{n}\) to encode a trie with \(O\left(|V|^{n+1}\right)\) nodes that maps \({\bf x}\mapsto\tilde{p}({\bf x})\) for any \(|{\bf x}|\) of length \(n\), and design \(M\) such that the Turing machine \(\tilde{p}_{n}=M(\mathbf{\theta}_{n})\) has a (large) state transition table that mirrors the structure of this trie. The resulting collection of Turing machines \(\{\vec{p}_{n}~{}|~{}n\in\mathbb{N}\}\) can then compute \(\tilde{p}({\bf x})\) exactly for any \({\bf x}\), with only linear runtime \(O\left(|{\bf x}|\right)\) (which is used to traverse the trie). Footnote 2: See our remark on computability in Appendix A.
* Separately, if unbounded runtime is permitted for \(M\), then one can exactly fit _any computable_ weighted language \(\tilde{p}\). Simply have \(M\), when run on \(\mathbf{\theta}_{n}\), _compute_ and return the large trie-structured \(\tilde{p}_{n}\) that was mentioned above. In this case, \(M\) need not even use the parameters \(\mathbf{\theta}_{n}\), except to determine \(n\).
* Finally, if unbounded runtime is permitted for \(\tilde{p}_{n}\), then again one can exactly fit _any computable_ weighted language \(\tilde{p}\). In this case, \(M\) trivially returns \(\tilde{p}_{n}=\tilde{p}\) for all \(n\).
* However, if the parameters \(\mathbf{\Theta}\) are "compact" in the sense that \(|\mathbf{\theta}_{n}|\) grows only as \(O\left(\operatorname{poly}(n)\right)\), and also \(\tilde{p}_{n}=M(\mathbf{\theta}_{n})\) is constructed by \(M\) in time \(O\left(\operatorname{poly}(n)\right)\), and \(\tilde{p}_{n}\) scores any \({\bf x}\) of length \(n\) in time \(O\left(\operatorname{poly}(n)\right)\), then we say that the resulting weighted language \(\tilde{p}\) is **efficiently computable with compact parameters** (ECCP).3 

to \(M\) paired with a parameter space of possible compact values for \({\mathbf{\Theta}}\) as an **ECCP model**.

Neural models of weighted languages are typically ECCP models. The construction and execution of the neural network \(\tilde{p}_{n}\) may perform a polynomial amount of total computation to score the string \({\bf x}\). This computation may involve parameters that were precomputed using any amount of effort (, training on data) or even obtained from an oracle (they need not be computable). However, the exponentially many strings of length \(n\) must share a polynomial-size parameter vector \({\mathbf{\theta}}_{n}\), which prevents the solution given in the first bullet point above.

In practice one takes \({\mathbf{\theta}}_{n}={\mathbf{\theta}}\) for all \(n\) and obtains \({\mathbf{\theta}}\in\mathbb{R}^{d}\) by training. However, we do not consider whether such parameters are easy to estimate or even computable. We simply ask, for a given target language \(\tilde{p}\), whether there _exists_ a polynomially growing sequence \({\mathbf{\Theta}}\) of "good" parameter vectors for any parametric model \(M\). When not, there can be no scheme for estimating arbitrarily long finite prefixes of such a sequence. So for any polynomial \(f\), any training scheme that purports to return a trained model of size \(f(n)\) that works "well" for strings of length \(\leq n\) must fail for large enough \(n\) -- even if unlimited data, computation, and oracles are allowed at training time.

### P, \({\rm P/poly}\), and \({\rm NP/poly}\)

The phrase "efficiently computable with compact parameters" means that without access to those parameters, the ECCP weighted language may no longer be efficiently computable. Indeed, it need not be computable at all, if the parameter vectors store the outputs of some uncomputable function.

Our definitions above of EC and ECCP weighted languages are weighted generalizations of complexity classes \({\rm P}\) and \({\rm P/poly}\), respectively,4 and their supports are always unweighted languages in \({\rm P}\) and \({\rm P/poly}\), respectively. An unweighted language \(L\) is in \({\rm P}\) iff there is a deterministic Turing machine that decides in \(O\left(\operatorname{poly}(|{\bf x}|)\right)\) time whether \({\bf x}\in L\). And an unweighted language \(L^{\prime}\) is in \({\rm P/poly}\) iff5 there exist linearised runtime model for inputs of length \(n\). Our Turing machines in \(O\left(\operatorname{poly}(n)\right)\) time whether \({\bf x}\) of length \(n\) is in \(L^{\prime}\), where each \(M_{n}\) can be constructed in \(O\left(\operatorname{poly}(n)\right)\) time as \(M({\mathbf{\theta}}_{n})\), for some Turing machine \(M\) and some sequence of polynomially-sized **advice strings**\({\mathbf{\Theta}}=\{{\mathbf{\theta}}_{n}~{}|~{}n\in\mathbb{N}\}\) with \(|{\mathbf{\theta}}_{n}|\in O\left(\operatorname{poly}(n)\right)\). We define the language class \({\rm NP/poly}\) similarly to \({\rm P/poly}\): the only difference is the family \(\{M_{n}:n\in\mathbb{N}\}\) consists of _nondeterministic Turing machines_.

Footnote 4: Namely the nonnegative functions in \({\rm FP}\) and \({\rm PP/poly}\).

Naturally, \({\rm P}\subseteq{\rm P/poly}\). But \({\rm P/poly}\) is larger than \({\rm P}\): it contains all sparse languages, regardless of their hardness -- even sparse undecidable languages -- as well as many dense languages. The extra power of \({\rm P/poly}\) comes from its access to compact advice strings that do not have to be recursively enumerable, let alone efficient to find. This corresponds to statistical modeling, where the trained model has a computationally efficient architecture plus access to parameters that might have taken a long time to find.

### \({\rm NP}\)-completeness and Sat

NP-complete decision problems have solutions that are efficient to validate but inefficient to find (assuming \({\rm P}\neq{\rm NP}\)). One of the most well-known NP-complete problems is the boolean satisfiability problem [1]. Given a boolean formula \(\phi\), Sat accepts \(\phi\) iff \(\phi\) can be satisfied by some value assignment. For example, the formula \((A_{1}\vee\neg A_{2}\lor A_{3})\wedge(A_{1}\vee\neg A_{4})\) is in Sat, since there is a satisfying assignment \(A_{1\ldots 4}=\mathbf{1101}\). We denote the number of satisfying assignments to \(\phi\) as \(\#(\phi)\).

It is widely believed that no NP-complete languages are in \({\rm P/poly}\). Otherwise we would have all of \({\rm NP}\subseteq{\rm P/poly}\) and the polynomial hierarchy would collapse at the second level [8].

A capacity limitation of EC/ECCP weighted languages naturally follows from this belief:6

Footnote 6: All omitted proofs are in Appendix A.

Lemma 1: _For any \(L\in{\rm P}\), there exists an EC weighted language with support \(L\). For any \(L\in{\rm P/poly}\), there exists an ECCP language with support \(L\). But for any \(L\in{\rm NP}\)-complete, there exists no ECCP language with support \(L\) (assuming \({\rm NP}\not\subset{\rm P/poly}\))._

In addition to not capturing the support of NP-complete languages, ECCP weighted languages can 

not help solve other NP-hard problems, either. For example, many structured prediction problems in NLP can be formulated as \(\operatorname*{argmax}_{\mathbf{x}:\hat{\mathbf{z}}\leq\mathbf{x}}\tilde{p}( \mathbf{x})\): we are given a prefix \(\hat{\mathbf{x}}\) as input and look for its optimal continuation under \(\tilde{p}\). But if this problem is NP-hard for a particular \(\tilde{p}\), then it is not in P/poly (assuming NP \(\not\subseteq\text{P/poly}\)), so it cannot be accomplished by any polytime algorithm that queries an ECCP model.

## 3 Autoregressive ECCP models (ELNCP models) have reduced capacity

In this section we formally define _autoregressive_ECCP models, and prove that they have strictly less capacity than general ECCP models or even just EC models. Our proofs rely on the construction of a EC model \(\tilde{p}\) where computing the local conditional probabilities \(p(x\mid\hat{\mathbf{x}})\) is NP-hard, so they cannot be computed with compact parameters, if NP \(\not\subseteq\text{P/poly}\).

### ELN and ELNCP models

Many parameter estimation techniques and inference methods specifically work with local conditional probabilities \(p(x\mid\hat{\mathbf{x}})\). Thus, it is common to use parametric models where such quantities can be computed in time \(O(\operatorname{poly}(|\hat{\mathbf{x}}|))\) (given the parameters).7 These are the "standard autoregressive models" we discussed in SS1. We say that the resulting distributions are **efficiently locally normalizable**, or **ELN**.

Footnote 7: An autoregressive model architecture generally defines \(p(\mathbf{x})\) as an efficiently computable (§2.2) product of local conditional probabilities. However, the parametrization usually ensures only that \(\sum_{x\in V}p_{\boldsymbol{\theta}}(x\mid\hat{\mathbf{x}})=1\) for all prefixes \(\hat{\mathbf{x}}\). Some parameter settings may give rise to **inconsistent** distributions where \(Z\triangleq\Sigma_{\mathbf{x}\in V^{*}}\cdot p_{\boldsymbol{\theta}}(\mathbf{x})<1\) because the generative process terminates with probability \(<1\)[4]. In this case, the factors \(p_{\boldsymbol{\theta}}(x\mid\hat{\mathbf{x}})\) defined by the autoregressive model are not actually the conditional probabilities of the weighted language (as defined by §2.1). It is true that training \(\boldsymbol{\theta}\) with a likelihood objective does encourage finding a weighted language whose generative process always terminates (hence \(Z=1\)), since this is the behavior observed in the training corpus [5, 6, 8]. Our definitions of ELN(CP) models require the _actual_ conditional probabilities to be efficiently computable. Autoregressive models that do not sum to 1, whose normalized probabilities can be uncomputable, are not ruled out by our theorems that concern ELN(CP).

* \(q_{n}\) runs on those inputs \(\hat{\mathbf{x}}x\) in time \(O(\operatorname{poly}(n))\) If there is \(M^{9}\) that efficiently locally normalizes a weighted language \(\tilde{p}\) with compact parameters \(\Theta^{\mathfrak{q}}\), we say \(\tilde{p}\) is **efficently locally normalizable with compact parameters**, or **ELNCP**. Note that this is a property of the weighted language itself. In this case, it is obvious that \(\tilde{p}\) is ECCP:

Lemma 2: _An ELNCP model \(\tilde{p}\) is also ECCP. Likewise, an ELN model is also EC._

If we define ELNCP _models_ analogously to ECCP models, Lemma 2 means that locally normalized models do not provide any extra power. Their distributions can always be captured by globally normalized models (of an appropriate architecture that we used in the proof). But we will see in Theorem 1 that the converse is likely not true: provided that NP \(\not\subseteq\text{P/poly}\), there are efficiently computable weighted languages that cannot be efficiently locally normalized, even with the help of compact parameters. That is, they are EC (hence ECCP), yet they are not ELNCP (hence not ELN).

### ELNCP models cannot exactly capture all EC (or ECCP) distributions

We reducing Sat to computing certain local conditional probabilities of \(\tilde{p}\) (as defined in SS2.1). Each decision Sat\((\phi)\) (where \(\phi\) ranges over formulas) corresponds to a particular local conditional probability, implying that there is no polytime scheme for computing all of these probabilities, even with polynomially sized advice strings (_i.e._, parameters).

Without loss of generality, we consider only formulae \(\phi\) such that the set of variables mentioned at least once in \(\phi\) is \(\{A_{1},\ldots,A_{j}\}\) for some \(j\in\mathbb{N}\); we use \(|\phi|\) to denote the number of variables \(j\) in \(\phi\). We say that **a satisfies**\(\phi\) if \(\textbf{a}\in\mathbb{B}^{|\phi|}\) and \((A_{1}=a_{1},\dots,A_{|\phi|}=a_{|\phi|})\) is a satisfying assignment. Finally, let boldface \(\boldsymbol{\phi}\in\mathbb{B}^{+}\) denote enc\((\phi)\) where enc is a prefix-free encoding function. We can now define the unweighted language \(L=\{\boldsymbol{\phi}\textbf{a}\mid\phi\mbox{ is a formula and }\textbf{a}\in\mathbb{ B}^{|\phi|}\mbox{ and }\textbf{a}\mbox{ satisfies }\phi\}\) over alphabet \(\mathbb{B}\), which contains each possible Sat problem concatenated to each of its solutions.8

Footnote 8: For example, \(L\) contains the string \(\boldsymbol{\phi}\textbf{a}\) where \(\boldsymbol{\phi}=\text{enc}((A_{1}\vee\neg A_{2}\lor A_{3})\wedge(A_{1}\lor \neg A_{4}))\) and \(\textbf{a}=11\mathbbm{0}1\).

We now convert \(L\) to a weighted language \(\tilde{p}\), defined by \(\tilde{p}(\textbf{x})=\tilde{p}(\boldsymbol{\phi},\textbf{a})=(\frac{1}{3})^{| \textbf{x}|+1}\) for \(\textbf{x}\in L\) (otherwise \(\tilde{p}(\textbf{x})=0\)). \(\tilde{p}\) is normalizable since \(Z\) is both finite (\(Z=\sum_{\textbf{x}\in\mathbb{B}^{+}}\tilde{p}(\textbf{x})\leq\sum_{\textbf{x} \in\mathbb{B}^{+}}(\frac{1}{3})^{|\textbf{x}|+1}=1\)) and positive (\(Z>0\) because the example string in footnote 8 has weight \(>0\)). The conditional distribution 

\(p\left({\bf a}~{}|~{}\mathbf{\phi}\right)\) is uniform over the satisfying assignments \({\bf a}\) of \(\mathbf{\phi}\), as they all have the same length \(|\phi|\).

\(\tilde{p}\) is efficiently computable, and so is \(p=\tilde{p}/Z\).9 Yet deciding whether the local conditional probabilities of \(\tilde{p}\) are greater than 0 is NP-hard. In particular, we show that Sat can be reduced to deciding whether certain local probabilities are greater than 0, namely the ones that condition on prefixes \(\hat{\mathbf{x}}\) that consist only of a formula: \(\hat{\mathbf{x}}=\mathbf{\phi}\) for some \(\phi\). This implies, assuming \(\mathrm{NP}\nsubseteq\mathrm{P}/\text{poly}\), that no \((M^{q},\mathbf{\Theta}^{q})\) can efficiently locally normalize \(\tilde{p}\) with compact parameters. Granted, the restriction of \(\tilde{p}\) to the finite set \(\{\mathbf{x}\in\mathbb{B}^{*}:|\mathbf{x}|\leq n\}\) can be locally normalized by some polytime Turing machine \(q_{n}\), using the same trie trick sketched in SS2.3. But such tries have sizes growing exponentially in \(n\), and it is not possible to produce a sequence of such machines, \(\{q_{n}:n\in\mathbb{N}\}\), via a single master Turing machine \(M^{q}\) that runs in \(O\left(\text{poly}(n)\right)\) on \(\mathbf{\theta}^{q}_{n}\). That is:

Footnote 9: Almost. This Z could be irrational, but at least it is computable to any desired precision. For any rational \(\tilde{Z}\approx Z\), we can say \(\tilde{p}=\tilde{p}/\hat{Z}\approx p\) is EC, via a Turing machine \(M^{\bar{q}}\) that stores \(\hat{Z}\). Further remarks on irrationality appear in Appendix A.

**Theorem 1**.: _Assuming \(\mathrm{NP}\nsubseteq\mathrm{P}/\text{poly}\), there exists an efficiently computable normalizable weighted language \(\tilde{p}\) that is not ELNCP._

Proof sketch.: Take \(\tilde{p}\) to be the weighted language we defined earlier in this section. \(\tilde{p}\) is clearly efficiently computable. We will show that if it is ELNCP via \((M^{q},\mathbf{\Theta}^{q})\), then the NP-complete problem Sat is in \(\mathrm{P}/\text{poly}\), contradicting the assumption. We must give a method for using \((M^{q},\mathbf{\Theta}^{q})\) to decide Sat in polytime and with compact parameters \(\mathbf{\Theta}\). Given \(\phi\), our method constructs a simple related formula \(\phi^{\prime}\) such that

* \(\phi^{\prime}\) has at least one satisfying assignment (so \(Z(\mathbf{\phi}^{\prime})>0\) and thus \(p\left({\bf 1}~{}|~{}\mathbf{\phi}^{\prime}\right)\) is defined)
* \(\phi^{\prime}\) has satisfying assignments with \(A_{1}={\bf 1}\) (_i.e._, \(p\left({\bf 1}~{}|~{}\mathbf{\phi}^{\prime}\right)>0\)) if and only if \(\phi\) is satisfiable Our construction also provides a polynomial function \(f\) such that \(|\mathbf{\phi}^{\prime}|\) is guaranteed to be \(\leq f(|\mathbf{\phi}|)\). We now define \(\mathbf{\Theta}\) by \(\mathbf{\theta}_{n}=\mathbf{\theta}^{q}_{f\left(n\right)}\) (\(\forall n\)). When our Sat algorithm with compact parameters \(\mathbf{\Theta}\) is given \(\mathbf{\phi}\) of length \(n\), it can use the polynomial-size advice string \(\mathbf{\theta}_{n}\) to ask \((M^{q},\mathbf{\Theta}^{q})\) in polynomial time for \(p\left({\bf 1}~{}|~{}\mathbf{\phi}^{\prime}\right)\). Sat\((\mathbf{\phi})\) returns true iff that probability is \(>0\).10 

Footnote 9: See also the remark on implications for seq2seq models following the proof in Appendix A.

### ELNCP models cannot even capture all EC (or ECCP) supports or rankings

We can strengthen Theorem 1 as follows:

**Theorem 2**.: _Assuming \(\mathrm{NP}\nsubseteq\mathrm{P}/\text{poly}\), there exists an efficiently computable normalizable weighted language \(\tilde{p}\) where there is no ELNCP \(\tilde{q}\) such that \(\mathrm{support}(\tilde{p})=\mathrm{support}(\tilde{q})\)._

Proof.: Observe that for any two weighted languages \(\tilde{p}\) and \(\tilde{q}\) with the same support, \(\forall\hat{\mathbf{x}}\in V^{*}\), \(Z_{\tilde{p}}(\hat{\mathbf{x}})>0\iff Z_{\tilde{q}}(\hat{\mathbf{x}})>0\) (where \(Z_{\tilde{p}}\) and \(Z_{\tilde{q}}\) return the prefix probabilities of \(\tilde{p}\) and \(\tilde{q}\) respectively). Thus, for any \(\hat{\mathbf{x}}\) with \(Z_{\tilde{p}}(\hat{\mathbf{x}})>0\), \(p\left({\bf 1}~{}|~{}\hat{\mathbf{x}}\right)\triangleq\mathit{L}_{\tilde{p}}(\hat {\mathbf{x}}\mathds{1})/\mathit{L}_{\tilde{p}}(\hat{\mathbf{x}})\) and \(q\left({\bf 1}~{}|~{}\hat{\mathbf{x}}\right)\triangleq\mathit{L}_{\tilde{q}}(\hat {\mathbf{x}}\mathds{1})/\mathit{L}_{\tilde{q}}(\hat{\mathbf{x}})\) are well-defined and \(p\left({\bf 1}~{}|~{}\hat{\mathbf{x}}\right)>0\iff q\left({\bf 1}~{}|~{}\hat{ \mathbf{x}}\right)>0\). If \(\tilde{q}\) is ELNCP, then all such probabilities \(q\left({\bf 1}~{}|~{}\hat{\mathbf{x}}\right)\) can be computed in polytime with compact parameters, so it is likewise efficient to determine whether \(p\left({\bf 1}~{}|~{}\hat{\mathbf{x}}\right)>0\). But this cannot be the case when \(\tilde{p}\) is the weighted language used in the proof of Theorem 1, since that would suffice to establish that Sat\(\in\mathrm{P}/\text{poly}\), following the proof of that theorem. 

To put this another way, there exists an unweighted language in P (namely \(\mathrm{support}(\tilde{p})\)) that is not the support of _any_ ELNCP distribution.

If they have different support, normalizable languages also differ in their ranking of strings:

**Lemma 3**.: _Let \(\tilde{p},\tilde{q}\) be normalizable weighted languages with \(\mathrm{support}(\tilde{p})\neq\mathrm{support}(\tilde{q})\). Then \(\exists\mathbf{x}_{1}\), \(\mathbf{x}_{2}\in V^{*}\) such that \(\tilde{p}\left({\mathbf{x}_{1}}\right)<\tilde{p}\left({\mathbf{x}_{2}}\right)\) but \(\tilde{q}\left({\mathbf{x}_{1}}\right)\geq\tilde{q}\left({\mathbf{x}_{2}}\right)\)._

Therefore, no ELNCP \(\tilde{q}\) captures the string ranking of \(\tilde{p}\) from Theorem 2. And for some \(\tilde{p}\), any ELNCP \(\tilde{q}\) misranks even string pairs of "similar" lengths:

**Theorem 3**.: _Assuming \(\mathrm{NP}\nsubseteq\mathrm{P}/\text{poly}\), there exists an efficiently computable normalizable weighted language \(\tilde{p}\) such that no ELNCP \(\tilde{q}\) with \(\mathrm{support}(\tilde{q})\supseteq\mathrm{support}(\tilde{p})\) has \(\tilde{p}\left({\mathbf{x}_{1}}\right)<\tilde{p}\left({\mathbf{x}_{2}}\right) \Rightarrow\tilde{q}\left({\mathbf{x}_{1}}\right)<\tilde{q}\left({\mathbf{x}_{2}}\right)\) for all \(\mathbf{x}_{1},\mathbf{x}_{2}\in V^{*}\). Indeed, any such \(\tilde{q}\) has a counterexample where \(\tilde{p}\left({\mathbf{x}_{1}}\right)=0\). Moreover, there is a polynomial \(f_{\tilde{q}}:\mathbb{N}\rightarrow\mathbb{N}\) such that a counterexample exists for every \(\mathbf{x}_{1}\) such that \(\tilde{p}\left({\mathbf{x}_{1}}\right)=0\) and \(\tilde{q}\left({\mathbf{x}_{1}}\right)>0\), where the \(\mathbf{x}_{2}\) in this counterexample always satisfies \(|\mathbf{x}_{2}|\leq f_{\tilde{q}}(|\mathbf{x}_{1}|)\)._

Theorem 3 is relevant if one wishes to train a model \(\tilde{q}\) to rerank strings that are proposed by another method (_e.g._, beam search on \(\tilde{q}\), or exact \(k\)-best decoding from a more tractable distribution). If the desired rankings are given by Theorem 3's \(\tilde{p}\), any smoothed11 ELNCP model \(\tilde{q}\) will misrank some sets of candidate strings, even sets all of whose strings are "close" in length, by failing to rank an impossible string (\(\mathbf{x}_{1}\) with \(\tilde{p}\left({\mathbf{x}_{1}}\right)=0\)) below a possible one (\(\mathbf{x}_{2}\) with \(\tilde{p}\left({\mathbf{x}_{2}}\right)>0\) 



### ELNCP models cannot even _approximate_ EC (or ECCP) distributions

Theorem 2 implies that there exists \(\tilde{p}\) whose local probabilities \(p(x\mid\hat{\mathbf{x}})\) are not approximated by any ELNCP \(q\) to within any constant factor \(\lambda\), since that would perfectly distinguish zeroes from non-zeroes and the resulting support sets would be equal.12

Footnote 12: Dropping the normalization requirement on the approximated local probabilities (so that possibly \(\sum_{x\in V}q(x\mid\hat{\mathbf{x}})\neq 1\)) does not help. Otherwise, again, Sat could be solved in polynomial time (with the help of polysize advice strings) by using \(q(1\mid\boldsymbol{\phi}^{\prime})\) to determine in the proof of Theorem 1 whether \(p(1\mid\boldsymbol{\phi}^{\prime})>0\).

However, this demonstration hinges on the difficulty of multiplicative approximation of zeroes -- whereas real-world distributions may lack zeroes. Below we further show that it is hard even to approximate the _non-zero_ local conditional probabilities (even with the additional help of randomness).

**Theorem 4**.: _Assuming \(\mathrm{NP}\not\subseteq\mathrm{P/poly}\), there exists an efficiently computable weighted language \(\tilde{p}:V^{*}\rightarrow\mathbb{R}_{\geq 0}\) such that there is no \((M^{\text{q}},\boldsymbol{\Theta}^{\text{q}})\) where \(\boldsymbol{\Theta}^{\text{q}}=\{\boldsymbol{\theta}_{n}^{\text{q}}\mid n\in \mathbb{N}\}\) that satisfies all of the following properties (similar to SS3.1):_

* _the parameter size_ \(|\boldsymbol{\theta}_{n}^{\text{q}}|\) _grows only as_ \(O(\operatorname{poly}(n))\)__
* _[leftmargin=*]_
* _[leftmargin=*]_
* _[leftmargin=*]_
* _[leftmargin=*]_
* _[leftmargin=*]_
* _[rightmargin=*]_


REBMs, again with NCE training, and evaluated them on two different neural architectures (GRU- and Transformer-based) and 3 datasets WikiText Merity et al. (2017), Yelp Yelp (Yelp), and RealNewzellers et al. (2019)). In each setting we tried, the REBM slightly but significantly improved the perplexity of the base model \(p_{0}\) (\(p<0.05\)).14

Footnote 14: We independently conceived of and implemented the REBM idea proposed in Bakhtin et al. (2021). Details of neural architecture choice, model parameter sizes, training regimen, and evaluation (Appendices B–D) differ between our work and theirs, which also reported positive empirical results (on different datasets). We regard the two independent positive findings as a strong indication that the REBM design is effective.

### Latent-variable models

Autoregressive models have \(Z=1\) for any setting of the parameters (or at least any setting that guarantees consistency: see footnote 7). Clearly \(Z=1\) ensures that \(Z\) is both finite and tractable. Can we find a model family that retains this convenience (unlike EBMs), while still being expressive enough to have any non-empty language in P as support?

Autoregressive _latent-variable_ models form such a family. As in directed graphical models, the use of latent variables provides a natural way to model partial observations of an underlying stochastic sequence of events. We will model an observed sequence \(\mathbf{x}\) of length \(n\) as a function of a latent string \(\mathbf{z}\) of length \(O(\text{poly}(n))\). As in EBMs, the probability \(p(\mathbf{x})\) can be computationally intractable, allowing these models to break the expressivity bottleneck of ordinary autoregressive models. However, the intractability no longer comes from exponentially many summands in the denominator \(Z\), but rather from exponentially many summands in the numerator -- namely, the summation over all latent \(\mathbf{z}\) that could have produced \(\mathbf{x}\). Notice that as a result, even unnormalized string weights are now hard to compute, although once computed they are already normalized.

Formally, we define **marginalized** weighted languages. We say that \(\tilde{p}\) is a **marginalization** of the weighted language \(\bar{r}\) if it can be expressed as \(\tilde{p}(\mathbf{x})=\sum_{\mathbf{z}:\mu(\mathbf{z})=\mathbf{x}}\bar{r}( \mathbf{z})\), where \(\mu:S\to V^{*}\) is some function (the **marginalization operator**). We say it is a **light marginalization** if \(|\mathbf{z}|\in O(\text{poly}(|\mu(\mathbf{z})|))\) and \(\mu\) runs in time \(O(\text{poly}(|\mathbf{z}|))\).15 Typically \(\mu(\mathbf{z})\) extracts a subsequence of \(\mathbf{z}\); it can be regarded as keeping the observed symbols while throwing away a polynomially bounded number of latent symbols.

Footnote 15: WLOG, \(\mu\) can be required for run in linear time \(O\left(|\mathbf{z}|\right)\), as it does in our constructions below.

Light marginalizations of ELN distributions are a reasonable formalization of latent-variable autoregressive models. They are more powerful than ELN distributions, and even include some distributions that (by Lemma 1) are not even ELNCP or ECCP:

**Theorem 7**.: _There exists a light marginalization \(p\) of an ELN distribution, such that \(\mathrm{support}(p)\) is an NP-complete language._

Our proof of Theorem 7 relies on special structure of a certain NP-complete language Sat and does not evidently generalize to all languages in NP.

However, light marginalizations of _ELNCP_ distributions are more powerful still,16 and can have _any_ language \(\in\)NP or even NP/poly (SS2.4) as support:

Footnote 16: The capacity established by Theorem 8 does not need the full power of marginalization. We could similarly define light _maximizations_ of ELNCP distributions, \(\bar{p}(\mathbf{x})=\max_{\mathbf{z}\mu(\mathbf{z})=\mathbf{x}}\bar{r}( \mathbf{z})\). Replacing sum by max does not change the support.

**Theorem 8**.: _The following statements are equivalent for any nonempty \(L\subseteq V^{*}\):_

1. \(L\in\mathrm{NP/poly}\)_._
2. \(L\) _is the support of a light marginalization of an ELNCP distribution._
3. \(L\) _is the support of a light marginalization of an ECCP weighted language._

Theorems 7 and 8 make use of unrestricted latent-variable autoregressive models. There exist more practical restricted families of such models that admit tractable computation of \(p(\mathbf{x})\)Lafferty et al. (2001); Rastogi et al. (2016); Wu et al. (2018); Buys and Blunsom (2018). Such models are EC (and indeed, typically ELN) -- but this limits their expressivity, by Theorem 1. Both Lin et al. (2019) and Buys and Blunsom (2018) observed that such models yield worse empirical results than models that do not have tractable exact inference methods. The tractability requirement is dropped in "self-talk" blixt (2020; Gontier et al., 2020; Shwartz et al., 2020), where a neural autoregressive language model generates an analysis of the prefix \(\mathbf{\hat{x}}\) via latent intermediate symbols before predicting the next output symbol.17

Footnote 16: Here the marginal distribution of the next observed symbol can require superpolynomial time to compute (if # FP + FP, which follows from \(\mathrm{NP}\not\subseteq\mathsf{P/poly}\)). Theorem 1 could likewise be evaded by _other_ autoregressive approaches that investerpolynomial computation in predicting the next symbol Graves (2016). Each autoregressive step might explicitly invoke lookahead or reasoning algorithms, just as feed-forward network layers can invoke optimizers or solvers Amos and Kolter (2017); Wang et al. (2019b).

We remark that for autoregressive models, the _position_ of the latent variables is significant. Marginalizing out latent variables at the _end_ of the string adds no power. More precisely, if an ELNCP distribution is over strings \(\mathbf{z}\) of the form \(\mathbf{x}

 

via \(\mu({\bf x}\#{\bf y})={\bf x}\) can be expressed more simply as an ELNCP language. Thus, by Theorem 2, marginalizations of such distributions cannot have arbitrary NP languages as support. Our proofs of Theorems 7 and 8 instead use latent strings of the form \({\bf y}\#{\bf x}\), where all latent variables precede all observed ones (as in Kingma and Welling, 2014). (This simple design can always be used without loss of generality.) Trying to reorder those latent strings as \({\bf x}\#{\bf y}\) while preserving their weights would have yielded a non-ELNCP distribution \(p({\bf x}\#{\bf y})\) (because if it were ELNCP, then \(p({\bf x})\) would be ELNCP also, and we know from Lemma 1 that it cannot be for any distribution whose support is an NP-complete language).

How about lightly marginalizing ECCP languages instead of ELNCP ones? This cannot model any additional _unweighted_ languages, by Theorem 8. But it may be able to model more probability distributions. One can easily construct a light marginalization \(p\) of an ECCP distribution such that \(\#(\phi)=c_{n}\cdot p(\boldsymbol{\phi})\), where \(\#(\phi)\) is the number of satisfying assignments of \(\phi\) and the constant \(c_{n}\) depends only on \(n=|\boldsymbol{\phi}|\). We conjecture that this is not possible with lightly marginalized ELNCP distributions.

### Lookup models

SS2.3 noted that with exponential growth in stored parameters, it is possible to fit any weighted language up to length \(n\), with local probabilities computed in only \(O(n)\) time by lookup. Of course this rapidly becomes impractical as \(n\) increases, even if the amount of training data increases accordingly. However, there has been some recent movement toward storage-heavy models. Such models are typically semiparametric: they use a parametric neural model, such as an autoregressive model, together with an external knowledge base of text strings or factoids that are not memorized in the layer weights. The neural model generates queries against the knowledge base and combines their results. Examples include \(k\)NNLMs (Khandelwal et al., 2020) and semiparametric LMs (Yogatama et al., 2021). The knowledge base grows linearly with the training data rather than compressing the data into a smaller parameter vector. It is in fact a copy of the training data, indexed to allow fast lookup (Indyk and Motwani, 1998). (Preparing the index is much cheaper than neural network training.) Access to the large knowledge base may reduce the amount of computation needed to find the local conditional probabilities, much as in the trie construction of SS2.3.

## 5 Related work

Chen et al. (2018) show that it is hard to map _RNN parameters_ to properties of the resulting autoregressive weighted language, such as consistency (\(Z=1\)). We focus on cases where the RNN parameters are already known to be consistent, so the RNN efficiently maps a _string_\(\mathbf{\hat{x}}\) to its local conditional distribution \(p(\cdot\mid\mathbf{\hat{x}})\). Our point is that for some weighted languages, this is not possible (even allowing polynomially larger RNNs for longer strings), so consistent RNNs and their lik cannot be used to describe such languages.

In a Bayes network -- which is really just an autoregressive model of fixed-length strings -- approximate marginal inference is NP-hard (Roth, 1996). Assuming \(\mathrm{NP}\not\subseteq\mathrm{P/poly}\) and the grid-minor hypothesis, Chandrasekaran et al. (2008, Theorem 5.6) further showed that for any infinite sequence of graphs \(G_{1},G_{2},\ldots\) where \(G_{n}\) has treewidth \(n\), there is no sequence of algorithms \(M_{1},M_{2},\ldots\) such that \(M_{n}\) performs approximate marginal inference in time \(O(\operatorname{poly}(n))\) on graphical models of structure \(G_{n}\). This remarkable negative result says that in _any_ graph sequence of unbounded treewidth, approximating the normalizing constant for \(G_{n}\) given arbitrary parameters is hard (not \(O(\operatorname{poly}(n))\)), even with advice strings. Our negative result (Theorem 4) focuses on _one particular_ infinite weighted language, showing that approximating local conditional probabilities given an arbitrary length-\(n\) prefix is hard in the same way. (So this language cannot be captured by an RNN, even with advice strings.)

## 6 Conclusion and future work

Autoregressive models are suited to those probability distributions whose prefix probabilities are efficiently computable. This efficiency is convenient for training and sampling. But unless we sacrifice it and allow runtime or parameter size to grow superpolynomially in input length, autoregressive models are less expressive than models whose prefix probabilities expensively marginalize over suffixes or latent variables.

All model families we have discussed in this paper can be seen as making compromises between different desiderata (Table 1). Natural follow-up questions include '_Are there model families that win on all fronts? 'What are other modeling desiderata?'_

While _some_ languages \(\in\mathrm{P}\) cannot be supports of ELNCPs, we do not know if the same can be said for _most_ languages \(\in\mathrm{P}\). This problem seems to be closely related to the average complexity of NP-complete languages, where most questions remain open (Levin, 1986; Bogdanov and Trevisan, 2006) 



## Acknowledgements

We thank the anonymous reviewers for their comments. We also thank our colleagues at Johns Hopkins University, Facebook, and Carnegie Mellon University for their comments on earlier versions of the manuscript. This material is based upon work at Johns Hopkins University supported by the National Science Foundation under Grant No. 1718846. It does not represent the views of Microsoft (where Dr. Eisner is also a paid employee, in an arrangement that has been reviewed and approved by the Johns Hopkins University in accordance with its conflict of interest policies).

## References

* Amos and Kolter (2017) Brandon Amos and J. Zico Kolter. 2017. OptNet: Differentiable optimization as a layer in neural networks. In _ICML_.
* Arora and Barak (2009) Sanjeev Arora and Boaz Barak. 2009. _Computational Complexity: a Modern Approach_. Cambridge University Press.
* Bakhtin et al. (2021) Anton Bakhtin, Yuntian Deng, Sam Gross, Myle Ott, Marc'Aurelio Ranzato, and Arthur Szlam. 2021. Residual energy-based models for text generation. _JMLR_, 22(40):1-41.
* Bender et al. (2021) Emily M. Bender, Timnit Gebru, Angelina McMillan-Major, and Shmargaret Shmitchell. 2021. On the dangers of stochastic parrotts: Can language models be too big?. In _FAccT_.
* blixt (2020) blixt. 2020. Re: Teaching gpt-3 to identify nonsense. [https://news.ycombinator.com/item?id=23990902](https://news.ycombinator.com/item?id=23990902). Online (accessed Oct 23, 2020).
* Bogdanov and Trevisan (2006) Andrej Bogdanov and Luca Trevisan. 2006. Average-case complexity. _Foundations and Trends in Theoretical Computer Science_, 2(1):1-106.
* Brown et al. (2020) Tom B. Brown, Benjamin Mann, Nick Ryder, Melanie Subbiah, Jared Kaplan, Prafulla Dhariwal, Arvind Neelakantan, Pranav Shyam, Girish Sastry, Amanda Askell, Sandhini Agarwal, Ariel Herbert-Voss, Gretchen Krueger, Tom Henighan, Rewon Child, Aditya Ramesh, Daniel M. Ziegler, Jeffrey Wu, Clemens Winter, Christopher Hesse, Mark Chen, Eric Sigler, Mateusz Litwin, Scott Gray, Benjamin Chess, Jack Clark, Christopher Berner, Sam McCandlish, Alec Radford, Ilya Sutskever, and Dario Amodei. 2020. Language models are few-shot learners.
* Buys and Blunsom (2018) Jan Buys and Phil Blunsom. 2018. Neural syntactic generative models with exact marginalization. In _NAACL_.
* Cai and Knight (2013) Shu Cai and Kevin Knight. 2013. Smatch: an evaluation metric for semantic feature structures. In _ACL_.
* Chandrasekaran et al. (2008) Venkat Chandrasekaran, Nathan Srebro, and Prahladh Harsha. 2008. Complexity of inference in graphical models. In _UAI_.
* Chen et al. (2018) Yining Chen, Sorcha Gilroy, Andreas Maletti, Jonathan May, and Kevin Knight. 2018. Recurrent neural networks as weighted language recognizers. In _NAACL_.
* Chi and Geman (1998) Zhiyi Chi and Stuart Geman. 1998. Estimation of probabilistic context-free grammars. _Computational Linguistics_, 24(2):299-305.
* Child et al. (2019) Rewon Child, Scott Gray, Alec Radford, and Ilya Sutskever. 2019. Generating long sequences with sparse transformers. _ArXiv_, abs/1904.10509.
* Cook (1971) Stephen A. Cook. 1971. The complexity of theorem-proving procedures. In _STOC_.
* DeNero and Klein (2008) John DeNero and D. Klein. 2008. The complexity of phrase alignment problems. In _ACL_.
* Gontier et al. (2020) Nicolas Gontier, Koustuv Sinha, Siva Reddy, and C. Pal. 2020. Measuring systematic generalization in neural proof generation with transformers. In _NeurIPS_.
* Graves (2016) A. Graves. 2016. Adaptive computation time for recurrent neural networks. _ArXiv_, abs/1603.08983.
* Gutmann and Hyvarinen (2010) Michael U. Gutmann and Aapo Hyvarinen. 2010. Noise-contrastive estimation: A new estimation principle for unnormalized statistical models. In _AISTATS_.
* Gutmann and Hyvarinen (2012) Michael U. Gutmann and Aapo Hyvarinen. 2012. Noise-contrastive estimation of unnormalized statistical models, with applications to natural image statistics. _JMLR_, 13(11):307-361.
* Huang et al. (2018) Y. Huang, A. Sethy, K. Audhkasi, and B. Ramabhadran. 2018. Whole sentence neural language models. In _ICASSP_.
* Hyvarinen (2005) Aapo Hyvarinen. 2005. Estimation of non-normalized statistical models by score matching. _JMLR_, 6(24):695-709.
* Idsardi (2006) W. Idsardi. 2006. A simple proof that optimality theory is computationally intractable. _Linguistic Inquiry_, 37:271-275.
* Indyk and Motwani (1998) Piotr Indyk and Rajeev Motwani. 1998. Approximate nearest neighbors: Towards removing the curse of dimensionality. In _STOC_.
* Karp and Lipton (1980) Richard M. Karp and Richard J. Lipton. 1980. Some connections between nonuniform and uniform complexity classes. In _STOC_.
* Khandelwal et al. (2020) Urvashi Khandelwal, Omer Levy, Dan Jurafsky, Luke Zettlemoyer, and Mike Lewis. 2020. Generalization through memorization: Nearest neighbor language models. In _ICLR_.
* Kingma and Welling (2014) Diederik P. Kingma and Max Welling. 2014. Autoencoding variational Bayes. In _ICLR_

Richard E. Ladner. 1975. The circuit value problem is log space complete for P. _SIGACT News_, 7(1):18-20.
* Lafferty et al. [2001] John D. Lafferty, Andrew McCallum, and Fernando C. N. Pereira. 2001. Conditional random fields: Probabilistic models for segmenting and labeling sequence data. In _ICML_.
* LeCun et al. [2006] Yann LeCun, Sumit Chopra, Raia Hadsell, Marc'Aurelio Ranzato, and Fu-Jie Huang. 2006. A tutorial on energy-based learning. In _Predicting Structured Data_. MIT Press.
* Levin [1986] Leonid A. Levin. 1986. Average case complete problems. _SIAM Journal on Computing_, 15:285-286.
* Lin et al. [2019] Chu-Cheng Lin, Hao Zhu, Matthew R. Gormley, and Jason Eisner. 2019. Neural finite-state transducers: Beyond rational relations. In _NAACL_.
* Ma and Collins [2018] Zhuang Ma and Michael Collins. 2018. Noise contrastive estimation and negative sampling for conditional models: Consistency and statistical efficiency. In _EMNLP_.
* Merity et al. [2017] Stephen Merity, Caiming Xiong, James Bradbury, and Richard Socher. 2017. Pointer sentinel mixture models. _ArXiv_, abs/1609.07843.
* Mikolov et al. [2011] Tomas Mikolov, Stefan Kombrink, Anoop Deoras, Lukas Burget, and Jan Honza Cernocky. 2011. RNNLM--Recurrent neural network language modeling toolkit. In _IEEE Automatic Speech Recognition and Understanding Workshop_.
* Munroe [2009] Randall Munroe. 2009. _My Hobby: Embedding NP-Complete Problems in Restaurant Orders_. Online (accessed May 29, 2020).
* Myasnikov and Rybalov [2008] Alexei G. Myasnikov and Alexander N. Rybalov. 2008. Generic complexity of undecidable problems. _The Journal of Symbolic Logic_, 73(2):656-673.
* van den Oord et al. [2016] Aaron van den Oord, Sander Dieleman, Heiga Zen, Karen Simonyan, Oriol Vinyals, Alex Graves, Nal Kalchbrenner, Andrew Senior, and Koray Kavukcuoglu. 2016. WaveNet: A generative model for raw audio. _ArXiv_, abs/1609.03499.
* Radford et al. [2019] Alec Radford, Jeff Wu, Rewon Child, David Luan, Dario Amodei, and Ilya Sutskever. 2019. Language models are unsupervised multitask learners.
* Rastogi et al. [2016] Pushpendre Rastogi, Ryan Cotterell, and Jason Eisner. 2016. Weighting finite-state transductions with neural context. In _NAACL_.
* Rosenfeld et al. [2001] Ronald Rosenfeld, Stanley Chen, and Xiaojin Zhu. 2001. Whole-sentence exponential language models: A vehicle for linguistic-statistical integration. _Computer Speech & Language_, 15(1):55-73.
* Roth [1996] Dan Roth. 1996. On the hardness of approximate reasoning. _Artificial Intelligence_, 82(1-2):273-302.
* Sandbank [2008] Ben Sandbank. 2008. Refining generative language models using discriminative learning. In _EMNLP_.
* Shwartz et al. [2020] Vered Shwartz, Peter West, Ronan Le Bras, Chandra Bhagavatula, and Yejin Choi. 2020. Unsupervised commonsense question answering with self-talk. In _EMNLP_.
* Siegelmann and Sontag [1992] Hava T. Siegelmann and Eduardo D. Sontag. 1992. On the computational power of neural nets. In _COLT_.
* Sutskever et al. [2014] Ilya Sutskever, Oriol Vinyals, and Quoc V. Le. 2014. Sequence to sequence learning with neural networks. In _NeurIPS_.
* Uria et al. [2016] Benigno Uria, Marc-Alexandre Cote, Karol Gregor, Iain Murray, and Hugo Larochelle. 2016. Neural autoregressive distribution estimation. _JMLR_, 17(1):7184-7220.
* Vaswani et al. [2017] Ashish Vaswani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N. Gomez, Lukasz Kaiser, and Illia Polosukhin. 2017. Attention is all you need. In _NeurIPS_.
* Wang et al. [2019a] Alex Wang, Amanpreet Singh, Julian Michael, Felix Hill, Omer Levy, and Samuel R. Bowman. 2019a. GLUE: A multi-task benchmark and analysis platform for natural language understanding. In _ICLR_.
* Wang et al. [2019b] Po-Wei Wang, P. Donti, B. Wilder, and J. Z. Kolter. 2019b. SATNet: Bridging deep learning and logical reasoning using a differentiable satisfiability solver. In _ICML_.
* Welleck et al. [2020] Sean Welleck, Ilia Kulikov, Jaedeok Kim, Richard Yuanzhe Pang, and Kyunghyun Cho. 2020. Consistency of a recurrent language model with respect to incomplete decoding. In _EMNLP_.
* Wu et al. [2018] Shijie Wu, Pamela Shapiro, and Ryan Cotterell. 2018. Hard non-monotonic attention for character-level transduction. In _EMNLP_.
* Yelp [dataset. [https://www.yelp.com/dataset](https://www.yelp.com/dataset).
* Yogatama et al. [2021] Dani Yogatama, Cyprien de Masson d'Autume, and Lingpeng Kong. 2021. Adaptive semiparametric language models. _ArXiv_, abs/2102.02557.
* Zellers et al. [2019] Rowan Zellers, Ari Holtzman, Hannah Rashkin, Yonatak Bisk, Ali Farhadi, Franziska Roesner, and Yejin Choi. 2019. Defending against neural fake news. In _NeurIPS_.

 

Figure 2: The space of unweighted languages. We assume in this diagram that NP \(\not\subseteq{\rm P/poly}\). Each rectangular outline corresponds to a complexity class (named in its lower right corner) and encloses the languages whose decision problems fall into that class. Each _bold-italic label_ (colored to match its shape outline) names a model family and encloses the languages that can be expressed as the _support_ of some _weighted_ language in that family. All induced partitions in the figure are non-empty sets: shape A properly encloses shape B if and only if language class A is a strict superset of language class B. As mentioned in Table 1, standard autoregressive models (ELN models) have support languages that form a strict subset of P (Lemmas 1 and 2, Theorem 5, and §2.4). ELNCP models (§3.1) extend ELN models by allowing the parameter size to grow polynomially in string length, allowing them to capture both more languages inside P (Theorem 6) and languages outside P (including undecidable but sparse languages) that can be characterized autoregressively with the help of these compact parameters. All of those languages belong in the class \({\rm P/poly}\). Theorem 2 establishes that energy-based (EC) and ECCP models go strictly further than ELN and ELNCP models, respectively (Theorem 2): they correspond to the _entire_ classes P and \({\rm P/poly}\) (Lemma 1). However, even ECCP does not capture any NP-complete languages under our assumption NP \(\not\subseteq{\rm P/poly}\). Allowing a polynomial number of latent symbols extends the power further still: lightly marginalized ELNCP or ECCP distributions cover exactly the languages \(\in{\rm NP/poly}\) (Theorem 8). Finally, if we were to drop the requirement that the parameters \(\mathbf{\Theta}\) must be compact, we could store lookup tries to model any weighted language (SS4.3).

 

Proofs

**Lemma 1**.: _For any \(L\in{\rm P},\) there exists an EC weighted language with support \(L\). For any \(L\in{\rm P/poly},\) there exists an ECCP language with support \(L\). But for any \(L\in{\rm NP}\mbox{-complete},\) there exists no ECCP language with support \(L\) (assuming \({\rm NP}\not\subseteq{\rm P/poly}\))._

This simple lemma relates our classes EC and ECCP of _weighted_ languages to the complexity classes \({\rm P}\) and \({\rm P/poly}\) of their supports, which are _unweighted_ formal languages (SS2). It holds because computing a string's weight can be made as easy as determining whether that weight is nonzero (if we set the weights in a simple way), but is certainly no easier. We spell out the trivial proof to help the reader gain familiarity with the formalism.

Proof.: Given \(L\), define a weighted language \(\tilde{p}\) with support \(L\) by \(\tilde{p}\left({\bf x}\right)=1\) if \({\bf x}\in L\) and \(\tilde{p}\left({\bf x}\right)=0\) otherwise.

If \(L\in P\), then clearly \(\tilde{p}\) is EC since the return value of \(1\) or \(0\) can be determined in polytime.

If \(L\in{\rm P/poly}\), \(L\) can be described as a tuple \((M,\mathbf{\Theta})\) following our characterization in SS2.4. It is easy to show that \(\tilde{p}\) is ECCP, using the same polynomially-sized advice strings \(\mathbf{\Theta}\). We simply construct \(M^{\tilde{\rm P}}\) such that \(M^{\tilde{\rm P}}(\mathbf{\theta}_{n})\) returns \(1\) or \(0\) on input \({\bf x}\) according to whether \(M(\mathbf{\theta}_{n})\) accepts or rejects \({\bf x}\). Both \(M^{\tilde{\rm P}}(\mathbf{\theta}_{n})\) and \(M^{\tilde{\rm P}}(\mathbf{\theta}_{n})({\bf x})\) are computed in time \(O\left({\rm poly}\left(n\right)\right)\) if \(|{\bf x}|=n\). (The technical construction is that \(M^{\tilde{\rm P}}\) simulates the operation of \(M\) on the input \(\mathbf{\theta}_{n}\) to obtain the description of the Turing machine \(M_{n}=M(\mathbf{\theta}_{n})\), and then outputs a slightly modified version of this description that will write \(1\) or \(0\) on an output tape.)

For the second half of the lemma, we use the reverse construction. Suppose \(\tilde{p}\) is an ECCP weighted language with support \(L\). \(\tilde{p}\) can be characterized by a tuple \((M^{\tilde{\rm p}},\mathbf{\Theta})\). It is easy to show that \(L\in{\rm P/poly}\), using the same polynomially-sized advice strings \(\mathbf{\Theta}\). We simply construct \(M\) such that \(M(\mathbf{\theta}_{n})\) accepts \({\bf x}\) iff \(M^{\tilde{\rm P}}(\mathbf{\theta}_{n})\left({\bf x}\right)>0\). Then by the assumption, \(L\notin{\rm NP}\mbox{-complete}\). 

**Lemma 2**.: _An ELNCP model \(\tilde{p}\) is also ECCP. Likewise, an ELN model is also EC._

Proof.: Let \(\tilde{p}\) be an ELNCP language. This implies that \(\tilde{p}\) is normalizable, so let \(p\left({\bf x}\right)\triangleq\tilde{p}\left({\bf x}\right)/Z\) as usual. Specifically, let \(M^{q}\) efficiently locally normalize \(\tilde{p}\) with compact parameters \(\mathbf{\Theta}^{q}=\{\mathbf{\theta}_{n}^{q}\mid n\in\mathbb{N}\}\). It is simple to define a Turing machine \(M^{r}\) that maps each parameter string \(\mathbf{\theta}_{n}^{q}\) to a Turing machine \(r_{n}\), where \(r_{n}({\bf x})\) simply computes \(\left(\prod_{t=1}^{n}q_{n}(x_{t}\mid{\bf x}_{<t})\right)\cdot q_{n}(\$\;\mid \;{\bf x})\). Then for all \({\bf x}\) of length \(n\), \(r_{n}({\bf x})=\left(\prod_{t=1}^{n}p\left(x_{t}\mid{\bf x}_{<t}\right)\right) \cdot p\left(\$\;\mid\;{\bf x}\right)\), by the definition of local normalization, and thus \(r_{n}({\bf x})=p({\bf x})\).

\(M^{r}\) can be constructed by incorporating the definition of \(M^{q}\), so that \(r_{n}=M^{r}(\mathbf{\theta}_{n}^{q})\) can include \(q_{n}=M^{q}(\mathbf{\theta}_{n}^{q})\) as a subroutine. This allows \(r_{n}\) to query \(q_{n}\) for local conditional probabilities and multiply them together.

* Since \(M^{q}\) runs in polytime, it is straightforward for this construction to ensure that \(M^{r}\) runs in polytime as well.
* Since \(q_{n}(\cdot\mid\;\dot{\bf x})\in O({\rm poly}(n))\), this construction can ensure that \(r_{n}\) runs in polytime as well.
* We were given that \(|\mathbf{\theta}_{n}^{q}|\in O({\rm poly}(n))\) (compact parameters).

Since \(p\) is the weighted language defined by \((M^{r},\mathbf{\Theta}^{q})\), and \(M^{r}\) and \(\mathbf{\Theta}^{q}\) have the properties just discussed, we see that \(p\) is efficiently computable with compact parameters (ECCP). Therefore \(\tilde{p}({\bf x})=Zp({\bf x})\) is also ECCP.

In the case where \(\tilde{p}\) is more strongly known to be ELN (the parameters \(\mathbf{\Theta}^{q}\) are not needed), a simplification of this argument shows that it is EC. 

**Theorem 1**.: _Assuming \({\rm NP}\not\subseteq{\rm P/poly}\), there exists an efficiently computable normalizable weighted language \(\tilde{p}\) that is not ELNCP._

Proof.: The proof was sketched in SS3.2. Here we fill in the details.

The unweighted language \(\tilde{p}\) defined in that section is efficiently computable via the following simple algorithm that outputs \(\tilde{p}\left({\bf x}\right)\) given \({\bf x}\in\mathbb{B}^{*}\). If \({\bf x}\) has a prefix that encodes a formula \(\phi\), and the remainder of \({\bf x}\) is a satisfying assignment \({\bf a}\) to the variables of \(\phi\), then return \((\frac{1}{3})^{|{\bf x}|+1}\). Otherwise return \(0\). This algorithm can be made to run in polynomial time because whether an assignment satisfies a formula can be determined in polynomial time (a fact that is standardly used to establish that Sat \(\in{\rm NP}\)).

Given a formula \(\phi\) with variables \(A_{1},\ldots,A_{j}\), we define \(\phi^{\prime}=(\neg A_{1}\wedge\neg A_{2}\land\ldots\wedge\neg A_{j}\wedge \neg A_{j+1})\lor(A_{1}\wedge\mathrm{Shift}(\phi))\), where Shift\((\phi)\) is a version of \(\phi\) in which \(A_{i}\) has been renamed to \(A_{i+1}\) for all \(1\leq i\leq j\). It is obvious that \(\phi^{\prime}\) and \(p\) have the properties stated in the proof sketch. The strings in \(L\) that begin with \(\mathbf{\phi}^{\prime}\) are precisely the strings of the form \(\mathbf{\phi}^{\prime}\mathbf{a}^{\prime}\) where \(\mathbf{a}^{\prime}\) is a satisfying assignment of \(\phi^{\prime}\) -- which happen just when \(\mathbf{a}^{\prime}=\emptyset^{j+1}\) or \(\mathbf{a}^{\prime}=1\mathbf{a}\) where \(\mathbf{a}\) is a satisfying 

assignment of \(\phi\). At least one string in \(L\) begins with \({\mathbf{\phi}^{\prime}}\), namely \({\mathbf{\phi}^{\prime}}{\mathbf{\Theta}^{j+1}}\), so \(Z({\mathbf{\phi}^{\prime}})>0\). Moreover, \(Z({\mathbf{\phi}^{\prime}}1)>0\) iff \(\phi\) has any satisfying assignments. Therefore the local probability \(p(1~{}|~{}{\mathbf{\phi}^{\prime}})=Z({\mathbf{\phi}^{\prime}}1)/Z({\mathbf{\phi}^{\prime}})\) is defined (see SS2.1), and is \(>0\) iff Sat\((\phi)\).

Notice that the formal problem used in the proof is a version of Sat whose inputs are encoded using the same prefix-free encoding function enc that was used by our definition of \(L\) in SS3.2. We must choose this encoding function to be concise in the sense that \({\mathbf{\phi}}\triangleq\text{enc}(\phi)\) can be converted to and from the conventional encoding of \(\phi\) in polynomial time. This ensures that our version of Sat is \(\leq_{m}^{P}\)-interreducible with the conventional version and hence NP-complete. It also ensures that there is a polynomial function \(f\) such that \(|{\mathbf{\phi}^{\prime}}|\leq f(|{\mathbf{\phi}}|)\), as required by the proof sketch, since there is a polynomial-time function that maps \({\mathbf{\phi}}\rightarrow{\mathbf{\phi}}\rightarrow{\mathbf{\phi}^{\prime}}\to{\mathbf{ \phi}^{\prime}}\) and the output length of this function is bounded by its runtime. This is needed to show that our version of Sat is in P/poly.

Specifically, to show that the existence of \((M^{\mathfrak{q}},{\mathbf{\Theta}^{\mathfrak{q}}})\) implies Sat\(\in\) P/poly, we use it to construct an appropriate pair \((M,{\mathbf{\Theta}})\) such that \((M({\mathbf{\theta}}_{n}))({\mathbf{\phi}})=\textsc{Sat}(\phi)\) if \(|{\mathbf{\phi}}|=n\). As mentioned in the proof sketch, we define \({\mathbf{\Theta}}\) by \({\mathbf{\theta}}_{n}={\mathbf{\theta}}_{f\;(n)}^{\mathfrak{q}}\), and observe that \(|{\mathbf{\theta}}_{n}|\in O(\operatorname{poly}(n))\) (thanks to compactness of the parameters \({\mathbf{\Theta}^{\mathfrak{q}}}\) and the fact that \(f\) is polynomially bounded). Finally, define \(M({\mathbf{\theta}}_{n})\) to be a Turing machine that maps its input \({\mathbf{\phi}}\) of length \(n\) to \({\mathbf{\phi}^{\prime}}\) of length \(\leq f(n)\), then calls \(M^{\mathfrak{q}}({\mathbf{\theta}}_{n})=M^{\mathfrak{q}}({\mathbf{\theta}}_{f\;(n)}^{ \mathfrak{q}})\) on \({\mathbf{\phi}^{\prime}}1\) to obtain \(p(1~{}|~{}{\mathbf{\phi}^{\prime}})\), and returns true or false according to whether \(p(1~{}|~{}{\mathbf{\phi}^{\prime}})>0\). Computing \({\mathbf{\phi}^{\prime}}\) takes time polynomial in \(n\) (thanks to the properties of enc). Constructing \(M^{\mathfrak{q}}({\mathbf{\theta}}_{f\;(n)})\) and calling it on \({\mathbf{\phi}^{\prime}}\) each take time polynomial in \(n\) (thanks to the properties of \(f\) and \(M^{\mathfrak{q}}\)). 

Remark on conditional models.While we focus on modeling _joint_ sequence probabilities in this work, we note that in many applications it often suffices to just model _conditional_ probabilities [45]. Unfortunately, our proof of Theorem 1 above implies that ELNCPs do not make good conditional models either: specifically, there exists \({\mathbf{\phi}}\) such that deciding whether \(p(1~{}|~{}{\mathbf{\phi}})>0\) is NP-hard, and thus beyond ELNCP's capability.

Remark on irrationality.In our definitions of ECCP and ELNCP languages, we implicitly assumed that the Turing machines that return weights or probabilities would write them in full on the output tape, presumably as the ratio of two integers. Such a Turing machine can only return rational numbers.

But then our formulation of Theorem 1 allows another proof. We could construct \(\tilde{p}\) such that the local conditional probabilities \(p(x~{}|~{}\hat{\mathbf{x}})\triangleq Z(\hat{\mathbf{x}}x)/Z(\hat{\mathbf{x}})\) are sometimes irrational. In this case, they cannot be output exactly by a Turing machine, implying that \(\tilde{p}\) is not ELNCP. However, this proof exposes only a trivial weakness of ELNCPs, namely the fact that they can only define distributions whose local marginal probabilities are rational.

We can correct this weakness by formulating ELNCP languages slightly differently. A real number is said to be **computable** if it can be output by a Turing machine to any desired precision. That Turing machine takes an extra input \(b\) which specifies the number of bits of precision of the output. Similarly, our definitions of ECCP and ELNCP can be modified so that their respective Turing machines \(\tilde{p}_{n}\) and \(q_{n}\) take this form, are allowed to run in time \(O(\operatorname{poly}(n+b))\), and have access to the respective parameter vectors \({\mathbf{\Theta}}_{n+b}^{\mathfrak{p}}\) and \({\mathbf{\Theta}}_{n+b}^{\mathfrak{q}}\). Since some of our results concern the ability to distinguish zero from small values (arbitrarily small in the case of Theorem 6), our modified definitions also require \(\tilde{p}_{n}\) and \(q_{n}\) to output a bit indicating whether the output is _exactly_ zero. For simplicity, we suppressed these technical details from our exposition.

Relatedly, in SS4.3, we claimed that lookup models can fit any weighted language up to length \(n\). This is not strictly true if the weights can be irrational. A more precise statement is that for any weighted language \(\tilde{p}\), there is a lookup model that maps \((\mathbf{x},b)\) to the first \(b\) bits of \(\tilde{p}(\mathbf{x})\). Indeed, this holds even when \(\tilde{p}(\mathbf{x})\) is uncomputable.

Remark on computability.In SS2.1 we claimed that any weighted language \(\tilde{p}\) that has a finite and strictly positive \(Z\) can be normalized as \(p(\mathbf{x})=\nicefrac{{p(\mathbf{x})}}{{Z}}\). However, \(Z\) may be uncomputable: that is, there is no algorithm that takes number of bits of precision \(b\) as input, and outputs an approximation of \(Z\) within \(b\) bits of precision. Therefore, even if \(\tilde{p}\) is computable, \(p\) may have weights that are not merely irrational but even _uncomputable_. An example appears in the proof of Theorem 6 below. Weighted language classes (ELNCP) that only model normalized languages will not be able to model such languages, simply because the partition function is uncomputable.

However, our proof of Theorem 1 does not rely on this issue, because the \(\tilde{p}\) that it exhibits happens to have a computable \(Z\). For any \(b,Z\) may be computed to \(b\) bits of precision as the explicit sum \(\sum_{\mathbf{x}:|\mathbf{x}|\leq N}\tilde{p}(\mathbf{x})\) 

for a certain large \(N\) that depends on \(b\).

Remark on RNNsOur proof of Theorem 1 showed that our problematic language \(\tilde{p}\) is efficiently computable (though not by any locally normalized architecture with compact parameters). Because this paper is in part a response to popular neural architectures, we now show that \(\tilde{p}\) can in fact be computed efficiently _by a recurrent neural network (RNN)_ with compact parameters. Thus, this is an example where a simple globally normalized RNN parameterization is fundamentally more efficient (in runtime or parameters) than any locally normalized parameterization of any architecture (RNN, Transformer, etc.).

Since we showed that \(\tilde{p}\) is efficiently computable, the existence of an RNN implementation is established in some sense by the ability of finite rational-weighted RNNs to simulate Turing machines Siegelmann and Sontag (1992), as well as an extension to Chen et al. (2018, Thm. 11) to a family of RNNs, where each RNN instance also takes some formula encoding as input. However, it is straightforward to give a concrete construction, for each \(n\in\mathbb{N}\), for a simple RNN that maps each string \(\mathbf{x}\in\mathbb{B}^{n}\) to \(\tilde{p}(\mathbf{x})\). Here \(\tilde{p}(\mathbf{x})\) will be either \((\frac{1}{3})^{n+1}\) or \(0\), according to whether \(\mathbf{x}\) has the form \(\boldsymbol{\phi}\mathbf{a}\) where \(\boldsymbol{\phi}\) encodes a 3-CNF-Sat formula \(\phi\) that is satisfied by \(\mathbf{a}\).18 The basic idea is that \(\boldsymbol{\phi}\) has \(j\leq n\) variables, so there are only \(O(n^{3})\) possible 3-CNF clauses. The RNN allocates one hidden unit to each of these. When reading \(\boldsymbol{\phi}\mathbf{a}\), each clause encountered in \(\boldsymbol{\phi}\) causes the corresponding hidden unit to turn on, and then each literal encountered in \(\mathbf{a}\) turns off the hidden units for all clauses that would be satisfied by that literal. If any hidden units remain on after \(\mathbf{x}\) has been fully read, then \(\boldsymbol{\phi}\) was not satisfied by \(\mathbf{a}\), and the RNN's final output unit should return \(0\). Otherwise it should return \((\frac{1}{3})^{n+1}\), which is constant for this RNN. To obtain digital behaviors such as turning hidden units on and off, it is most convenient to use ramp activation functions for the hidden units and the final output unit, rather than sigmoid activation functions. Note that our use of a separate RNN \(M_{n}^{\text{RNN}}\) for each input length \(n\) is an example of using more hidden units for larger problems, a key idea that we introduced in SS2.3 in order to look at asymptotic behavior. The RNN's parameter sequence \(\boldsymbol{\Theta}^{\text{RNN}}=\{\boldsymbol{\theta}_{n}^{\text{RNN}}~{}|~{ }n\in\mathbb{N}\}\) is obviously compact, as \(\boldsymbol{\theta}_{n}^{\text{RNN}}\) only has to store the input length \(n\). With our alphabet \(\mathbb{B}\) for \(\tilde{p}\), \(|\boldsymbol{\theta}_{n}^{\text{RNN}}|\in O\left(\log n\right)\).

Footnote 18: The restriction to 3-CNF-Sat formulas is convenient, but makes this a slightly different definition of \(L\) and \(\tilde{p}\) than we used in the proofs above. Those proofs can be adjusted to show that this \(\tilde{p}\), too, cannot be efficiently locally normalized with compact parameters. The only change is that in the construction of Theorem 1, \(\phi^{\prime}\) must be converted to 3-CNF. The proof then obtains its contradiction by showing that 3-CNF-Sat\(\in\)P/poly (which suffices since 3-CNF-Sat is also NP-complete).

Lemma 3: _Let \(\tilde{p}\), \(\tilde{q}\) be normalizable weighted languages with \(\operatorname{support}(\tilde{p})\neq\operatorname{support}(\tilde{q})\). Then \(\exists\mathbf{x}_{1},\allowbreak\mathbf{x}_{2}\in V^{*}\) such that \(\tilde{p}(\mathbf{x}_{1})<\tilde{p}(\mathbf{x}_{2})\) but \(\tilde{q}(\mathbf{x}_{1})\geq\tilde{q}(\mathbf{x}_{2})\)._

Proof: Suppose that the claim is false, _i.e._, \(\tilde{p}\) and \(\tilde{q}\) have the same ranking of strings. Then the minimum-weight strings under \(\tilde{p}\) must also be minimum-weight under \(\tilde{q}\). WLOG, there exists \(\mathbf{x}\in V^{*}\) with \(\tilde{p}(\mathbf{x})=0\) and \(\tilde{q}(\mathbf{x})=c>0\). Then \(c>0\) is the minimum weight of strings in \(\tilde{q}\). But this is not possible for a normalizable language \(\tilde{q}\), since it means that \(Z_{\tilde{q}}\triangleq\sum_{\mathbf{x}^{\prime}\in V^{*}}q(\mathbf{x}^{ \prime})\geq\sum_{\mathbf{x}^{\prime}\in V^{*}}c\) diverges. 

Theorem 4.1: _Assuming \(\mathrm{NP}\not\subseteq\mathrm{P/poly}\), there exists an efficiently computable normalizable weighted language \(\tilde{p}\) such that no ELNCP \(\tilde{q}\) with \(\operatorname{support}(\tilde{q})\supseteq\operatorname{support}(\tilde{p})\) has \(\tilde{p}(\mathbf{x}_{1})<\tilde{p}(\mathbf{x}_{2})\Rightarrow\tilde{q}( \mathbf{x}_{1})<\tilde{q}(\mathbf{x}_{2})\) for all \(\mathbf{x}_{1},\mathbf{x}_{2}\in V^{*}\). Indeed, any such \(\tilde{q}\) has a counterexample where \(\tilde{p}(\mathbf{x}_{1})=0\). Moreover, there is a polynomial \(f_{\tilde{q}}:\mathbb{N}\to\mathbb{N}\) such that a counterexample exists for every \(\mathbf{x}_{1}\) such that \(\tilde{p}(\mathbf{x}_{1})=0\) and \(\tilde{q}(\mathbf{x}_{1})>0\), where the \(\mathbf{x}_{2}\) in this counterexample always satisfies \(|\mathbf{x}_{2}|\leq f_{\tilde{q}}(|\mathbf{x}_{1}|)\)._

Proof: Let \(\tilde{p}\) be the weighted language from Theorem 2. Given an ELNCP \(\tilde{q}\). By Theorem 2, \(\operatorname{support}(\tilde{q})\neq\operatorname{support}(\tilde{p})\), so there must exist a string \(\mathbf{x}_{1}\) that is in one support language but not the other. With the additional assumption that \(\operatorname{support}(\tilde{q})\supseteq\operatorname{support}(\tilde{p})\), it must be that \(\mathbf{x}_{1}\in\operatorname{support}(\tilde{q})\), so \(\tilde{p}(\mathbf{x}_{1})=0\) but \(\tilde{q}(\mathbf{x}_{1})>0\).

Given _any_ such \(\mathbf{x}_{1}\) with \(\tilde{p}(\mathbf{x}_{1})=0\) but \(\tilde{q}(\mathbf{x}_{1})>0\), we must find a \(\mathbf{x}_{2}\) of length \(O(\operatorname{poly}(|\mathbf{x}_{1}|))\) with \(\tilde{p}(\mathbf{x}_{2})>0\) but \(\tilde{q}(\mathbf{x}_{2})\leq\tilde{q}(\mathbf{x}_{1})\).

To ensure that \(\tilde{p}(\mathbf{x}_{2})>0\), let us use the structure of \(\tilde{p}\). For any \(j\), we can construct a tautological formula \(\phi\) over variables \(A_{1},\ldots A_{j}\), as \(\phi=(A_{1}\vee\neg A_{1})\wedge\cdots\wedge(A_{j}\lor\neg A_{j})\). It follows that \(\tilde{p}(\boldsymbol{\phi}\mathbf{a})>0\) for any \(\mathbf{a}\in\mathbb{B}^{j}\). We will take \(\mathbf{x}_{2}=\boldsymbol{\phi}\mathbf{a}\) for a particular choice of \(j\) and \(\mathbf{a}\).

Specifically, we choose them to ensure that \(\tilde{q}(\mathbf{x}_{2})\leq\tilde{q}(\mathbf{x}_{1})\). Since \(\tilde{q}\) is ELNCP, it is normalizable and hence has a finite \(Z\). Thus, \(\sum_{\mathbf{a}\in\mathbb{B}^{j}}\bar{q}(\boldsymbol{\phi}\mathbf{a})\leq Z\). So there must exist some \(\mathbf{a}\in\mathbb{B}^{j}\) such that \(\tilde{q}(\boldsymbol{\phi}\mathbf{a})\leq\nicefrac{{Z}/{2}}{{}^{\prime}}\). We choose that \(\mathbf{a}\), after choosing \(j\) large enough such that \(\nicefrac{{Z}/{2}}{{}^{\prime}}\leq\tilde{q}(\mathbf{x}_{1})\). Then \(\tilde{q}(\mathbf{x}_{2})=\tilde{q}(\boldsymbol{\phi}\mathbf{a})\leq\nicefrac{{Z} /{2}}{{}^{\prime}}\leq\tilde{q}(\mathbf{x}_{1})\).

To achieve the last claim of the theorem, we must also ensure that \(|\mathbf{x}_{2}|\in O(\operatorname{poly}(|\mathbf{x}_{1}|))\). Observe that \(\tilde{q}(\mathbf{x}_{1})\) can be computed in polytime (with access to 

compact parameters), by Lemma 2. But this means that the representation of \(\tilde{q}(\mathbf{x}_{1})>0\) as a rational number must have \(\leq g(|\mathbf{x}_{1}|)\) bits for some polynomial \(g\). Then \(\tilde{q}(\mathbf{x}_{1})\geq 2^{-g(|\mathbf{x}_{1}|)}\), and it suffices to choose \(j=\lceil g(|\mathbf{x}_{1}|)+\log_{2}Z\rceil\) to ensure that \(z/2^{j}\leq 2^{-g|\mathbf{x}_{1}|}\leq\tilde{q}(\mathbf{x}_{1})\) as required above.

But then \(j\in O(\operatorname{poly}(|\mathbf{x}_{1}|))\). Also, recall that the encoding function enc used in the construction of \(\tilde{p}\) is guaranteed to have only polynomial blowup (see the proof of Theorem 2). Thus, \(|\mathbf{x}_{2}|=|\boldsymbol{\phi}|+|\mathbf{a}|=|\mathrm{enc}(\phi)|+j\in O (\operatorname{poly}(j))\subseteq O(\operatorname{poly}(|\mathbf{x}_{1}|))\) as required by the theorem. 

**Lemma A.1**.: _The first part of Theorem 4 (without the modifications (a) and (b))._

We first prove the first part of Theorem 4 (which is restated in full below). In this case we will use a distribution \(\tilde{p}\) that does not have support \(V^{*}\) (so it does not prove modification (b)).

Proof.: We take \(\tilde{p}\) to be the weighted language that was defined in SS3.2, which was already shown to be efficiently computable. Suppose \((M^{\mathfrak{q}},\boldsymbol{\Theta}^{\mathfrak{q}},\lambda)\) is a counterexample to Lemma A.1. Choose integer \(k\geq 1\) in a manner (dependent only on \(\lambda\)) to be described at the end of the proof.

Suppose we would like to answer Sat where \(\phi\) is a formula with variables \(A_{1},\ldots,A_{j}\). Define \(\phi^{\prime}=(\neg A_{1}\wedge\neg A_{2}\land\ldots\land\neg A_{j}\land \neg A_{j+1}\land\neg A_{j+k})\lor(A_{1}\land\text{Shift}(\phi))\). Note that \(\phi^{\prime}\) augments \(\phi\) with \(k\) additional variables, namely \(A_{1}\) and \(A_{j+2,\ldots,j+k}\). For \(k=1\), this is the same construction as in the proof of Theorem 1. Let \(n=|\boldsymbol{\phi}^{\prime}|\) and note that \(n\) is polynomial in the size of \(\phi\) (holding \(k\) constant).

The strings in \(L=\operatorname{support}(\tilde{p})\) that begin with \(\boldsymbol{\phi}^{\prime}\) are precisely the strings of the form \(\boldsymbol{\phi}^{\prime}\mathbf{a}^{\prime}\) where \(\mathbf{a}^{\prime}\) is a satisfying assignment of \(\phi^{\prime}\). This is achieved precisely when \(\mathbf{a}^{\prime}=\boldsymbol{\theta}^{j+k}\) or \(\mathbf{a}^{\prime}=1\mathbf{a}\overline{b}\) where \(\mathbf{a}\) is a satisfying assignment of \(\phi\) and \(\overline{b}\in\mathbb{B}^{k-1}\).

By our definition of \(\tilde{p}\), all strings in \(L\) that begin with \(\boldsymbol{\phi}^{\prime}\) have equal weight under \(\tilde{p}\). Call this weight \(w\).19 Clearly \(Z(\boldsymbol{\phi}^{\prime}\boldsymbol{\theta})=w\), and \(Z(\boldsymbol{\phi}^{\prime}1)=w\cdot 2^{k-1}\cdot(number\) of satisfying assignments of \(\phi\)).

Footnote 19: Specifically, each such string has length \(n+j+k\), so \(\tilde{p}\) gives it a weight of \(w=(\frac{1}{3})^{n+j+k+1}\).

Recall that \(p(\boldsymbol{\emptyset}\mid\boldsymbol{\phi}^{\prime})=Z(\boldsymbol{\phi}^{ \prime}\boldsymbol{\theta})/(Z(\boldsymbol{\phi}^{\prime}\boldsymbol{\theta})+ Z(\boldsymbol{\phi}^{\prime}1))\). Let us abbreviate this quantity by \(p\). It follows from the previous paragraph that if \(\phi\) is unsatisfiable, then \(p=1\), but if \(\phi\) is satisfiable, then \(p\leq\nicefrac{{1}}{{(1+2^{k-1})}}\). By hypothesis, \(p\) is approximated (with error probability \(<\nicefrac{{1}}{{3}}\)) by the possibly random quantity \((M^{\mathfrak{q}}(\boldsymbol{\theta}^{\mathfrak{q}}_{|\boldsymbol{\phi}^{ \prime}|}))(\boldsymbol{\phi}^{\prime}\boldsymbol{\theta})\), which we abbreviate by \(q\), to within a factor of \(\lambda\). That is, \(p\in[q/\lambda,dq]\). By choosing \(k\) large enough20 such that \([q/\lambda,dq]\) cannot contain both \(1\) and \(\nicefrac{{1}}{{(1+2^{k-1})}}\), we can use \(q\) to determine whether \(p=1\) or \(p\leq\nicefrac{{1}}{{(1+2^{k-1})}}\). This allows us to determine \(\textsc{Sat}(\phi)\) in polynomial time with error probability \(<\nicefrac{{1}}{{3}}\), since by hypothesis \(q\) is computable in polynomial time with compact parameters. This shows that \(\textsc{Sat}\in\textup{BPP}/\operatorname{poly}=\textup{P}/\operatorname{ poly}\), implying \(\textup{NP}\subseteq\textup{P}/\operatorname{poly}\), contrary to our assumption. (\(\textup{BPP}/\operatorname{poly}\) is similar to \(\textup{P}/\operatorname{poly}\) but allows \(M^{\mathfrak{q}}\) to be a bounded-error probabilistic Turing machine.) 

Footnote 20: It suffices to ensure that \(1+2^{k-1}>\lambda^{2}\), so take any \(k>1+\log_{2}(\lambda^{2}-1)\).

**Theorem 4**.: _Assuming \(\textup{NP}\nsubseteq P/\operatorname{poly}\), there exists an efficiently computable weighted language \(\tilde{p}:V^{*}\to\mathbb{R}_{\geq 0}\) such that there is no \((M^{\mathfrak{q}},\boldsymbol{\Theta}^{\mathfrak{q}})\) where \(\boldsymbol{\Theta}^{\mathfrak{q}}=\{\boldsymbol{\theta}^{\mathfrak{q}}_{n}\mid n \in\mathbb{N}\}\) that satisfies all of the following properties (similar to SS3.1):_

* _the parameter size_ \(|\boldsymbol{\theta}^{\mathfrak{q}}_{n}|\) _grows only as_ \(O(\operatorname{poly}(n))\)__
* \(M^{\mathfrak{q}}(\boldsymbol{\theta}^{\mathfrak{q}}_{n})\) _returns a_ probabilistic _Turing machine_ \(q_{n}\) _in time_ \(O(\operatorname{poly}(n))\)__
* _there exists_ \(\lambda\geq 1\) _such that for each_ \(x\in V\cup\{\$\}\) _and_ \(\hat{\mathbf{x}}\in V^{*}\) _with_ \(|\hat{\mathbf{x}}|\leq n\) _and_ \(p(x\mid\hat{\mathbf{x}})>0\)_, the probabilistic computation_ \(q_{n}(\hat{\mathbf{x}})\) _has probability_ \(>\nicefrac{{2}}{{3}}\) _of approximating_ \(p(x\mid\hat{\mathbf{x}})\) _to within a factor of_ \(\lambda\) _(that is,_ \(q_{n}(\hat{\mathbf{x}}x)/p(x\mid\hat{\mathbf{x}})\in[1/\lambda,\lambda]\)_)_
* \(q_{n}\) _runs on those inputs_ \(\hat{\mathbf{x}}x\) _in time_ \(O(\operatorname{poly}(n))\)__

_Moreover, the statement above remains true_

* _when the approximation guarantee is only required to hold for prefixes_ \(\hat{\mathbf{x}}\) _where_ \(\{\mathbf{x}:\hat{\mathbf{x}}\leq\mathbf{x}\}\) _is finite (so_ \(p(x\mid\hat{\mathbf{x}})\) _is computable by brute force)_
* _or, when_ \(\operatorname{support}(\tilde{p})=V^{*}\)__

Proof.: It remains to show that the statement remains true with modification (a) and with modification (b). For (a), the proof of Lemma A.1 suffices, since it reduces Sat to approximate local probability queries of the stated form. That is, the true local probabilities \(p(x\mid\hat{\mathbf{x}})\) that can be computed with finite summations, thanks to the structure of our example language \(\tilde{p}\), which guarantees that the prefix \(\hat{\mathbf{x}}\) can only continue with suffixes of a fixed length that is easily determined from \(\hat{\mathbf{x}}\).

For modification (b), again let \(V=\mathbb{B}=\{\emptyset,1\}\). Choose some \(\epsilon>0\) (any choice will do), and let

\[\tilde{p}_{1}(\mathbf{x}) =\begin{cases}(\tfrac{1}{3})^{|\mathbf{x}+1|}&\mbox{if $\mathbf{ x}=\boldsymbol{\phi}\mathbf{a}$ where $\boldsymbol{\phi}=\mathrm{enc}(\phi)$}\\ &\qquad\quad\mbox{and $\mathbf{a}$ satisfies $\phi$}\\ 0&\qquad\mbox{otherwise}\end{cases}\] \[\tilde{p}_{2}(\mathbf{x}) =(\tfrac{1}{6})^{|\mathbf{x}+1|}>0\] \[\tilde{p}(\mathbf{x}) =\tilde{p}_{1}(\mathbf{x})+\epsilon\cdot\vec{p}_{2}(\mathbf{x})\] 

We use \(Z_{1},Z_{2},\) and \(Z\) respectively to denote normalizing constants of these three weighted languages. Note that \(\tilde{p}_{1}\) is the weighted language that was previously used in the proofs of Theorem 3.1 and Lemma A.1. Our new \(\tilde{p}\) is intended to be very similar while satisfying the additional condition (b). It is easy to show that \(\tilde{p}\) is efficiently computable, much as we showed for \(\tilde{p}_{1}\) in Theorem 3.1. Also, \(\tilde{p}\) is normalizable, since \(Z=Z_{1}+\epsilon\cdot Z_{2}\), where \(Z_{1}\leq(\frac{1}{3})/(1-\frac{2}{3})=1\) and \(Z_{2}=(\frac{1}{9})/(1-\frac{2}{9})=\frac{1}{7}\) are both finite.

The proof proceeds as in Lemma A.1, with \(\phi^{\prime}\) constructed from \(\phi\) as before. Recall that \(\phi\) has \(j\) variables, \(\phi^{\prime}\) has \(j+k\) variables, and \(|\mathbf{\phi}^{\prime}|=n\). We may assume WLOG that the encoding function enc is such that an encoded formula always has at least as many bits as the number of variables in the formula, so \(n\geq j+k\).

Notice that \(Z_{1}(\mathbf{\phi}^{\prime})\) sums over the satisfying assignments of \(\phi^{\prime}\), and there may be as few as one of these (if \(\phi\) is unsatisfiable). By contrast, \(Z_{2}(\mathbf{\phi}^{\prime})\) sums over an infinite number of continuations with positive probability. The faster decay rate of \(\frac{1}{9}\) in \(\tilde{p}_{2}\) was chosen to keep \(Z_{2}(\mathbf{\phi}^{\prime})\) small relative to \(Z_{1}(\mathbf{\phi}^{\prime})\) despite this. Specifically,

\[Z_{1}(\mathbf{\phi}^{\prime}\otimes\theta) =(\tfrac{1}{3})^{n+j+k+1}\] \[Z_{1}(\mathbf{\phi}^{\prime}1) =(\tfrac{1}{3})^{n+j+k+1}\cdot 2^{k-1}\] \[\qquad\cdot(\text{$\#$ of satisfying assignments of $\phi$})\] \[Z_{2}(\mathbf{\phi}^{\prime}\otimes\theta) =(\tfrac{1}{9})^{n}\cdot\tfrac{1}{9}\cdot(\tfrac{1}{9}/(1-\tfrac {2}{9}))\] \[=\tfrac{1}{7}\cdot(\tfrac{1}{5})^{2(n+1)}\] \[<\tfrac{1}{7}\cdot Z_{1}(\mathbf{\phi}^{\prime}\otimes\theta)\] \[(\text{because $2(n+1)>n+j+k+1$})\] \[Z_{2}(\mathbf{\phi}^{\prime}1) =Z_{2}(\mathbf{\phi}^{\prime}\otimes\theta)\]

As in the proof of Lemma A.1, we will show that \(p(\theta\mid\mathbf{\phi}^{\prime})\) is much larger when \(\phi\) is unsatisfiable. Recall that \(Z(\hat{\mathbf{x}})=Z_{1}(\hat{\mathbf{x}})+\epsilon\cdot Z_{2}(\hat{\mathbf{ x}})\). When \(\phi\) has zero satisfying assignments,

\[p(\theta\mid\mathbf{\phi}^{\prime}) =\frac{Z(\mathbf{\phi}^{\prime}\otimes\theta)}{Z(\mathbf{\phi}^{\prime} \otimes\theta)+Z(\mathbf{\phi}^{\prime}1)}\] \[=\frac{Z(\mathbf{\phi}^{\prime}\otimes\theta)}{Z_{1}(\mathbf{\phi}^{ \prime}\otimes\theta)+\epsilon\cdot Z_{2}(\mathbf{\phi}^{\prime}\otimes\theta)+ \epsilon\cdot Z_{2}(\mathbf{\phi}^{\prime}1)}\] \[>\frac{Z(\mathbf{\phi}^{\prime}\otimes\theta)}{Z_{1}(\mathbf{\phi}^{ \prime}\otimes\theta)+2\cdot\tfrac{\epsilon}{7}\cdot Z_{1}(\mathbf{\phi}^{\prime} \otimes\theta)}\]

whereas if \(\phi\) has at least one satisfying assignment, then

\[p(\theta\mid\mathbf{\phi}^{\prime}) =\frac{Z(\mathbf{\phi}^{\prime}\otimes\theta)}{Z(\mathbf{\phi}^{\prime} \otimes\theta)+Z(\mathbf{\phi}^{\prime}1)}\] \[<\frac{Z(\mathbf{\phi}^{\prime}\otimes\theta)}{Z_{1}(\mathbf{\phi}^{ \prime}\otimes\theta)+Z_{1}(\mathbf{\phi}^{\prime}1)}\] \[\leq\frac{Z(\mathbf{\phi}^{\prime}\otimes\theta)}{Z_{1}(\mathbf{\phi}^{ \prime}\otimes\theta)+2^{k-1}Z_{1}(\mathbf{\phi}^{\prime}\otimes\theta)}\]

This rewrites both probabilities in terms of \(Z.(\mathbf{\phi}^{\prime}0)\) quantities, which do not depend on the number of satisfying assignments. So now we can see that the first probability is at least \((1+2^{k-1})~{}/~{}(1+\tfrac{2\epsilon}{7})\) times as large as the second probability. Choose \(k\) large enough21 such that \([q/\lambda,\lambda q]\) cannot contain both probabilities, and complete the proof as in Lemma A.1. 

Footnote 21: It suffices to ensure that \((1+2^{k-1})/(1+\tfrac{2\epsilon}{7})>\lambda^{2}\), so take any \(k>1+\log_{2}(\lambda^{2}\cdot(1+\tfrac{2\epsilon}{7})-1)\).

**Theorem 4**.: _The set \(\{\tilde{p}:\tilde{p}\text{ is normalizable},\tilde{p}\in\mathrm{EC},\tilde{p}\notin \mathrm{ELN}\}\) is not empty._

Theorem 4 states that some normalizable EC distributions cannot be expressed as ELN distributions. The proof is based on the undecidability of the halting problem, rather than the assumed inefficiency of the Boolean satisfiability problem. Thus, unlike Theorem 3.1, it does _not_ rely on the assumption that \(\operatorname*{NP}\nsubseteq\operatorname*{P}/\mathrm{poly}\), or even on the weaker assumption that \(\operatorname*{P}\neq\operatorname*{NP}\).

Proof.: Given any unweighted language \(L\subseteq\mathbb{B}^{*}\), we can define a normalizable weighted language \(\tilde{p}\) with support \(L\) by \(\tilde{p}(\mathbf{x})=\nicefrac{{1}}{{3}}^{|\mathbf{x}|+1}\) for \(\mathbf{x}\in L\) and \(\tilde{p}(\mathbf{x})=0\) otherwise. Moreover, if \(L\in\operatorname*{P}\), then \(\tilde{p}\in\mathrm{EC}\).

For our purposes, we take \(L\) to consist of all strings of the form \(\mathbf{x}^{(1)}\mathbf{x}^{(2)}\), for which there exists a deterministic Turing machine \(M\) such that \(\mathbf{x}^{(1)}=\operatorname*{enc}(M)\) (where \(\operatorname*{enc}\) is a prefix-free encoding function) and \(\mathbf{x}^{(2)}\) encodes an accepting execution path of \(M\) on an empty input. (Such a path may be represented as a sequence of transitions of \(M\) that begins with an initial state and ends at an accepting state.) Note that any deterministic TM \(\mathbf{x}^{(1)}\) can be paired with at most one accepting execution path \(\mathbf{x}^{(2)}\), and cannot be paired with any \(\mathbf{x}^{(2)}\) if it does not halt.

Clearly \(L\in\operatorname*{P}\): given \(\mathbf{x}\in\mathbb{B}^{*}\), we can decide whether \(\mathbf{x}\in L\) by first checking if \(\mathbf{x}\) can be expressed as a concatenation of strings \(\mathbf{x}^{(1)}\) and \(\mathbf{x}^{(2)}\) of the required form. Then we build \(M\) from \(\mathbf{x}^{(1)}\) and simulate it to check the transitions in \(\mathbf{x}^{(2)}\) on \(M\) step-by-step. This can be done in \(O(\mathrm{poly}(|\mathbf{x}|))\) total time. We conclude that the \(\tilde{p}\) derived from \(L\) is EC.

 

Now, \(Z({\bf x}^{(1)})>0\) iff \(M\) halts on the empty input. But this undecidable problem could be decided if there were an ELN weighted language that had support \(L\), since then \(Z({\bf x}^{(1)})~{}/~{}Z\) could be found as a product of local conditional probabilities, \(\prod_{t=1}^{|{\bf x}^{(i)}|}p(x_{t}^{(1)}~{}|~{}{\bf x}^{(1)}_{<t})\), that could each be computed by a Turing machine. Therefore \(\vec{p}\) is not ELN.

We have shown above that a certain unweighted language \(L\) is not the support of any ELN distribution. We conjecture that it is also not the support of any ELNCP distribution;22 a proof of this would strengthen Theorem 5 to become an unconditional version of Theorem 1. However, ELNCP weighted languages do have more power than ELN weighted languages, as we now show.

Footnote 22: We have not attempted to prove this. Our loose intuition is that the compact parameters of an ELNCP language may help it to memorize some small part of \(L\), but the halting problem would still be undecidable when restricted to the rest of \(L\)[4] and Rybalov, 2008.

**Theorem 6**.: _The set \(\{\tilde{p}:\tilde{p}\text{ is normalizable},\tilde{p}\in\mathrm{EC},\tilde{ p}\in\mathrm{ELNCP},\tilde{p}\notin\mathrm{ELN}\}\) is not empty._

Theorem 6 justifies why this region is drawn as non-empty in Figure 2. Again, it does not rely on the assumption NP \(\not\subseteq\mathrm{P/poly}\) or P \(\neq\) NP. Note that Theorem 5 can be regarded as a corollary of Theorem 6.

Proof.: The weighted language \(\tilde{p}\) constructed in Theorem 5 is not necessarily ELNCP. To fix this, we modify the construction to obtain a weighted language \(\tilde{p}^{\prime}\) with _sparse_ support \(L^{\prime}\). We will again be able to show that \(\tilde{p}^{\prime}\) is EC and not ELN. To show that \(\tilde{p}^{\prime}\) is also ELNCP, we will rely on the sparsity of \(L^{\prime}\), meaning that prefixes\((L^{\prime})\triangleq\{\hat{{\bf x}}^{\prime}:(\exists{\bf x}^{\prime}\in L^{\prime})\ \hat{{\bf x}}^{\prime}\leq{\bf x}^{\prime}\}\) contains at most \(O(\operatorname{poly}(n))\) strings \(\hat{{\bf x}}^{\prime}\) of length \(\leq n+1\). Thus, we can use \(\Theta_{n}^{\mathbf{q}}\) to store all of those strings \(\hat{{\bf x}}^{\prime}\) in polynomial space, along with their \(Z(\hat{{\bf x}}^{\prime})\) values.23 Notice that all strings \(\hat{{\bf x}}^{\prime}\notin\operatorname{prefixs}(L^{\prime})\) have \(Z(\hat{{\bf x}}^{\prime})=0\), so they need not be stored. Now for any \(\hat{{\bf x}}^{\prime}\) of length \(\leq n\), a Turing machine that consults \(\theta_{n}^{\mathbf{q}}\) can compute \(q(x~{}|~{}\hat{{\bf x}}^{\prime})=Z_{\tilde{p}^{\prime}}(\hat{{\bf x}}^{ \prime}x)~{}/~{}Z_{\tilde{p}^{\prime}}(\hat{{\bf x}}^{\prime})\) in time \(O(\operatorname{poly}(n))\) as desired, establishing that \(\tilde{p}^{\prime}\) is ELNCP.

Footnote 23: More precisely, the first \(b\) bits of \(Z(\hat{{\bf x}}^{\prime})\leq 1\) may be stored in \(\Theta_{n+b}^{\mathbf{q}}\), when ELNCP is defined as explained in our “Remark on irrationality” above.

We may define \(\tilde{p}^{\prime}\) as follows. Let sparsify\(({\bf x})\) be a version of \({\bf x}\) with many extra \(\emptyset\) symbols inserted: specifically, it inserts \(2^{\prime}\) copies of \(\emptyset\) immediately before the \(t^{\rm th}\) bit of \({\bf x}\), for all \(1\leq t\leq|{\bf x}|\). We construct \(\tilde{p}^{\prime}\) so that \(\tilde{p}^{\prime}(\mbox{sparsify}({\bf x}))=\tilde{p}({\bf x})\). Specifically, let \(L^{\prime}\triangleq\mbox{sparsity}(L)\). The inverse function sparsify\({}^{-1}({\bf x}^{\prime})\) is defined on exactly \({\bf x}^{\prime}\in L^{\prime}\), and is unique when defined. For all \({\bf x}^{\prime}\in\mathbb{B}^{*}\), let \(\tilde{p}^{\prime}({\bf x}^{\prime})\triangleq\tilde{p}(\mbox{sparsify}^{-1}({ \bf x}^{\prime}))\) if \(\mbox{sparsify}^{-1}({\bf x}^{\prime})\) is defined, and \(\tilde{p}^{\prime}({\bf x}^{\prime})\triangleq 0\) otherwise. This can be computed in polytime, so \(\tilde{p}^{\prime}\) is EC. Also, its support \(L^{\prime}\) is sparse as claimed, so \(\tilde{p}^{\prime}\) is ELNCP.

Finally, we claim \(\tilde{p}^{\prime}\) is not ELN. A given deterministic Turing machine \(M\) halts on the empty input iff \(\operatorname{enc}(M)\in\operatorname{prefixs}(L)\) iff \(\mbox{sparsify}(\operatorname{enc}(M))\in\operatorname{prefixs}(L^{\prime})\) iff \(Z^{\prime}(\mbox{sparsify}(\operatorname{enc}(M)))>0\). But as in the proof of Theorem 5, this would be decidable if \(\tilde{p}^{\prime}\) were ELN as defined in SS3.1, since then we would have a Turing machine to compute the local conditional probabilities \(p^{\prime}(\hat{{\bf x}}_{l}~{}|~{}\hat{{\bf x}}_{<l})\) for \(\hat{{\bf x}}=\mbox{sparsify}(\operatorname{enc}(M))\). 

**Theorem 7**.: _There exists a light marginalization \(p\) of an ELN distribution, such that \(\operatorname{support}(p)\) is an NP-complete language._

Proof.: We will construct \(p\) such that \(\operatorname{support}(p)\) is the NP-complete language Sat of all satisfiable boolean formulas. The idea is to construct an ELN distribution \(r\) that can autoregressively generate any assignment \({\bf a}\) followed by any formula \(\phi\) that is satisfied by \({\bf a}\). Thus, if we delete the \({\bf a}\) prefixes, the support consists of exactly the satisfiable formulas \(\phi\) (or more precisely, their encodings \(\boldsymbol{\phi}\)).

To be more precise, we will have \(\operatorname{support}(r)\) be the language \(L=\{{\bf a}\#\boldsymbol{\phi}~{}|~{}{\bf a}\in\mathbb{B}^{*}\text{ and $\phi$ is a formula satisfied by ${\bf a}$}\}\). This is defined similarly to the support language \(L\) in SS3.2, but with the order of \(\boldsymbol{\phi}\) and \({\bf a}\) crucially swapped: \(r\) will now generate the "solution" \({\bf a}\)_before_ the "problem" \(\boldsymbol{\phi}\). The alphabet \(V\) of this language contains at least the symbols \(\{{\bf 0},{\bf 1},\#\}\), where \(\#\) is a separator symbol, and any other symbols needed to encode \(\phi\) as \(\boldsymbol{\phi}\). The marginalization operator \(\mu\) maps \({\bf a}\#\boldsymbol{\phi}\) to \(\boldsymbol{\phi}\).

Let \(j=|{\bf a}|\). As in SS3.2, we will require \(\phi\) to use all of the variables \(A_{1},\ldots,A_{j}\) (and only those variables), implying that \(|\boldsymbol{\phi}|\geq j\). This ensures that marginalizing over the \(j+1\) latent symbols is only light marginalization since \(j+1+|\boldsymbol{\phi}|\in O(\operatorname{poly}(|\boldsymbol{\phi}|))\). For convenience, we will also require \(\phi\) to be a CNF formula. These requirements shrink \(\operatorname{support}(p)\) but do not affect its NP-completeness.

The remaining challenge is to construct an autoregressive distribution \(r\) whose support is \(L\). We can think of this distribution as describing an efficient procedure for randomly generating a string from left to right so that the procedure generates the \(t^{\rm th}\) symbol 

in time \(O({\rm poly}(t))\), terminates with probability 1,24 has positive probability of producing any string in \(L\), and has zero probability of producing any string not in \(L\). Below we give such a procedure.25

Footnote 24: Phase 1 almost surely terminates after a finite number of bits. Phase 2 almost surely terminates after a finite number of clauses, and each clause almost surely terminates after a finite number of literals. “Almost surely” means “with probability 1.” For example, **a**= 010 and \(j=3\).

Footnote 25: Our presentation here makes use of an infinite alphabet that includes symbols such as \(A_{i}\) and \(-\Lambda_{i}\) for all \(i\in\mathbb{N}_{>0}\), as well as symbols such as \(\mathbf{0}\), \(\mathbf{1}\), \(\land\), \(\lor\). We implicitly invoke some prefix-free encoding scheme to translate each symbol into a fixed string over the finite alphabet \(V\).

1. First, the procedure generates **a#** as a sequence of random symbols from \(\{\boldsymbol{0},1,\boldsymbol{\#}\}\), making a uniform draw at each step. It stops immediately after generating # for the first time. The string generated before # is called **a** and we let \(j=|\textbf{a}|\). For example, \(\textbf{a}=\texttt{010}\) and \(j=3\).
2. Second, the procedure must generate the encoding \(\boldsymbol{\phi}\) of a random CNF formula \(\phi\) that is satisfied by **a**, such as \((A_{2}\vee\neg A_{3}\vee\neg A_{2}\lor A_{2})\wedge(\neg A_{1})\) in our example. This involves generating a random sequence of \(0\) or more satisfied clauses connected by \(\land\). At each step, the procedure decides whether to generate a new clause or end the formula. The probability of generating a new clause is ordinarily \(\nicefrac{{1}}{{2}}\). However, this probability is \(1\) if the previous clauses do not yet mention all the variables \(A_{1},\ldots,A_{j}\). How does it generate each satisfied clause? This involves generating a sequence of literals connected by \(\lor\), at least one of which must be true. At each step of this subroutine, it uniformly chooses an integer \(i\in[1,j]\), and then flips a fair coin to decide whether to add the literal \(A_{i}\) or \(\neg A_{i}\) to the current clause. If the clause is now satisfied by **a** (_i.e._, at least one of the literals is true), it then flips another fair coin to decide whether to end the clause.

\(r\) is ELN because there exists a Turing machine that computes from input \(\hat{\bf x}\) -- in time \(O({\rm poly}(|\hat{\bf x}|))\) -- the probability that the next symbol generated after the prefix \(\hat{\bf x}\) would be \(x\), under the above procedure. As discussed in footnote 7, that probability equals \(r(x\mid\hat{\bf x})\) -- which is what our Turing machine is required to return -- because the above procedure almost surely terminates (footnote 24), ensuring that \(r\) is a consistent probability distribution over \(V^{*}\) (that is, \(\sum_{\textbf{x}\in V^{*}}r(\textbf{x})=1\)). 

Theorem8: _The following statements are equivalent for any nonempty \(L\subseteq V^{*}\):_

1. \(L\in{\rm NP/poly}\)_._
2. \(L\) _is the support of a light marginalization of an ELNCP distribution._
3. \(L\) _is the support of a light marginalization of an ECCP weighted language._

Proof: (b) implies (c) since any ELNCP distribution is an ECCP weighted language (Lemma 2). (c) implies (a) by Lemma A.2 below. Finally, (a) implies (b) by Lemma A.3 below. 

Lemma: For any ECCP weighted language \(\tilde{r}\), if \(\tilde{p}\) is a light marginalization of \(\tilde{r}\), then \({\rm support}(\tilde{p})\in{\rm NP/poly}\).

Notice that this lemma concerns the class \({\rm NP/poly}\), not \({\rm P/poly}\) (see SS2.4). The proof is straightforward.

Proof: Suppose \(\tilde{r}\) is ECCP via \((M^{\tilde{\bf r}},\boldsymbol{\theta}^{\tilde{\bf r}})\), and \(\mu\) is the marginalization operator such that \(\tilde{p}(\textbf{x})=\sum_{\textbf{x}:\textbf{u}(\textbf{z})=\textbf{x}}\tilde {r}(\textbf{z})\). By the light marginalization assumption, there is a polynomial \(f\) such that \(|\textbf{z}|\leq f(|\mu(\textbf{z})|)\).

To prove \({\rm support}(\tilde{p})\in{\rm NP/poly}\), we must show that there exists \((M,\boldsymbol{\Theta})\) such that for all \(n\geq 0\), a _nondeterministic_ Turing machine \(M_{n}\) can be constructed as \(M(\boldsymbol{\theta}_{n})\) in time \(O\left({\rm poly}(n)\right)\), which can in turn decide in time \(O\left({\rm poly}(n)\right)\) whether \(\tilde{p}(\textbf{x})>0\) for any **x** with \(|\textbf{x}|=n\).

Deciding \(\tilde{p}(\textbf{x})>0\) means deciding whether \((\exists\textbf{z}\in V^{*})~{}\mu(\textbf{z})=\textbf{x}\) and \(\tilde{r}(\textbf{z})>0\). But if \(|\textbf{x}|=n\),the first condition \(\mu(\textbf{z})=\textbf{x}\) implies \(|\textbf{z}|\leq f(|\mu(\textbf{z})|)=f(|\textbf{x}|)=f(n)\). Thus, we need \(M_{n}\) to nondetermistically check only the **z** of length up to \(f(n)\) to see whether \(\mu(\textbf{z})=\textbf{x}\) and \(\tilde{r}(\textbf{z})>0\).

How can \(M_{n}\) check a string **z** of length \(m\)? It can decide the first condition \(\mu(\textbf{z})=\textbf{x}\) in time \(O\left({\rm poly}(m)\right)\), since the marginalization operator \(\mu\) is a polyline function. To decide the second condition \(\tilde{r}(\textbf{z})>0\), it must construct the (deterministic) Turing machine \(M^{\tilde{\bf r}}(\boldsymbol{\theta}_{m}^{\tilde{\bf r}})\) and then apply it to **z** to obtain \(\tilde{r}(\textbf{z})\): since \(\tilde{r}\) is ECCP, both steps take time \(O\left({\rm poly}(m)\right)=O\left({\rm poly}(f(n))\right)\subseteq O\left({ \rm poly}(n)\right)\) as required.

However, this means that \(M_{n}=M(\boldsymbol{\theta}_{n})\) must have access to the parameter vectors \(\boldsymbol{\theta}_{m}^{\tilde{\bf r}}\) for all \(m\leq f(n)\). We therefore make \(\boldsymbol{\theta}_{n}\) include this collection of parameter vectors. Each \(|\boldsymbol{\theta}_{m}^{\tilde{\bf r}}|\in O({\rm poly}(m))\subseteq O\left({ \rm poly}(n)\right)\) since \(\tilde{r}\) is ECCP. So \(|\boldsymbol{\theta}_{n}|\in O\left({\rm poly}(n)\right)\) as required. 

Lemma: For any \(L\in{\rm NP/poly}\), there exists a light marginalization \(p\) of an ELNCP distribution, such that \({\rm support}(p)=L\).

Lemma: resembles Theorem 7, but it constructs distributions for _all_\(L\in{\rm NP/poly}\), not just for _one 

_particular \(L\in{\rm NPC}\). The proof is similar but more complicated. In both cases, the goal is to demonstrate how an ELNCP distribution \(r\) can define a left-to-right stochastic string generation process such that the suffix of the generated string must be in \(L\) and can be any element of \(L\).

Our string generation process in this case is inspired by rejection sampling, a widely used method for sampling from an energy-based model with support \(L\). The standard scheme is to first sample a string **x** from a tractable distribution \(q\) such that \({\rm support}(q)\supseteq L\), then accept the sample with an appropriate probability, which is 0 if \({\bf x}\not\in L\). The process is repeated until a sample is finally accepted. There is no guarantee that this standard scheme will terminate in polynomial time, however. Fortunately, in our setting, we are not trying to match our sampling distribution \(p\) to a given energy-based model, but simply match its support to a given language \(L\). We make use of the polysize parameter vectors of ELNCP languages to store certain 'fallback strings' that are guaranteed to be in the desired language \(L\). Wherever ordinary rejection sampling would reject a string and try generating another, we switch to generating a stored fallback string of an appropriate length. This scheme places all of the rejected probability mass on the small set of fallback strings (in contrast to rejection sampling, which in effect throws away this mass and renormalizes). The advantage is that it does not iterate indefinitely. At a high level, \(r\) is a distribution over strings \({\bf z}\) that record traces of this generative story we describe above.

Proof: WLOG we assume \(L\) uses the alphabet \(V=\{{\bf 0},1,\#\}\). In the case where \(L\) is finite, the result is trivial. We simply define \(r({\bf x})=\nicefrac{{1}}{{|L|}}\) for \({\bf x}\in L\) and \(r({\bf x})=0\) otherwise. We then take \(p=r\) (a trivial marginalization). It is easy to show that \(r\) is ELN, and therefore ELNCP as desired, by constructing an appropriate Turing machine that maps \(\hat{\bf x}\) to \(r(x~{}|~{}\hat{\bf x})\) in time \(O(|\hat{\bf x}v|)\), for any \(\hat{\bf x}\) that is a prefix of some string in \(L\) and any \(x\in V\cup\{{\bf$\}}\). The finite state table of the Turing machine includes states that correspond to all possible strings \(\hat{\bf x}\), with transitions arranged in a trie. It reads the input string \(\hat{\bf x}\) from left to right to reach the state corresponding to \(\hat{\bf x}\). If it detects the end of the input while in that state, it writes \(r(x~{}|~{}\hat{\bf x})\) on the output tape.

Now we consider the case where \(L\) is infinite. For each \(j\in\mathbb{N}_{\geq 0}\), let the 'fallback string' \({\bf x}^{(j)}\) be some string in \(L\) of length \(\geq j\). For definiteness, let us take it to be the shortest such string, breaking ties lexicographically. At least one such string does exist because \(L\) is infinite, so \({\bf x}^{(j)}\) is well-defined.

Also, since \(L\in{\rm NP/poly}\) (SS2.4), let \((M,\mathbf{\Theta})\) be an ordered pair and \(f\) be a polynomial such that \(M_{j}=M(\theta_{j})\) nondeterministically accepts **a** within \(\leq f(j)\) steps iff \({\bf a}\in L\).

As in the proof of Theorem 7, we now describe a procedure for randomly generating a string \({\bf z}\) from left to right. \({\bf z}\) will have the form **afb#c\({\bf d}\)**, where \({\bf d}\in L\) and the latent substring **afb#c** will be removed by the marginalization operator \(\mu\).

1. First we generate a random string \({\bf a}\in\mathbb{B}^{*}\) followed by \(\mathbf{\#}\), just as in the proof of Theorem 7. Again let \(j=|{\bf a}|\).
2. Next, we must consider whether \({\bf a}\in L\). We generate a random computation path **b** of \(M_{j}\) on input **a** until it either accepts (in which case we then generate #1 to record acceptance of **a**) or has run for \(f(j)\) steps without accepting (in which case we then generate #0 to record rejection).
3. In the former case (\(c=1\)) we finish by deterministically generating \({\bf d}\triangleq{\bf a}\in L\). In the latter case (\(c=\emptyset\)), a \(\notin L\), so we fall back and finish by deterministically generating \({\bf d}\triangleq{\bf x}^{(j)}\in L\).

Let \(r({\bf z})\) be the probability that the above procedure generates \({\bf z}\). \({\rm support}(r)\) is then the set of strings that can be generated by the above procedure. The marginalized language \(\mu({\rm support}(r))\) keeps just the **d** parts of those strings. It consists of all strings \({\bf a}\) that are accepted by at least one path **b** of \(M_{|{\bf a}|}\) (which are exactly the strings in \(L\)) together with the fallback strings (which form a subset of \(L\)). Thus, \(\mu({\rm support}(r))=L\) as desired.

We wish to show that \(r\) is ELNCP. In other words, some Turing machine \(M^{\mathfrak{q}}\) efficiently locally normalizes \(r\) with compact parameters \(\mathbf{\Theta}^{\mathfrak{q}}\), as defined in SS3.1. The parameters will be used to store information about the infinite set of fallback strings.

In particular, for each \(n\), \(\boldsymbol{\theta}_{n}^{\mathfrak{q}}\) must have enough information to construct a Turing machine \(q_{n}=M^{\mathfrak{q}}(\boldsymbol{\theta}_{n}^{\mathfrak{q}})\) such that \(q_{n}(\hat{\textbf{z}}z)\) returns \(r(z~{}|~{}\hat{\textbf{z}})\) for all \(z\in V\cup\{{\bf$\}}\) and all \(\hat{\textbf{z}}\) with \(|\hat{\textbf{z}}|\leq n\) and \(Z(\hat{\textbf{z}})>0\). Here \(Z(\hat{\textbf{z}})>0\) means that \(\hat{\textbf{z}}\) is a prefix of a string \({\bf z}={\bf a}\#{\bf b}\#c{\bf d}\) that could be generated by the above procedure. The computation \(q_{n}(\hat{\textbf{z}}z)\) proceeds by simulating the sequence of choices in the above procedure that would be required to generate \(\hat{\textbf{z}}\), and then returning the probability that the procedure would generate symbol \(z\) next. That probability equals \(r(z~{}|~{}\hat{\textbf{z}})\) as desired because the above procedure 

almost surely terminates (as explained at the end of the proof of Theorem 4.1).

In general, the computation \(q_{n}(\mathbf{z}z)\) may have to construct \(M_{j}=M(\theta_{j})\) and simulate it on \(\mathbf{a}\) (for \(j=|\mathbf{a}|\)) if \(z\) falls in the \(\mathbf{b}\#c\) portion of \(\hat{\mathbf{z}}\), and it may have to look up a character of the fallback string \(\mathbf{x}^{(j)}\$\) if \(z\) falls in the \(\mathbf{d}\) portion of \(\hat{\mathbf{z}}\) or terminates that portion with \(z=\$\) Fortunately \(j<n\), and fortunately if the computation looks up the \(t^{\text{th}}\) character of \(\mathbf{x}^{(j)}\$\) then \(t<n\). Thus, constructing and simulating \(M_{j}\) can be done in time \(O\left(\operatorname{poly}(j)\right)\subseteq O\left(\operatorname{poly}( n)\right)\), and looking up the \(t^{\text{th}}\) character of \(\mathbf{x}^{(j)}\$\) can be achieved with access to the first \(n\) characters of each of \(\mathbf{x}^{(1)},\ldots,\mathbf{x}^{(n)}\), which can be stored by \(\boldsymbol{\theta}_{n}^{\text{q}}\) in space \(O\left(n^{2}\right)\). It follows that \(M^{\text{q}}\) can construct and apply \(q_{n}\) in polynomial time with access to compact parameters \(\boldsymbol{\Theta}^{\text{q}}\), so \(r\) is ELNCP.

## Appendix B Implementation details of REBMs

### Modeling finite subsets of infinite languages

The experiments of this paper are conducted on datasets where we only observe strings that are finitely long. Given a possibly infinite language \(L\), we use the notation \(L_{\leq T}=\{\mathbf{x}~{}|~{}\mathbf{x}\in L,|\mathbf{x}|\leq T\}\) for the subset of strings that are most \(T\) symbols long. Specific values of \(T\) for datasets used in our experiments are listed in SectionD.1.

### Design of base models \(p_{0}\)

\(p_{0}\) can be any distribution over \(L_{\leq T}\)26 provided that we can sample from it, and evaluate \(p_{0}(\mathbf{x}),\forall\mathbf{x}\in L_{\leq T}\), both in \(O(\operatorname{poly}(|\mathbf{x}|))\). In this work, we experiment with two designs of \(p_{0}\): GRU- and Transformer-based locally normalized language models. GRU-based models are used in WikiText and Yelp experiments. The GRU-based \(p_{0}\)'s are parametrized with 2-layer GRUs with 500 hidden units, and word embeddings of dimension size 500.

Footnote 26: Note that since \(p_{0}\) does not have support over \(L\), it has to assign \(p(\$\mid\mathbf{x}_{1...T})=1\), which is generally not an issue.

As for Transformer-based \(p_{0}\)'s, we make use of Grover models Zellers et al. (2019), which effectively are GPT-2 models trained on the aforementioned RealNews dataset. In this work, we experiment with the 'base' variant of public available weights, which are 12-layered Transformers, with 12 heads, and 768 hidden units.

### Design of discriminators \(g_{\boldsymbol{\theta}}\)

We formulate \(g_{\boldsymbol{\theta}}(\mathbf{x})\) as a summation of scores at positions \(1\dots|\mathbf{x}|\), passed through an activation function \(f\):

\[g_{\boldsymbol{\theta}}(\mathbf{x})=f\left(\sum_{i=1}^{|\mathbf{ x}|}g_{t}(\mathbf{x};\boldsymbol{\theta})\right). \tag{1}\]

To verify whether lower-bounding \(g_{\boldsymbol{\theta}}\) would help with learning, as we discuss in SS4.1, we experiment with two variants of \(f\):

* **tanh**: \(f(x)=2\cdot\tanh(x)\)
* **softplus**: \(f(x)=-\log(1+\exp(x+s))\)

The former one is bounded between \((-2,2)\), while the second one has range \((-\infty,0)\). The offset term \(s\) in the softplus activation function determines initial values of \(Z_{\boldsymbol{\theta}}\). In this paper we set \(s=20\).

The design of \(g_{t}(\mathbf{x};\boldsymbol{\theta})\) follows their base model counterparts: we use Bi-GRU discriminators for GRU base models; and bi-directional Transformer discriminators for Transformer ones. For GRUs \(g_{t}(\mathbf{x};\boldsymbol{\theta})=\mathbf{h}_{t}\cdot x_{t}\), For Transformers \(g_{t}(\mathbf{x};\boldsymbol{\theta})=\sum\mathbf{h}_{t}\) where \(\mathbf{h}_{t}\) are the hidden states at time step \(t\). In both cases, the discriminators have access to information of the whole sequence \(\mathbf{x}\) at any timestep: the Bi-GRU discriminators achieve this through the bi-directional RNNs, and the Transformers through the attention mechanism without directional masking.

### Training procedure

As we note in SS4.1, MLE-based training methods are generally not feasible for globally normalized models. We therefore opt to train our model using the ranking variant of noise contrastive estimation (NCE) Ma and Collins (2018), which does not require samples from \(p_{0}\) and has a simple form for residual LMs. Using \(p_{0}\) as a _noise distribution_, NCE training requires minimizing the following single-sequence loss, in expectation over the true distribution \(p\):

\[\mathcal{L}_{\textsc{NCE}}(\boldsymbol{\theta},\mathbf{x},p_{0},K)=-\log\frac {\frac{\tilde{p}_{\boldsymbol{\theta}}}{p_{0}}(\mathbf{x})}{\sum_{k=0}^{K} \frac{\tilde{p}_{\boldsymbol{\theta}}}{p_{0}}(\mathbf{x}^{(k)})}, \tag{2}\]

where \(\mathbf{x}^{(0)}\triangleq\mathbf{x}\), \(\frac{\tilde{p}_{\boldsymbol{\theta}}}{p_{0}}(\mathbf{x})\triangleq\frac{\tilde {p}_{\boldsymbol{\theta}}(\mathbf{x})}{p_{0}(\mathbf{x})}\), and \(\mathbf{x}^{(1)}\dots\mathbf{x}^{(K)}\sim p_{0}\). Since \(\tilde{p}_{\boldsymbol{\theta}}(\mathbf{x})=p_{0}(\mathbf{x})\cdot\exp g_{ \boldsymbol{\theta}}(\mathbf{x})\), we have \(\frac{\tilde{p}_{\boldsymbol{\theta}}}{p_{0}}(\mathbf{x})=\exp g_{\boldsymbol{ \theta}}(\mathbf{x})\). The NCE minimization objective (2) now reduces to the simple form

\[\mathcal{L}_{\textsc{NCE}}(\boldsymbol{\theta},\mathbf{x},p_{0}, K)\\ =-g_{\boldsymbol{\theta}}(\mathbf{x})\\ +\log(\exp g_{\boldsymbol{\theta}}(\mathbf{x})+\sum_{k=1}^{K}\exp g _{\boldsymbol{\theta}}(\mathbf{x}^{(k)})).\] (3) 

Notice that minimizing the expected loss with stochastic gradient descent methods \({\cal L}_{\text{NCE}}\) defined in equation (3) requires only evaluating sequence probabilities under \(g_{\mathbf{\theta}}\), and tuning its parameters, but not the base model \(p_{0}\). We only need to generate the noise samples \(\{\mathbf{x}^{(k)}\sim q~{}|~{}k\in[K]\}\) from \(p_{0}\). This way we do not need to backpropagate through parameters of the base model \(p_{0}\), which can speed up training considerably when \(p_{0}\) is backed by a huge network. In fact, the training of \(g_{\mathbf{\theta}}\) can be completely agnostic to the design of \(p_{0}\), allowing for the application of finetuning any locally normalized \(p_{0}\).

Given the same discriminator \(g_{\mathbf{\theta}}\), the difference of KL-divergence between the true model \(p\) and residual language models \(\tilde{p}^{\prime}_{\mathbf{\theta}}(\mathbf{x})=p^{\prime}_{0}(\mathbf{x})\cdot \exp g_{\mathbf{\theta}}(\mathbf{x})\), and the KL-divergence between the true model and \(\tilde{p}^{\prime\prime}_{\mathbf{\theta}}(\mathbf{x})=p^{\prime\prime}_{0}( \mathbf{x})\cdot\exp g_{\mathbf{\theta}}(\mathbf{x})\), defined with base models \(p^{\prime}_{0}\) and \(p^{\prime\prime}_{0}\) respectively, can be written as

\[\operatorname*{KL}[p||p^{\prime}_{\mathbf{\theta}}]-\operatorname*{ KL}[p||p^{\prime\prime}_{\mathbf{\theta}}]\\ =\operatorname*{KL}[p||p^{\prime}_{0}]-\operatorname*{KL}[p||p^{ \prime\prime}_{0}]+\log\frac{Z^{\prime}}{Z^{\prime\prime}}, \tag{4}\]

where \(Z^{\prime}=\mathbb{E}_{\mathbf{x}\sim p^{\prime}_{0}}[\exp g_{\mathbf{\theta}}( \mathbf{x})]\), and \(Z^{\prime\prime}\) is similarly defined with \(p^{\prime\prime}_{0}\). As a direct result of equation (4), we can see that finding \(p^{\prime\prime}_{0}\) where \(\operatorname*{KL}[p||p^{\prime\prime}_{0}]<\operatorname*{KL}[p||p^{\prime}_ {0}]\) implies improvement in \(\operatorname*{KL}[p||p^{\prime\prime}_{\mathbf{\theta}}]\) over \(\operatorname*{KL}[p||p^{\prime}_{\mathbf{\theta}}]\), under mild conditions:

**Theorem B.1**.: _If \(\exists k>0\) such that \(\frac{\mathbb{E}_{\mathbf{x}\sim p^{\prime}_{0}}[\exp g_{\mathbf{\theta}}(\mathbf{ x})]}{\mathbb{E}_{\mathbf{x}\sim p^{\prime\prime}_{0}}[\exp g_{\mathbf{\theta}}( \mathbf{x})]}>\exp(-k)\) and \(\operatorname*{KL}[p||p^{\prime}_{0}]-\operatorname*{KL}[p||p^{\prime\prime}_ {0}]>k\) then \(\operatorname*{KL}[p||p^{\prime}_{\mathbf{\theta}}]>\operatorname*{KL}[p||p^{ \prime\prime}_{\mathbf{\theta}}]\)._

Proof.: \[\operatorname*{KL}[p||p^{\prime}_{\mathbf{\theta}}]-\operatorname*{KL}[p||p^{ \prime\prime}_{\mathbf{\theta}}]\\ =\mathop*{\mathbb{E}}_{\mathbf{x}\sim p}[\log p^{\prime\prime}_{ \mathbf{\theta}}(\mathbf{x})-\log p^{\prime}_{\mathbf{\theta}}(\mathbf{x})]\\ =\mathop*{\mathbb{E}}_{\mathbf{x}\sim p}[\log\frac{p^{\prime \prime}_{0}(\mathbf{x})\exp g_{\mathbf{\theta}}(\mathbf{x})}{\mathbb{E}_{\mathbf{x} \sim p^{\prime\prime}_{0}}[\exp g_{\mathbf{\theta}}(\mathbf{x})]}\\ -\log\frac{p^{\prime}_{0}(\mathbf{x})\exp g_{\mathbf{\theta}}( \mathbf{x})}{\mathbb{E}_{\mathbf{x}\sim p^{\prime}_{0}}[\exp g_{\mathbf{\theta}}( \mathbf{x})]}\\ -\log\frac{p^{\prime}_{0}(\mathbf{x})\exp g_{\mathbf{\theta}}( \mathbf{x})}{\mathbb{E}_{\mathbf{x}\sim p^{\prime}_{0}}[\exp g_{\mathbf{\theta}}( \mathbf{x})]}\\ =\mathop*{\mathbb{E}}_{\mathbf{x}\sim p}[\log p^{\prime\prime}_{ 0}(\mathbf{x})-\log p^{\prime}_{0}(\mathbf{x})]\\ +\mathop*{\mathbb{E}}_{\mathbf{x}\sim p}[\log\mathop*{\mathbb{ E}}_{\mathbf{x}\sim p^{\prime}_{0}}[\exp g_{\mathbf{\theta}}(\mathbf{x})]-\log\mathop*{ \mathbb{E}}_{\mathbf{x}\sim p^{\prime\prime}_{0}}[\exp g_{\mathbf{\theta}}( \mathbf{x})]]\\ =\operatorname*{KL}[p||p^{\prime}_{0}]-\operatorname*{KL}[p||p^{ \prime\prime}_{0}]\\ +\log\frac{\mathbb{E}_{\mathbf{x}\sim p^{\prime}_{0}}[\exp g_{\mathbf{ \theta}}(\mathbf{x})]}{\mathbb{E}_{\mathbf{x}\sim p^{\prime\prime}_{0}}[\exp g _{\mathbf{\theta}}(\mathbf{x})]}.\] (5)

Plugging assumptions \(\frac{\mathbb{E}_{\mathbf{x}\sim p^{\prime}_{0}}[\exp g_{\mathbf{\theta}}(\mathbf{ x})]}{\mathbb{E}_{\mathbf{x}\sim p^{\prime\prime}_{0}}[\exp g_{\mathbf{\theta}}( \mathbf{x})]}>\exp(-k)\) and \(\operatorname*{KL}[p||p^{\prime}_{0}]-\operatorname*{KL}[p||p^{\prime\prime}_ {0}]>k\) into equation (5), \(\operatorname*{KL}[p||p^{\prime}_{\mathbf{\theta}}]-\operatorname*{KL}[p||p^{ \prime\prime}_{\mathbf{\theta}}]>0\). 

Theorem B.1 suggests a training strategy that we first train the base model \(p_{0}\), then finetune \(g_{\mathbf{\theta}}\): under a roughly uniform \(g_{\mathbf{\theta}}\) (_e.g._ when \(\mathbf{\theta}\) is newly initialized), \(\mathbb{E}_{\mathbf{x}\sim p^{\prime}_{0}}[\exp g_{\mathbf{\theta}}]/\mathbb{E}_{ \mathbf{x}\sim p^{\prime\prime}_{0}}[\exp g_{\mathbf{\theta}}]\approx\exp(0)\); so improvements on the inclusive KL-divergence of base model \(\operatorname*{KL}[p||p_{0}]\) will mostly translate to improvement in \(\operatorname*{KL}[p||\tilde{p}_{\mathbf{\theta}}]\). Optimizing the base model (_i.e._ finding \(p^{\prime\prime}_{0}\) such that \(\operatorname*{KL}[p||p^{\prime\prime}_{0}]<\operatorname*{KL}[p||p^{\prime \prime}_{0}]\)) is much easier than directly minimizing \(\operatorname*{KL}[p||p^{\prime\prime}_{\mathbf{\theta}}]\): the former can be done by minimizing empirical cross entropy, which is computationally efficient, while the latter involves an intractable partition function \(\sum_{\mathbf{x}\in L_{ST}}\tilde{p}^{\prime}_{\mathbf{\theta}}(\mathbf{x})\).

Pseudocode for fine-tuning \(g_{\mathbf{\theta}}\) is listed in Algorithm 1.

### Computing normalized probabilities

The unnormalized probability \(\tilde{p}_{\mathbf{\theta}}(\mathbf{x})\) (in equation (1)) can be evaluated easily, and should suffice for (re)ranking purposes (_e.g._ for ASR and MT applications). However, the _normalized_ probability \(q_{\mathbf{\theta}}(\mathbf{x})\triangleq\frac{\tilde{p}_{\mathbf{\theta}}(\mathbf{x})}{ \mathbb{E}_{\mathbf{\theta}}(\mathbf{x})}\) does require computing the partition function \(Z_{\mathbf{\theta}}\). An unbiased importance sampling 

estimate of \(\Sigma_{\mathbf{x}\in L_{zT}}~{}\tilde{p}_{\mathbf{\theta}}(\mathbf{x})\) is

\[Z_{\mathbf{\theta}} =\sum_{\mathbf{x}\in L_{zT}}~{}\tilde{p}_{\mathbf{\theta}}(\mathbf{x})\] \[=\sum_{\mathbf{x}\in L_{zT}}~{}p_{0}(\mathbf{x})\exp g_{\mathbf{\theta }}(\mathbf{x})\] \[=\mathop{\mathbb{E}}_{\mathbf{x}^{-}p_{0}}\left[\exp g_{\mathbf{ \theta}}(\mathbf{x})\right]\] \[\approx\sum_{m=1}^{M}\frac{\exp g_{\mathbf{\theta}}(\mathbf{x}^{(m) })}{M}=\hat{Z}_{\mathbf{\theta}M}, \tag{6}\]

where \(\mathbf{x}^{(1)}\ldots\mathbf{x}^{(M)}\sim q_{0}\).

## Appendix C Comparison between REBMs and autoregressive models

We evaluate the effectiveness of REBMs on two different neural architectures (GRU- Transformer-based) and 3 datasets: WikiText Merity et al. (2017), YelpYelp), and RealNews Zellers et al. (2019), on the task of modeling sequence probabilities. An REBM \(\tilde{p}_{\mathbf{\theta}}\) has two components, \(g_{\mathbf{\theta}}\) and \(p_{0}\), and we would like to see how \(\tilde{p}_{\mathbf{\theta}}\) competes against \(p_{0}\) itself. We do not further tune \(p_{0}\) while training \(p_{\mathbf{\theta}}\). As a fair comparison, we also see how \(p_{0}^{\prime}\) compares against \(p_{0}\), where \(p_{0}^{\prime}\) is simply a version of \(p_{0}\) that has been trained as many additional epochs as were used to train \(p_{\mathbf{\theta}}\).

\(p_{0}\) models are pretrained on moderately large corpora (in GRU cases) or a very large corpus (in the Transformer case).28 We compare residual energy-based models \(\tilde{p}_{\mathbf{\theta}}\) to further-fine-tuned base models \(p_{0}^{\prime}\), on conservatively estimated (at the low end of 95% confidence interval) token perplexity and bootstrap-sampled log likelihood improvements. The results are in Table 2. Residual energy-based models show consistent perplexity improvement compared to \(p_{0}^{\prime}\) that are trained on the same data using the same maximum numbers of iterations. Although the improvement in log-likelihood of \(p_{\mathbf{\theta}}\) over \(p_{0}\) is modest (especially for RealNews experiments, where \(p_{0}\) is a very strong baseline), we verify that these improvements are all statistically significant (\(p<0.05\)) using bootstrapped test datasets.

Footnote 28: In the Transformer case we simply take \(p_{0}\) to be the Grover Zellers et al. (2019) pretrained language model, which is based on the GPT-2 Radford et al. (2019) architecture and performs competitively on news article generation.

We experiment with different designs of the discriminator \(g_{\mathbf{\theta}}\), evaluating the effectiveness of bounding \(g_{\mathbf{\theta}}\) and varying its number of parameters. We find that in Transformer-based experiments, bounding \(g_{\mathbf{\theta}}\) considerably helps with performance; but the opposite happens for GRU-based models. We speculate that this is due to the base models' performance: the Transformer base models have high parameter count and were trained on a lot of data; and the true distribution \(p\) likely is relatively similar to \(p_{0}\), and benefits from a small hypothesis space -- even though we don't know if the at-most-\(\epsilon\) error assumption in SS4.1 holds. On the other hand our GRU-based \(p_{0}\) has neither the capacity, nor the huge amount of training data. As a result, the unbounded variant \(g_{\mathbf{\theta}}\) (and \(q_{\mathbf{\theta}}\)) may end up learning a better approximation of \(p\).

## Appendix D Experimental details

### Datasets

Residual language model experiments are conducted on these datasets:

* **Segmented WikiText**: we take the standard WikiText-2 corpus Merity et al. (2017), and segment it into sequences at new line breaks. We discard all empty lines, and any line that starts with the '=' token. In effect, we obtain sequences that are mostly entire paragraphs. We also only keep lines that are shorter than 800 tokens after BPE tokenization. Because of our preprocessing, Segmented WikiText loses much interparagraph context information, and doesn't have the 'simple' header sequences that were in the original WikiText corpus, and is much harder to language-model.
* **Yelp**: the Yelp dataset (Yelp) contains business reviews. As in Segmented WikiText, We keep 

reviews shorter than 800 tokens.
* **RealNews**: we make use of the standard RealNews corpus comes from Zellers et al. (2019), which contains news articles that are up to \(1,024\) tokens long. In all experiments we tokenize with BPE tokenizers derived from the GPT-2 language models: the GRU models use Huggingface's implementation28 and the Transformers use Grover's29. Number of sequences in preprocessed datasets are listed in Table 3.

Footnote 28: [https://github.com/huggingface/transformers](https://github.com/huggingface/transformers)

Footnote 29: [https://github.com/rowanz/grover](https://github.com/rowanz/grover)

### Pretraining base models \(p_{0}\)

We use a pretrained Grover model as the base model in RealNews experiments. For GRU-based experiments, we train base models on WikiText and Yelp datasets using separate training and validation splits than those of the discriminator \(g_{\mathbf{\theta}}\) (Table 4). The base models are periodically (every \(1,000\) iterations) evaluated on the validation split for early stopping, where we stop if there is no improvement on validation perplexity for 10 consecutive evaluations. The base models \(q_{\mathbf{\theta}}\) achieve \(113.98\) for Segmented WikiText, and \(110.89\) in test set perplexity, respectively. Note that these base models are further fine-tuned on additional datasets in our comparison against residual language models.

### Metrics

We evaluate the relative performance of residual language models against autoregressive models (_i.e._ fine-tuned base models) on two metrics, log likelihood and perplexity improvement, which are approximated as follows:

* **Log likelihood improvement**: since \(p\), \(p_{\mathbf{\theta}}\) and \(q_{0}\) are all distributions over \(L_{\leq T}\), we can quantitatively evaluate their difference in log likelihood. We measure the difference between KL\([p||p_{\mathbf{\theta}}]\) and KL\([p||p_{0}]\):30 Footnote 30: Note that \(p_{0}\) here is the base model component of \(\tilde{p}_{\mathbf{\theta}}\). While comparing between residual language models and autoregressive models, we also finetune \(p_{0}\) on additional data to get a new model \(q^{\prime}_{0}\), which has different parameters than \(p_{0}\). \[\text{KL}[p||p_{\mathbf{\theta}}]-\text{KL}[p||p_{0}]\] \[=\mathop{\mathbb{E}}_{\mathbf{x}\sim p}\left[\log p_{\mathbf{\theta}}( \mathbf{x})-\log p_{0}(\mathbf{x})\right]\] \[=\mathop{\mathbb{E}}_{\mathbf{x}\sim p}\left[\log\tilde{p}_{\mathbf{ \theta}}(\mathbf{x})-\log p_{0}(\mathbf{x})\right]-\log Z_{\mathbf{\theta}}\] \[=\mathop{\mathbb{E}}_{\mathbf{x}\sim p}\left[g_{\mathbf{\theta}}( \mathbf{x})\right]-\log Z_{\mathbf{\theta}}\] \[\approx\frac{\sum_{\mathbf{x}\in Q_{\text{test}}}g_{\mathbf{\theta}} (\mathbf{x})}{|\mathcal{D}_{\text{test}}|}-\log\hat{Z}_{\mathbf{\theta}M},\] (7) where \(\hat{Z}_{\mathbf{\theta}M}\) is estimated using equation (6). A negative value of log likelihood difference indicates that \(\tilde{q}_{\mathbf{\theta}}\) approximates \(p\) better than \(p_{0}\) in terms of KL-divergence.
* **Perplexity improvement**: perplexity is a common language modeling metric. Following Rosenfeld et al. (2001), we compute perplexity improvement of \(p_{\mathbf{\theta}}\) \[=\frac{\exp\frac{|\mathcal{D}|\log\hat{Z}_{\mathbf{\theta}M}}{w\left( \hat{Z}_{\text{test}}\right)}}{\exp\frac{\sum_{\mathbf{x}\in Q_{\text{test}}} g_{\mathbf{\theta}}(\mathbf{x})}{w\left(\hat{Z}_{\text{test}}\right)}},\] (8)

\begin{table}
\begin{tabular}{l r l c} \hline \hline  & Train & Dev \\ \hline WikiText & \(17,556\) & \(1,841\) \\ Yelp & \(9,954\) & \(1,000\) \\ \hline \hline \end{tabular}
\end{table}
Table 4: Number of sequences in preprocessed datasets (for training and tuning the base model \(q\)). Note that we do not train our own base models for RealNews, but use one of the pretrained models provided by Zellers et al. (2019).

\begin{table}
\begin{tabular}{l r l r r} \hline \hline Experiment (Architecture) & Model & Best configuration & log likelihood improvement (95\% CI) & perplexity improvement \\ \hline RealNews (Transformer) & \(p_{\mathbf{\theta}}\) & 4-layer, tanh & \((-0.18,-0.13)\), \(\mu=-0.15\) & \(.03\%\) \\ RealNews (Transformer) & \(P_{0}^{\prime}\) & N/A & N/A & \(.00\%\) \\ \hline WikiText (GRU) & \(p_{\mathbf{\theta}}\) & 1-layer/500, softplus & \((-1.85,-1.54)\), \(\mu=-1.69\) & \(1.44\%\) \\ WikiText (GRU) & \(P_{0}^{\prime}\) & N/A & N/A & \(.50\%\) \\ \hline Yelp (GRU) & \(p_{\mathbf{\theta}}\) & 2-layer/500, softplus & \((-1.89,-1.67)\), \(\mu=-1.80\) & \(1.82\%\) \\ Yelp (GRU) & \(P_{0}^{\prime}\) & N/A & N/A & \(.49\%\) \\ \hline \hline \end{tabular}
\end{table}
Table 2: Residual energy-based model \(\tilde{p}_{\mathbf{\theta}}\) improvements over autoregressive base models \(p_{0}\). The perplexity numbers are per-token, and log likelihood improvements are per sequence (in nats). We only report each dataset’s best model (according to validation data) in this table. See Appendix D for experimental details.

 

where \(w({\mathcal{D}})\) is the total token count of dataset \({\mathcal{D}}\), and \(|{\mathcal{D}}|\) is the number of sequences of \({\mathcal{D}}\). \(\hat{Z_{\mathbf{\theta}M}}\) is computed Appendix B.5

Both evaluation metrics involve estimating the partition function with \(\hat{Z_{\mathbf{\theta}M}}\). For the perplexity improvement metric, we obtain 32 estimates of \(\hat{Z_{\mathbf{\theta}M}}\)31, which are normally distributed, and compute equation (8) using \(\hat{Z_{\mathbf{\theta}M}}\) the conservative end of a 95% confidence level. To account for variance in our test datasets, we further make use of bootstrapping estimation for log likelihood improvement: we bootstrap-sample \(1,000\) subsamples for each test dataset, and compute equation (7) for each datapoint in the Cartesian product (\(1,000\times 32\) in total). We then report results at the \(2.5\%\) and \(97.5\%\) percentiles.

Footnote 31: We set \(M=512\) in this paper.

### Hyperparameters

Transformer experiments.We train our models on 64 GPUs across 8 nodes, with a total batch size of \(64\times 8\times 2=1,024\), and with 1 noise sequence (\(K=1\) in Appendix B.4) per batch. We use an initial learning rate of \(5e-5\). The rest of the hyperparameters largely follow settings in Zellers et al. (2019). Optimization is done with the Grover implementation of AdaFactor.

GRU experiments.We train our models on 8 GPUs on a single node, with a total batch size of \(8\times 2=16\), and with 25 noise sequences (\(K=25\) in Appendix B.4) per batch. We have an initial learning rate of \(1e-4\). Upon no improvement on validation data, we half the learning rate, with patience \(=1\). The model parameters are \(l_{2}\) regularized with a coefficient of \(1e-5\). We also apply dropout regularization with \(p=0.5\). Optimization is done with PyTorch-supplied Adam.

### Configurations

We study the effects of these configurations:

* **Bounding \(g_{\mathbf{\theta}}\)**: we note in SS4.1 that with the strong hypothesis that the base model \(p_{0}\) has bounded error, \(g_{\mathbf{\theta}}\) will have a bounded range, and leads to a much smaller hypothesis space. In this work we experiment with both bounded and unbounded \(g_{\mathbf{\theta}}\)'s, with ranges \((-\infty,0)\) and \((-2,2)\) respectively. More details can be found in Appendix B.3.
* **Model capability of \(g_{\mathbf{\theta}}\)**: we hypothesize that the expressiveness of \(g_{\mathbf{\theta}}\) does not need to be as rich as the parametrization of \(p_{0}\), since \(g_{\mathbf{\theta}}\) essentially only has to tell whether the sequence \(\mathbf{x}\) comes from \(p\) or \(p_{0}\). For the GRU + WikiText experiments, we experiment with \(\{1,2\}\)-layer GRU models of \(g_{\mathbf{\theta}}\). For 1-layer models, we additionally experiment with a setup that has only 250 hidden units. For the Transformers/RealNews dataset, we experiment with \(\{12,4\}\)-layer Transformer models.

### Log likelihood improvements under different configurations

We also see in Table 5 that using tanh as the activation function \(f\) does better than softplus for Transformers; but performs very poorly for GRUs. We also observe degeneracy problems. We speculate that our Transformer-based base models \(q_{\mathbf{\theta}}\) have already learned a good approximation of the true distribution; and limiting the model capacity of \(g_{\mathbf{\theta}}\) in exchange of smaller variance results in a favorable trade-off, and vice versa for GRUs. Regarding discriminator capability: we see that performance is not sensitive to model size. Our best Transformers run actually is from the smaller-model runs. And the 1-layer 500-unit GRU models achieve best performance. Overall, results in Table 5 suggests that performance is sensitive to the choice of model configuration.

 



\begin{table}
\begin{tabular}{c c c c} \hline Model Size & Activation & log likelihood improvement \\ \cline{3-4}  & & 95\% CI & \(\mu\) \\ \hline \multicolumn{4}{c}{RealNews (Transformers)} \\ \hline
12-layer & softplus & \((-0.13,0.08)\) & \(-0.09\) \\
12-layer & tanh & \((-0.14,-0.10)\) & \(-0.12\) \\
4-layer & softplus & \((-0.15,2.62)\) & \(-0.02\) \\
4-layer & tanh & \((-0.18,-0.13)\) & \(-0.16\) \\ \hline \multicolumn{4}{c}{WikiText (GRUs)} \\ \hline
2-layer / 500 & tanh & \((-0.00,0.00)\) & \(-0.00\) \\
2-layer / 500 & softplus & \((-1.32,-0.85)\) & \(-1.18\) \\
1-layer / 500 & tanh & \((-0.79,-0.64)\) & \(-0.71\) \\
1-layer / 500 & softplus & \((-1.85,-1.54)\) & \(-1.69\) \\
1-layer / 250 & tanh & \((-0.02,0.02)\) & \(-0.00\) \\
1-layer / 250 & softplus & \((-1.85,-1.46)\) & \(-1.67\) \\ \hline \multicolumn{4}{c}{Yelp (GRUs)} \\ \hline
2-layer / 500 & tanh & \((-0.03,0.01)\) & \(-0.02\) \\
2-layer / 500 & softplus & \((-1.89,-1.67)\) & \(-1.80\) \\
1-layer / 500 & tanh & \((-0.65,-0.57)\) & \(-0.61\) \\
1-layer / 500 & softplus & \((-2.62,-2.03)\) & \(-2.43\) \\
1-layer / 250 & tanh & \((-0.00,0.00)\) & \(-0.00\) \\
1-layer / 250 & softplus & \((-2.25,-1.99)\) & \(-2.13\) \\ \hline \end{tabular}
\end{table}
Table 5: Comparison of different configurations.