Saved in:
Bibliographic Details
Main Authors: Lipkin, Benjamin, LeBrun, Benjamin, Vigly, Jacob Hoover, Loula, João, MacIver, David R., Du, Li, Eisner, Jason, Cotterell, Ryan, Mansinghka, Vikash, O'Donnell, Timothy J., Lew, Alexander K., Vieira, Tim
Format: Preprint
Published: 2025
Subjects:
Online Access:https://arxiv.org/abs/2504.05410
Tags: Add Tag
No Tags, Be the first to tag this record!
_version_ 1866911108606984192
author Lipkin, Benjamin
LeBrun, Benjamin
Vigly, Jacob Hoover
Loula, João
MacIver, David R.
Du, Li
Eisner, Jason
Cotterell, Ryan
Mansinghka, Vikash
O'Donnell, Timothy J.
Lew, Alexander K.
Vieira, Tim
author_facet Lipkin, Benjamin
LeBrun, Benjamin
Vigly, Jacob Hoover
Loula, João
MacIver, David R.
Du, Li
Eisner, Jason
Cotterell, Ryan
Mansinghka, Vikash
O'Donnell, Timothy J.
Lew, Alexander K.
Vieira, Tim
contents The dominant approach to generating from language models subject to some constraint is locally constrained decoding (LCD), incrementally sampling tokens at each time step such that the constraint is never violated. Typically, this is achieved through token masking: looping over the vocabulary and excluding non-conforming tokens. There are two important problems with this approach. (i) Evaluating the constraint on every token can be prohibitively expensive -- LM vocabularies often exceed $100,000$ tokens. (ii) LCD can distort the global distribution over strings, sampling tokens based only on local information, even if they lead down dead-end paths. This work introduces a new algorithm that addresses both these problems. First, to avoid evaluating a constraint on the full vocabulary at each step of generation, we propose an adaptive rejection sampling algorithm that typically requires orders of magnitude fewer constraint evaluations. Second, we show how this algorithm can be extended to produce low-variance, unbiased estimates of importance weights at a very small additional cost -- estimates that can be soundly used within previously proposed sequential Monte Carlo algorithms to correct for the myopic behavior of local constraint enforcement. Through extensive empirical evaluation in text-to-SQL, molecular synthesis, goal inference, pattern matching, and JSON domains, we show that our approach is superior to state-of-the-art baselines, supporting a broader class of constraints and improving both runtime and performance. Additional theoretical and empirical analyses show that our method's runtime efficiency is driven by its dynamic use of computation, scaling with the divergence between the unconstrained and constrained LM, and as a consequence, runtime improvements are greater for better models.
format Preprint
id arxiv_https___arxiv_org_abs_2504_05410
institution arXiv
publishDate 2025
record_format arxiv
spellingShingle Fast Controlled Generation from Language Models with Adaptive Weighted Rejection Sampling
Lipkin, Benjamin
LeBrun, Benjamin
Vigly, Jacob Hoover
Loula, João
MacIver, David R.
Du, Li
Eisner, Jason
Cotterell, Ryan
Mansinghka, Vikash
O'Donnell, Timothy J.
Lew, Alexander K.
Vieira, Tim
Computation and Language
Artificial Intelligence
Machine Learning
The dominant approach to generating from language models subject to some constraint is locally constrained decoding (LCD), incrementally sampling tokens at each time step such that the constraint is never violated. Typically, this is achieved through token masking: looping over the vocabulary and excluding non-conforming tokens. There are two important problems with this approach. (i) Evaluating the constraint on every token can be prohibitively expensive -- LM vocabularies often exceed $100,000$ tokens. (ii) LCD can distort the global distribution over strings, sampling tokens based only on local information, even if they lead down dead-end paths. This work introduces a new algorithm that addresses both these problems. First, to avoid evaluating a constraint on the full vocabulary at each step of generation, we propose an adaptive rejection sampling algorithm that typically requires orders of magnitude fewer constraint evaluations. Second, we show how this algorithm can be extended to produce low-variance, unbiased estimates of importance weights at a very small additional cost -- estimates that can be soundly used within previously proposed sequential Monte Carlo algorithms to correct for the myopic behavior of local constraint enforcement. Through extensive empirical evaluation in text-to-SQL, molecular synthesis, goal inference, pattern matching, and JSON domains, we show that our approach is superior to state-of-the-art baselines, supporting a broader class of constraints and improving both runtime and performance. Additional theoretical and empirical analyses show that our method's runtime efficiency is driven by its dynamic use of computation, scaling with the divergence between the unconstrained and constrained LM, and as a consequence, runtime improvements are greater for better models.
title Fast Controlled Generation from Language Models with Adaptive Weighted Rejection Sampling
topic Computation and Language
Artificial Intelligence
Machine Learning
url https://arxiv.org/abs/2504.05410