TensorX
返回文献探索

Paper · arXiv 2305.19234

Grammar Prompting for Domain-Specific Language Generation with Large Language Models

Bailin Wang, Zi Wang, Xuezhi Wang, Yuan Cao, Rif A. Saurous, Yoon Kim

4 upvotesMay 30, 2023arXiv 预印本
AI 摘要

Grammar prompting enhances LLMs' performance on DSL generation tasks by incorporating domain-specific grammars expressed in BNF.

grammar promptingBackus--Naur Form (BNF)semantic parsingDSL generationPDDL planningmolecule generationSMCalFlowOvernightGeoQuerySMILES

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 explore grammar prompting as a simple approach for enabling LLMs to use external knowledge and domain-specific constraints, expressed through a grammar expressed 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 even molecule generation (SMILES).

北京市昌平区探索星信息技术及软件开发工作室

京ICP备2026059466号
Grammar Prompting for Domain-Specific Language Generation with Large Language Models | TensorX