arXiv:2506.07154cs.CLcs.AI2025-06ACL被引 4

用后验推断方法让大模型生成语法更规范的文本

Syntactic Control of Language Models by Posterior Inference

  • 通过后验推断与语法标签器结合,控制生成文本的句法结构
  • GPT2和Llama3-8B的句法准确率F1从不足40提升至约93
  • 适合需要语法严谨性的场景,如技术写作或可解释性生成

控制语言模型生成文本的句法结构在需要清晰性、风格一致或可解释性的应用中具有重要价值,但仍是挑战。本文提出基于后验推断的采样算法,可在生成过程中有效施加目标成分结构。方法结合序列蒙特卡洛(Sequential Monte Carlo),通过从提议分布采样估计后验分布,并利用语法标签器确保每个生成词符与目标句法结构对齐。在GPT2-large和Llama3-8B模型上的实验表明,采用合适的提议分布后,句法准确率F1得分从12.31(GPT2-large)和35.33(Llama3-8B)分别提升至约93,且未牺牲语言模型的流畅性。结果凸显了句法控制的复杂性与采样算法的有效性,为需要精确句法控制的应用提供了有前景的解决方案。

原文摘要 · Abstract (English)

Controlling the syntactic structure of text generated by language models is valuable for applications requiring clarity, stylistic consistency, or interpretability, yet it remains a challenging task. In this paper, we argue that sampling algorithms based on the posterior inference can effectively enforce a target constituency structure during generation. Our approach combines sequential Monte Carlo, which estimates the posterior distribution by sampling from a proposal distribution, with a syntactic tagger that ensures that each generated token aligns with the desired syntactic structure. Our experiments with GPT2 and Llama3-8B models show that with an appropriate proposal distribution, we can improve syntactic accuracy, increasing the F1 score from $12.31$ (GPT2-large) and $35.33$ (Llama3-8B) to about $93$ in both cases without compromising the language model's fluency. These results underscore both the complexity of syntactic control and the effectiveness of sampling algorithms, offering a promising approach for applications where precise control over syntax is essential.

句法控制后验推断语言模型生成质量

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