arXivDaily arXiv每日学术速递 周一至周五更新
感恩节,周五至周末无更新,大家顺遂。周一再来吧
arXiv 2405.21047cs.AIcs.CLcs.LG
收藏

语法对齐解码

Grammar-Aligned Decoding

University of Wisconsin-Madison(威斯康星大学麦迪逊分校);University of California San Diego(加州大学圣地亚哥分校)

Kanghee Park, Jiayu Wang, Taylor Berg-Kirkpatrick, Nadia Polikarpova, Loris D'Antoni

AI总结:

本文提出语法对齐解码(GAD)方法,通过适应性采样与近似期望未来(ASAp)算法,提升语法约束下生成输出的质量和概率匹配度。

摘要:

大型语言模型(LLMs)在可靠生成高度结构化的输出方面存在困难,例如程序代码、数学公式或正确格式化的标记。受限解码方法通过贪婪地限制LLM在每一步可以输出的标记来缓解这一问题,以确保输出符合给定的约束。具体而言,在语法约束解码(GCD)中,LLM的输出必须遵循给定的语法。在本文中,我们证明GCD技术(以及一般受限解码技术)会扭曲LLM的分布,导致生成的输出虽然语法正确,但其出现的可能性与LLM给出的可能性不成比例,最终质量较低。我们称对齐采样与语法约束的问题为语法对齐解码(GAD),并提出了一种名为适应性采样与近似期望未来(ASAp)的解码算法,该算法保证输出语法正确,同时能证明生成的输出符合LLM分布在给定语法约束下的条件概率。我们的算法利用先前的样本输出,对不同输出前缀的未来语法正确性进行合理上界估计。我们在代码生成和结构化NLP任务上的评估显示,ASAp经常生成比现有GCD技术更高的可能性(根据LLM的分布)的输出,同时仍强制执行所需的语法约束。

英文摘要:

Large Language Models (LLMs) struggle with reliably generating highly structured outputs, such as program code, mathematical formulas, or well-formed markup. Constrained decoding approaches mitigate this problem by greedily restricting what tokens an LLM can output at each step to guarantee that the output matches a given constraint. Specifically, in grammar-constrained decoding (GCD), the LLM's output must follow a given grammar. In this paper, we demonstrate that GCD techniques (and in general constrained decoding techniques) can distort the LLM's distribution, leading to outputs that are grammatical but appear with likelihoods that are not proportional to the ones given by the LLM, and so ultimately are low-quality. We call the problem of aligning sampling with a grammar constraint, grammar-aligned decoding (GAD), and propose adaptive sampling with approximate expected futures (ASAp), a decoding algorithm that guarantees the output to be grammatical while provably producing outputs that match the conditional probability of the LLM's distribution conditioned on the given grammar constraint. Our algorithm uses prior sample outputs to soundly overapproximate the future grammaticality of different output prefixes. Our evaluation on code generation and structured NLP tasks shows how ASAp often produces outputs with higher likelihood (according to the LLM's distribution) than existing GCD techniques, while still enforcing the desired grammatical constraints.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑