Skip to main content
QUICK REVIEW

[论文解读] Grammar Prompting for Domain-Specific Language Generation with Large Language Models

Bailin Wang, Zi Wang|arXiv (Cornell University)|May 30, 2023
Topic Modeling被引用 24
一句话总结

语法提示通过先为每个示例预测一个最小的专用BNF语法,然后在该语法的约束下进行解码,帮助LLMs生成DSL输出,从而在语义解析、规划和分子生成任务中改进少样本DSL生成。

ABSTRACT

Large language models (LLMs) can learn to perform a wide range of natural language tasks from just a handful of in-context examples. However, for generating strings from highly structured languages (e.g., semantic parsing to complex domain-specific languages), it is challenging for the LLM to generalize from just a few exemplars. We propose \emph{grammar prompting}, a simple approach to enable LLMs to use external knowledge and domain-specific constraints, expressed through a grammar in Backus--Naur Form (BNF), during in-context learning. Grammar prompting augments each demonstration example with a specialized grammar that is minimally sufficient for generating the particular output example, where the specialized grammar is a subset of the full DSL grammar. For inference, the LLM first predicts a BNF grammar given a test input, and then generates the output according to the rules of the grammar. Experiments demonstrate that grammar prompting can enable LLMs to perform competitively on a diverse set of DSL generation tasks, including semantic parsing (SMCalFlow, Overnight, GeoQuery), PDDL planning, and SMILES-based molecule generation.

研究动机与目标

  • 在可用示例极少时,推动结构化DSL输出的数据高效生成。
  • 利用一个专门的、最小的BNF语法来约束上下文学习并引导解码。
  • 在语义解析、规划和分子生成方面展示相较于标准提示的改进。

提出的方法

  • 为每个上下文内演示添加一个足以生成目标输出 y 的最小专用语法 G[y]。
  • 从 G 和上下文示例中预测一个专用语法 G_hat,然后在 G_hat 的条件下生成 y。
  • 应用受约束的解码算法(基于 Earley)以确保输出落在 L(G_hat) 中并纠正无效前缀。
  • 使用 Earley 解析器提取有效前缀,在原始LLM续写无效时引导标记选择。
  • 在多个DSL领域中,将语法提示与标准提示和受约束解码基线进行比较。

实验结果

研究问题

  • RQ1在少样本设定下,语法提示是否能使LLMs比标准提示更准确地生成DSL输出?
  • RQ2预测并用专用语法进行约束是否提升对未见DSL结构或函数的泛化能力?
  • RQ3在语法引导下的受约束解码对计算成本和输出有效性有何影响?
  • RQ4语法提示在包括语义解析、PDDL规划和基于SMILES的分子生成在内的多样化DSL中是否有效?

主要发现

  • 在语义解析基准(GeoQuery、SMCalFlow、Overnight-Blocks)中,语法提示提高了程序和执行的准确性,相较于标准提示。
  • 在若干任务中,使用预测的语法进行受约束解码相较于无约束的语法提示带来进一步提升。
  • 相较于原始提示,专用语法提示在对未见函数和组合/泛化拆分(GeoQuery)上的泛化能力更强。
  • 在多种基础LLM中,语法提示在少样本设定下的一致性提升,且随领域和模型存在一定差异。

更好的研究,从现在开始

从论文设计到论文写作,大幅缩短您的研究时间。

无需绑定信用卡

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