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

Bailin Wang, Zi Wang, Xuezhi Wang, Yuan Cao, R. Saurous +1 more
5/1/2023
146 citations

Official code: berlino/grammar-prompting (78 stars, Python, last commit 2023-11-13).

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.

Show full abstract

We explore $\textbf{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).

View on arXivView PDF

Code Implementations(1)

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

788Python, ShellMay 19, 20233 years ago

Similar Papers

Cite this paper

@article{wang2023grammar,
  title  = {Grammar Prompting for Domain-Specific Language Generation with Large Language Models},
  author = {Bailin Wang and Zi Wang and Xuezhi Wang and Yuan Cao and R. Saurous and Yoon Kim},
  year   = {2023},
  eprint = {2305.19234},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/pdf/2305.19234},
  journal = {NEURIPS 2023 2023}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2305.19234.svg)](https://codeofpaper.com/paper/2305.19234)

Discussion