IterGen: Iterative Semantic-aware Structured LLM Generation with Backtracking

📅 2024-10-09
📈 Citations: 0
Influential: 0
📄 PDF
🤖 AI Summary
Large language models (LLMs) frequently exhibit hallucinations, toxicity, and syntactic errors in code and structured text generation; existing structured generation libraries support only unidirectional left-to-right decoding and lack dynamic correction capabilities. To address this, we propose the first grammar-symbol-driven bidirectional iterative generation framework, integrating backtracking with KV-cache state preservation to enable grammar-guided forward generation and position-aware backward rewriting. Our approach leverages symbol-position mapping, syntax-constrained decoding, and an iterative rewriting engine for semantics-aware, controllable generation. Experiments demonstrate substantial improvements in accuracy on SQL and Vega-Lite query generation tasks, alongside a significant reduction in privacy leakage risk. The framework is fully open-sourced, enabling complete reproducibility.

Technology Category

Application Category

📝 Abstract
Large Language Models (LLMs) are widely used for tasks such as natural language and code generation, but their outputs often suffer from issues like hallucination, toxicity, and incorrect results. Current libraries for structured LLM generation rely on left-to-right decoding without support for backtracking, limiting the ability to correct or refine outputs mid-generation. To address this, we introduce IterGen, a user-friendly library for iterative, grammar-guided LLM generation that enables users to move both forward and backward within the generated output based on grammar symbols. By leveraging a symbol-to-position mapping and maintaining the key-value (KV) cache state, IterGen ensures efficient and structured generation while allowing for corrections during the process. We demonstrate IterGen's effectiveness in two important applications: reducing privacy leakage in LLM outputs and improving the accuracy of LLM-generated SQL and Vega-Lite queries. Our code and additional resources are available at https://structuredllm.com.
Problem

Research questions and friction points this paper is trying to address.

Addresses LLM output issues like hallucination and toxicity
Enables iterative, grammar-guided LLM generation with backtracking
Improves accuracy in SQL and Vega-Lite query generation
Innovation

Methods, ideas, or system contributions that make the work stand out.

Iterative grammar-guided LLM generation
Backtracking for mid-generation corrections
Symbol-to-position mapping with KV cache
🔎 Similar Papers
No similar papers found.