Skip to main content
QUICK REVIEW

[论文解读] Grammar-Constrained Decoding for Structured NLP Tasks without Finetuning

Saibo Geng, Martin Josifosky|arXiv (Cornell University)|May 23, 2023
Natural Language Processing Techniques被引用 4
一句话总结

本文提出了语法约束解码(Grammar-Constrained Decoding, GCD),一种利用形式文法引导大型语言模型(LLMs)生成结构化输出而无需微调的方法。通过将增量解析器与LLMs集成,GCD确保生成的输出在句法上有效且符合词汇规范,在信息抽取、实体消歧和解析等任务上实现了与微调模型相当的性能,尤其在低资源或零样本设置下表现优异。

ABSTRACT

Despite their impressive performance, large language models (LMs) still struggle with reliably generating complex output structures when not finetuned to follow the required output format exactly. To address this issue, grammar-constrained decoding (GCD) can be used to control the generation of LMs, guaranteeing that the output follows a given structure. Most existing GCD methods are, however, limited to specific tasks, such as parsing or code generation. In this work, we demonstrate that formal grammars can describe the output space for a much wider range of tasks and argue that GCD can serve as a unified framework for structured NLP tasks in general. For increased flexibility, we introduce input-dependent grammars, which allow the grammar to depend on the input and thus enable the generation of different output structures for different inputs. We then empirically demonstrate the power and flexibility of GCD-enhanced LMs on (1) information extraction, (2) entity disambiguation, and (3) constituency parsing. Our results indicate that grammar-constrained LMs substantially outperform unconstrained LMs or even beat task-specific finetuned models. Grammar constraints thus hold great promise for harnessing off-the-shelf LMs for a wide range of structured NLP tasks, especially where training data is scarce or finetuning is expensive. Code and data: https://github.com/epfl-dlab/GCD.

研究动机与目标

  • 解决LLMs因输出词汇量庞大且缺乏结构约束而导致生成不可靠或无效结构化输出的挑战。
  • 克服任务特定微调的局限性,后者成本高昂且需要为每个新任务提供标注数据。
  • 开发一种统一、灵活的框架,利用形式文法支持结构化NLP任务,且可动态适应输入上下文。
  • 通过仅允许有效输出序列的解码约束,实现在少样本和零样本设置下结构化任务的性能提升。
  • 证明语法约束可超越无约束LLMs,甚至在不重新训练的情况下媲美微调模型的性能。

提出的方法

  • 定义形式文法以描述结构化NLP任务的有效输出空间,例如封闭式信息抽取中的主语-关系-对象三元组。
  • 引入输入相关文法,根据输入动态调整文法规则,实现每条输入对应可变的输出结构。
  • 将增量解析器作为补全引擎,在每个解码步骤中,仅根据当前文法和前缀确定有效的下一个标记。
  • 将LLM的自回归生成与语法感知的补全引擎结合,确保所有生成序列在结构上均有效。
  • 采用下推自动机或基于解析器的方法,实时高效地验证和约束解码过程。
  • 使用现成的LLMs部署该框架,避免为特定任务进行微调或复杂的约束工程。
Figure 1: Grammar-constrained decoding (GCD), applied to the task of closed information extraction, where the goal is to extract a list $y$ of subject–relation–object triplets from the input text $x$ . Subjects and objects are constrained to be Wikidata entities, relations to be a Wikidata relation.
Figure 1: Grammar-constrained decoding (GCD), applied to the task of closed information extraction, where the goal is to extract a list $y$ of subject–relation–object triplets from the input text $x$ . Subjects and objects are constrained to be Wikidata entities, relations to be a Wikidata relation.

实验结果

研究问题

  • RQ1形式文法是否可在无需任务特定微调的情况下,适用于广泛多样的结构化NLP任务,以定义有效输出空间?
  • RQ2与无约束生成相比,语法约束解码在少样本设置下如何提升LLMs在结构化任务上的性能?
  • RQ3输入相关文法在多大程度上可扩展GCD在输出结构可变或依赖输入的任务中的适用性?
  • RQ4在低资源场景下,GCD能否实现与微调模型相当或更优的性能?
  • RQ5在将复杂文法应用于大规模LLM解码时,延迟和可扩展性之间的实际权衡是什么?

主要发现

  • 语法约束解码显著提升了LLMs在多样化任务中生成结构化输出的可靠性与准确性,涵盖信息抽取、实体消歧和短语结构解析等任务。
  • 经过GCD增强的LLMs在所有评估任务中均优于无约束LLMs,甚至在少样本设置下超越部分微调模型。
  • 使用输入相关文法使该框架能够处理输出有效性依赖于输入上下文的任务,如实体消歧和实体链接。
  • 性能提升在低资源或零样本场景下最为显著,此时庞大的输出词汇量通常会压倒少样本提示的效果。
  • 尽管GCD因解析开销导致解码延迟增加,但性能增益使其成本合理,尤其在微调不可行时更具优势。
  • 该方法在更大LLMs上效果最佳,且当文法尽可能严格时性能最优,凸显了文法设计在框架成功中的关键作用。
Figure 2: Formal grammars for 14 structured NLP tasks, highlighting the general applicability of grammar-constrained decoding. All 14 grammars are context-free (mostly regular). * marks input-dependent grammars. Inputs $x=\langle x_{0},\dots,x_{n-1}\rangle$ are sequences of lexical units (e.g., word
Figure 2: Formal grammars for 14 structured NLP tasks, highlighting the general applicability of grammar-constrained decoding. All 14 grammars are context-free (mostly regular). * marks input-dependent grammars. Inputs $x=\langle x_{0},\dots,x_{n-1}\rangle$ are sequences of lexical units (e.g., word

更好的研究,从现在开始

从阅读论文到最终审阅,大幅缩短您的研究时间。

无需绑定信用卡

本解读由 AI 生成,并经人工编辑审核。