Grammar-Aligned Decoding
Kanghee Park, Jiayu Wang, Taylor Berg-Kirkpatrick, Nadia Polikarpova, Loris D'Antoni
摘要
Large Language Models (LLMs) struggle with reliably generating highly structured outputs, such as program code, mathematical formulas, or well-formed markup. Constrained decoding approaches mitigate this problem by greedily restricting what tokens an LLM can output at each step to guarantee that the output matches a given constraint. Specifically, in grammar-constrained decoding (GCD), the LLM's output must follow a given grammar. In this paper, we demonstrate that GCD techniques (and in general constrained decoding techniques) can distort the LLM's distribution, leading to outputs that are grammatical but appear with likelihoods that are not proportional to the ones given by the LLM, and so ultimately are low-quality. We call the problem of aligning sampling with a grammar constraint, grammar-aligned decoding (GAD), and propose adaptive sampling with approximate expected futures (ASAp), a decoding algorithm that guarantees the output to be grammatical while provably producing outputs that match the conditional probability of the LLM's distribution conditioned on the given grammar constraint. Our algorithm uses prior sample outputs to soundly overapproximate the future grammaticality of different output prefixes. Our evaluation on code generation and structured NLP tasks shows how ASAp often produces outputs with higher likelihood (according to the LLM's distribution) than existing GCD techniques, while still enforcing the desired grammatical constraints.
问 Lune
几分钟读透这篇 Paper,不用再花一下午。
Lune 能读完全文,也能读引用它的顶会 Paper,讲清它的结论、证据和局限,每一点都注明出自哪篇 Paper。不用硬啃,也不靠猜。
已有 26 篇顶会 Paper 引用了它。别等审稿人问起,先弄清它们发现了什么。
脉络
- Diffusion-LM Improves Controllable Text Generation 引用了 COLD Decoding: Energy-based Constrained Text Generation with Langevin Dynamics
- Taming Imperfect Process Verifiers: A Sampling Perspective on Backtracking 引用了 Constrained Language Models Yield Few-Shot Semantic Parsers
- Taming Imperfect Process Verifiers: A Sampling Perspective on Backtracking 引用了 Synchromesh: Reliable Code Generation from Pre-trained Language Models
- Taming Imperfect Process Verifiers: A Sampling Perspective on Backtracking 引用了 Constrained Sampling for Language Models Should Be Easy: An MCMC Perspective
- Synchromesh: Reliable Code Generation from Pre-trained Language Models 引用了 Constrained Language Models Yield Few-Shot Semantic Parsers
- DINGO: Constrained Inference for Diffusion LLMs 引用了 Synchromesh: Reliable Code Generation from Pre-trained Language Models
- Constrained Sampling for Language Models Should Be Easy: An MCMC Perspective 引用了 COLD Decoding: Energy-based Constrained Text Generation with Langevin Dynamics
- Constrained Sampling for Language Models Should Be Easy: An MCMC Perspective 引用了 Diffusion-LM Improves Controllable Text Generation
- Constrained Sampling for Language Models Should Be Easy: An MCMC Perspective 引用了 Constrained Language Models Yield Few-Shot Semantic Parsers
- Constrained Sampling for Language Models Should Be Easy: An MCMC Perspective 引用了 Synchromesh: Reliable Code Generation from Pre-trained Language Models
- Constrained Sampling for Language Models Should Be Easy: An MCMC Perspective 引用了 Grammar Prompting for Domain-Specific Language Generation with Large Language Models
- Grammar Prompting for Domain-Specific Language Generation with Large Language Models 引用了 Constrained Language Models Yield Few-Shot Semantic Parsers
- Grammar Prompting for Domain-Specific Language Generation with Large Language Models 引用了 Synchromesh: Reliable Code Generation from Pre-trained Language Models
引用它的顶会 Paper26
- Apertus: Democratizing Open and Compliant LLMs for Global Language EnvironmentsAlejandro Hernández-Cano, Alexander Hägele, Allen Hao Huang, Angelika Romanou 等ACL 2026 · 51 次引用
- DINGO: Constrained Inference for Diffusion LLMsTarun Suresh, Debangshu Banerjee, Shubham Ugare, Sasa Misailovic 等NeurIPS 2025 · 17 次引用
- Taming Imperfect Process Verifiers: A Sampling Perspective on BacktrackingDhruv Rohatgi, Abhishek Shetty, Donya Saless, Yuchen Li 等ICLR 2026 · 15 次引用
- Constrained Sampling for Language Models Should Be Easy: An MCMC PerspectiveEmmanuel Anaya Gonzalez, Sairam Vaidya, Kanghee Park, Ruyi Ji 等NeurIPS 2025 · 15 次引用
- Equality Saturation Theory Exploration à la CarteAnjali Pal, Brett Saiki, Ryan Tjoa, Cynthia Richey 等OOPSLA 2023 · 11 次引用
它引用的 Paper12
- Diffusion-LM Improves Controllable Text GenerationXiang Lisa Li, John Thickstun, Ishaan Gulrajani, Percy Liang 等NeurIPS 2022 · 1,546 次引用
- COLD Decoding: Energy-based Constrained Text Generation with Langevin DynamicsLianhui Qin, Sean Welleck, Daniel Khashabi, Yejin ChoiNeurIPS 2022 · 217 次引用
- Synchromesh: Reliable Code Generation from Pre-trained Language ModelsGabriel Poesia, Alex Polozov, Vu Le, Ashish Tiwari 等ICLR 2022 · 200 次引用
- Grammar Prompting for Domain-Specific Language Generation with Large Language ModelsBailin Wang, Zi Wang, Xuezhi Wang, Yuan Cao 等NeurIPS 2023 · 138 次引用
- Constrained Language Models Yield Few-Shot Semantic ParsersRichard Shin, Christopher H. Lin, Sam Thomson, Charles Chen 等EMNLP 2021 · 131 次引用
相关 Paper
- Flexible and Efficient Grammar-Constrained DecodingKanghee Park, Timothy Zhou, Loris D'AntoniICML 2025
- Guiding LLMs The Right Way: Fast, Non-Invasive Constrained GenerationLuca Beurer-Kellner, Marc Fischer, Martin T. VechevICML 2024 · 93 次引用
- Approximately Aligned DecodingDaniel Melcer, Sujan Kumar Gonugondla, Pramuditha Perera, Haifeng Qian 等NeurIPS 2025 · 3 次引用
- Grammar-Constrained Decoding for Structured NLP Tasks without FinetuningSaibo Geng, Martin Josifoski, Maxime Peyrard, Robert WestEMNLP 2023 · 33 次引用
- The Hidden Cost of Structured Generation in LLMs: Draft-Conditioned Constrained DecodingAvinash Reddy, Thayne Walker, Jaime Ide, Amrit Singh BediICML 2026 · 6 次引用
