用蒙特卡洛方法让小模型生成更符合语法语义约束的文本
Syntactic and Semantic Control of Large Language Models via Sequential Monte Carlo
- 基于序列蒙特卡洛框架,动态调整生成过程以满足约束
- 小模型在4个任务中超越8倍大的闭源模型,仅需少量额外计算
- 适合需要精准控制生成结果的研究与工程场景
大量语言模型应用需要生成符合句法或语义约束的文本。将此类约束建模为概率条件是自然的,但精确从所得分布中生成——该分布与语言模型基础分布差异显著——通常不可行。本文提出一种基于序列蒙特卡洛(SMC)的可控生成架构。我们的SMC框架可在推理时灵活引入领域和问题特定约束,并在生成过程中根据新信息高效重分配计算资源。在四个挑战性任务(数据科学的Python代码生成、文本转SQL、目标推断、分子合成)上,与多种替代方案及消融实验对比表明,本方法以极低开销使小型开源语言模型的表现超过大8倍的闭源微调模型。支持概率视角,我们进一步证明性能提升源于对后验分布更优的逼近。系统基于Lew等(2023)框架构建,集成其语言模型概率编程语言,为用户提供简单可编程的方式,将SMC应用于广泛的受控生成问题。
原文摘要 · Abstract (English)
A wide range of LM applications require generating text that conforms to syntactic or semantic constraints. Imposing such constraints can be naturally framed as probabilistic conditioning, but exact generation from the resulting distribution -- which can differ substantially from the LM's base distribution -- is generally intractable. In this work, we develop an architecture for controlled LM generation based on sequential Monte Carlo (SMC). Our SMC framework allows us to flexibly incorporate domain- and problem-specific constraints at inference time, and efficiently reallocate computational resources in light of new information during the course of generation. By comparing to a number of alternatives and ablations on four challenging domains -- Python code generation for data science, text-to-SQL, goal inference, and molecule synthesis -- we demonstrate that, with little overhead, our approach allows small open-source language models to outperform models over 8x larger, as well as closed-source, fine-tuned ones. In support of the probabilistic perspective, we show that these performance improvements are driven by better approximation to the posterior distribution. Our system builds on the framework of Lew et al. (2023) and integrates with its language model probabilistic programming language, giving users a simple, programmable way to apply SMC to a broad variety of controlled generation problems.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。