Sampling from Discrete Energy-Based Models with Quality/Efficiency Trade-offs

Bryan Eikema, Germán Kruszewski, Hady Elsahar, Marc Dymetman

TL;DR

Sampling from discrete Energy-Based Models (EBMs) for natural language is notoriously difficult because standard rejection sampling requires an intractable global upper bound, while MCMC methods yield correlated samples and lack convergence diagnostics. This paper introduces Quasi Rejection Sampling (QRS), a flexible sampling technique that uses modern deep neural models as global proposals and introduces a tunable parameter $\beta$ to trade off sampling efficiency against approximation quality, complete with provable convergence bounds and concrete diagnostics.

What Problem Does This Paper Address?

Energy-Based Models (EBMs) define unnormalized probability distributions $p(x) \propto P(x)$ that offer immense representational flexibility—such as steering language models with complex semantic, stylistic, or demographic constraints. However, drawing samples from discrete EBMs (like text sequences) is a major challenge:

  1. Standard Rejection Sampling (RS) guarantees exact, independent and identically distributed (i.i.d.) samples, but it requires a known finite global upper bound $\beta \ge P(x)/q(x)$ everywhere. For autoregressive language models, such bounds are usually infinite, unknown, or impossibly large (leading to near-zero acceptance rates).
  2. Markov Chain Monte Carlo (MCMC) methods (e.g., Random-Walk Metropolis-Hastings or Independent Metropolis-Hastings) can bypass global bounds, but they produce correlated samples, can get trapped in local modes, and crucially lack concrete convergence diagnostics—meaning practitioners cannot easily verify how close their samples are to the target distribution.

Methods

The authors introduce Quasi Rejection Sampling (QRS), an approximate rejection sampling algorithm:

  • Generalized Acceptance Probability: Instead of requiring $\beta$ to strictly upper-bound the importance ratio $P(x)/q(x)$ everywhere, QRS accepts candidate $x \sim q$ with probability $r_x = \min\left(1, \frac{P(x)}{\beta q(x)}\right)$.
  • Induced Distribution: QRS samples i.i.d. elements from a truncated distribution $p_\beta(x) = \frac{1}{Z_\beta} \min(P(x), \beta q(x))$. As $\beta \to \infty$, $p_\beta$ provably converges to the exact target $p$.
  • Quality/Efficiency Trade-off: The acceptance rate is simply $\text{AR}_\beta = Z_\beta / \beta$. Increasing $\beta$ improves fidelity to the target distribution at the expense of lower acceptance rates.
  • Explicit Diagnostics via Importance Sampling: Because $p_\beta(x)$ can be scored explicitly, the authors derive practical importance-sampling estimators and upper bounds for both Total Variation Distance (TVD) and KL-divergence between $p_\beta$ and $p$.
  • Adaptive Incremental Pruning: The authors provide an algorithm that dynamically tunes $\beta$ to maximize quality while ensuring the acceptance rate does not dip below a user-defined threshold ($ar_{\min}$).

Datasets

The authors evaluated QRS on multiple discrete text tasks:

  • Wikipedia Biographies (gpt2-biographies): Used to evaluate controlled generation and debiasing (controlling female representation and scientist profession).
  • OpenWebText / General Text (GPT-2 small): Used for pointwise lexical constraints (e.g., generating sequences containing "Wikileaks" or "amazing").
  • Paraphrasing Benchmark: Seed sentences paired with round-trip machine translation models (WMT19 English–German) and evaluated against Sentence-BERT embeddings.
  • Toy Synthetic Data: Two Poisson distributions ($\lambda_q = 10, \lambda_p = 11$) with an unbounded importance ratio.

Key Insights and Ideas

  • Modern Deep Models as Global Proposals: Traditional MCMC relied on local token-edit proposals because global proposals were weak. Today, prompted LLMs, fine-tuned autoregressive models (via Distributional Policy Gradients), and round-trip machine translation serve as remarkably capable global proposals.
  • Scorable Samples Mean Verifiable Quality: Unlike Independent Metropolis-Hastings (IMH), where the sample distribution $\pi^{(n)}$ cannot be scored, $p_\beta(x)$ has an explicit closed form. This allows researchers to calculate concrete TVD and KL convergence metrics rather than relying on heuristic diagnostics.
  • True i.i.d. Generation: QRS generates mutually independent samples on each accepted draw, completely eliminating autocorrelation and sample duplication issues that plague standard MCMC chains.

Key Results

  • Debiasing Language Models: On the task of generating 100% scientist biographies while balancing gender to 50% female (from an original base rate of 0.14% female scientists):
  • At $\text{AR} = 10^{-3}$, QRS matched the target constraints almost perfectly (49.5% female, 99.8% scientist) with TVD and KL dropping to 0.02.
  • Even at a high acceptance rate of $\text{AR} = 10^{-1}$, QRS achieved 44.8% female and 99.7% scientist mentions with a TVD of 0.27.
  • Comparison to MCMC Alternatives:
  • Standard IMH without reset produced up to 50% duplicate sequences due to rejected chain transitions.
  • Local Random-Walk Metropolis-Hastings (RWMH) frequently suffered from mode collapse or got stuck in local optima (e.g., repeating the target keyword indefinitely), yielding poor sample diversity.
  • Paraphrase Generation: By combining a GPT-2 prior with a Sentence-BERT threshold constraint ($>0.95$ cosine similarity), QRS filtered round-trip translation candidates to produce fluent, semantically accurate paraphrases, reaching TVD values near zero at $\text{AR} = 10^{-5}$.

Limitations and Future Work

  • Efficiency at High Precision: Approximating distributions with very high precision (large $\beta$) inevitably lowers the acceptance rate, requiring more forward passes through the proposal and energy models.
  • Proposal Quality Dependence: QRS fundamentally depends on the support and overlap of the proposal $q(x)$; if $q(x)$ assigns zero probability to regions where $p(x) > 0$, QRS cannot recover them.
  • Continuous Extensions: While the paper focused on discrete token sequences, the authors note that the core theoretical principles behind QRS extend naturally to continuous domains (e.g., vision, audio), leaving continuous applications for future study.

Summary updated

BibTeX
@inproceedings{eikema2022sampling,
  author = {Bryan Eikema and Germán Kruszewski and Hady Elsahar and Marc Dymetman},
  title = {{Sampling from Discrete Energy-Based Models with Quality/Efficiency Trade-offs}},
  booktitle = {International Conference on Learning Representations},
  year = {2022},
  url = {https://openreview.net/forum?id=9zcjXdavnX},
}

Loading related content...

Figure