arXiv:2504.05410cs.CLcs.AI2025-04被引 24

提出新采样算法,让语言模型生成更高效且符合约束。

Fast Controlled Generation from Language Models with Adaptive Weighted Rejection Sampling

  • 用自适应拒绝采样减少约束检查次数,避免全词表遍历。
  • 在多个任务上比现有方法更快更准,支持更广约束类型。
  • 适合需要高效可控生成的场景,如代码生成、分子设计。

主流的受约束语言模型生成方法是局部约束解码(LCD),在每一步采样时逐个检查词表,排除不符合约束的词。该方法存在两大问题:(i) 每步需对超10万词的词表进行约束评估,开销巨大;(ii) 仅依赖局部信息采样,可能陷入死胡同,扭曲全局分布。本文提出一种自适应拒绝采样算法,显著减少约束评估次数,通常降低数量级。进一步,该算法可低成本生成无偏重要性权重估计,可用于序列蒙特卡洛方法纠正局部约束带来的偏差。在text-to-SQL、分子合成、目标推断、模式匹配和JSON生成等任务上的实证表明,本方法优于现有最优基线,支持更广泛约束,同时提升运行速度与性能。理论与实验分析显示,其效率取决于无约束与有约束语言模型间的差异,模型越优,提速越明显。

原文摘要 · Abstract (English)

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.

语言模型生成控制采样算法

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。