提升受限生成效率,不破坏语言模型分布。
Constrained Adaptive Rejection Sampling
- 用可更新的前缀树记录无效生成路径,动态排除
- 每样本所需模型前向传播次数显著减少,效率更高
- 适合需要高多样性与严格约束的场景,如代码测试
语言模型在需满足严格语义或语法约束的应用中日益重要。现有方法存在两极问题:贪婪约束解码会扭曲模型分布,拒绝采样虽保持分布但浪费计算。针对程序模糊测试等对有效性和多样性均要求高的领域,本文提出受限自适应拒绝采样(CARS)。CARS首先进行无约束采样,通过在前缀树中记录违反约束的延续,并从后续采样中扣除其概率质量,实现自适应剪枝。该机制确保已证明无效的前缀不再被重复访问,接受率单调上升,最终样本精确服从约束分布。在程序模糊测试与分子生成等多个领域实验表明,CARS在每有效样本所需模型前向传播次数上持续优于基线,同时生成样本多样性更强于贪婪约束解码(GCD)及近似模型分布的方法。
原文摘要 · Abstract (English)
Language Models (LMs) are increasingly used in applications where generated outputs must satisfy strict semantic or syntactic constraints. Existing approaches to constrained generation fall along a spectrum: greedy constrained decoding methods enforce validity during decoding but distort the LM's distribution, while rejection sampling (RS) preserves fidelity but wastes computation by discarding invalid outputs. Both extremes are problematic in domains such as program fuzzing, where both validity and diversity of samples are essential. We present Constrained Adaptive Rejection Sampling (CARS), an approach that strictly improves the sample-efficiency of RS without distributional distortion. CARS begins with unconstrained LM sampling and adaptively rules out constraint-violating continuations by recording them in a trie and subtracting their probability mass from future draws. This adaptive pruning ensures that prefixes proven invalid are never revisited, acceptance rates improve monotonically, and the resulting samples exactly follow the constrained distribution. In experiments on a variety of domains -- e.g., program fuzzing and molecular generation -- CARS consistently achieves higher efficiency -- measured in the number of LM forward passes per valid sample -- while also producing stronger sample diversity than both GCD and methods that approximate the LM's distribution.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。