CoChat

Grammar-Aligned Decoding

Open access
Park, Kanghee, Wang, Jiayu, Berg-Kirkpatrick, Taylor, Polikarpova, Nadia, D'Antoni, Loris · 2024 · Advances in Neural Information Processing Systems 37

The DOI matches its Crossref record; 7 of the 11 references it cites were found in a registry or an index, and 4 are not checked yet.

Abstract

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.

Overview

The claims and statistics of this paper haven’t been checked yet.

Free: it reads the open-access text and checks the first 5 claims that cite a source we can check. Create a free account to check every claim.

A few free checks a day · papers already verified open instantly · results are public

Integrity signals

Registry

Crossref · 10.52202/079017-0774

Cites

0 citation errors · 0 not checkable

Statistics

Figures

Figure 2 Fragment of the conditional model distribution P for Ex. 2 depicted as a trie. Each node corresponds to a prefix w 1: i -1 , and each edge is annotated with the next token w i and its conditional probability P ( w i | w 1: i -1 ) . Filled nodes are complete strings. Grayed out parts of the trie are outside of the grammar G sk .
Figure 2 Fragment of the conditional model distribution P for Ex. 2 depicted as a trie. Each node corresponds to a prefix w 1: i -1 , and each edge is annotated with the next token w i and its conditional probability P ( w i | w 1: i -1 ) . Filled nodes are complete strings. Grayed out parts of the trie are outside of the grammar G sk .CC-BY-NC-SA · From the PDF
Figure 3 Illustration of the trie built by ASAp after sampling 00000 as the first string (left) and after sampling 11111 as the second string (right). EFG updates after each iteration are shown in red.
Figure 3 Illustration of the trie built by ASAp after sampling 00000 as the first string (left) and after sampling 11111 as the second string (right). EFG updates after each iteration are shown in red.CC-BY-NC-SA · From the PDF
Figure 5 KL ( Q ASAp ∥ P ) and KL ( Q GCD ∥ P )
Figure 5 KL ( Q ASAp ∥ P ) and KL ( Q GCD ∥ P )CC-BY-NC-SA · From the PDF
Figure 6 Expectations of ˜ Q ASAp , ˜ Q GCD , and P
Figure 6 Expectations of ˜ Q ASAp , ˜ Q GCD , and PCC-BY-NC-SA · From the PDF
Figure 7 Scatter plots of ˜ Q ASAp ( · ) and ˜ Q GCD ( × ) vs. expectations of P after 2,000 samples. Proximity to the diagonal indicates proximity to the actual expectation-e.g., a · at (0.45,0.4) indicates a benchmark where the empirical expectation of P was 0.45 and ˜ Q ASAp had converged to an expectation of 0.4 after 2,000 iterations.
Figure 7 Scatter plots of ˜ Q ASAp ( · ) and ˜ Q GCD ( × ) vs. expectations of P after 2,000 samples. Proximity to the diagonal indicates proximity to the actual expectation-e.g., a · at (0.45,0.4) indicates a benchmark where the empirical expectation of P was 0.45 and ˜ Q ASAp had converged to an expectation of 0.4 after 2,000 iterations.CC-BY-NC-SA · From the PDF
Figure 16 SLIA/name-combine-4 _ short
Figure 16 SLIA/name-combine-4 _ shortCC-BY-NC-SA · From the PDF
Figure 26 INV-BV/find _ inv _ bvsgt _ bvor _ 4bit
Figure 26 INV-BV/find _ inv _ bvsgt _ bvor _ 4bitCC-BY-NC-SA · From the PDF
Figure 36 INV-BV/find _ inv _ ne _ bvurem0 _ 4bit
Figure 36 INV-BV/find _ inv _ ne _ bvurem0 _ 4bitCC-BY-NC-SA · From the PDF
Figure 42 CP/CP _ re _ ptb _ 1434
Figure 42 CP/CP _ re _ ptb _ 1434CC-BY-NC-SA · From the PDF

Verification

Claims the paper makes

The claims and statistics of this paper haven’t been checked yet.

Free: it reads the open-access text and checks the first 5 claims that cite a source we can check. Create a free account to check every claim.

A few free checks a day · papers already verified open instantly · results are public

Claims other papers make about this one

Each is checked against this paper’s own text: does it say what the citing paper says it does?

Self-check

Percentages, sums and reported differences re-computed from the paper’s own numbers.

The self-check needs the paper’s full text.

Citations

Cites

The publisher hasn’t deposited this paper’s reference list.

Research works printed but not linked: 13

  1. Lakshya A Agrawal, Aditya Kanade, Navin Goyal, Shuvendu K. Lahiri, and Sriram K. Raja- mani. 2023. Monitor-guided decoding of code lms with static analysis of repository context. In Advances in Neural Information Processing Systems 36: Annual Conference on Neural Information Processing Systems 2023, NeurIPS 2023, New Orleans, LA, USA, December 10 - 16, 2023.
  2. Afra Amini, Li Du, and Ryan Cotterell. 2024. Structured voronoi sampling. Advances in Neural Information Processing Systems, 36.
  3. Peter Anderson, Basura Fernando, Mark Johnson, and Stephen Gould. 2016. Guided open vocabulary image captioning with constrained beam search. arXiv preprint arXiv:1612.00576. · arXiv
  4. Saibo Geng, Martin Josifoski, Maxime Peyrard, and Robert West. 2023. Grammar-constrained decoding for structured NLP tasks without finetuning. In Proceedings of the 2023 Conference on Empirical Methods in Natural Language Processing, Singapore. Association for Computational Linguistics.
  5. Chris Hokamp and Qun Liu. 2017. Lexically constrained decoding for sequence generation using grid beam search. arXiv preprint arXiv:1704.07138. · arXiv
  6. J Edward Hu, Huda Khayrallah, Ryan Culkin, Patrick Xia, Tongfei Chen, Matt Post, and Benjamin Van Durme. 2019. Improved lexically constrained decoding for translation and monolingual rewriting. In Proceedings of the 2019 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, Volume 1 (Long and Short Papers), pages 839-850.
  7. Sachin Kumar, Biswajit Paria, and Yulia Tsvetkov. 2022. Gradient-based constrained sampling from language models. In Proceedings of the 2022 Conference on Empirical Methods in Natural Language Processing, pages 2251-2277.
  8. Xiang Li, John Thickstun, Ishaan Gulrajani, Percy S Liang, and Tatsunori B Hashimoto. 2022. Diffusion-lm improves controllable text generation. Advances in Neural Information Processing Systems, 35:4328-4343.
  9. Yixuan Li, Julian Parsert, and Elizabeth Polgreen. 2024. Guiding enumerative program synthesis with large language models. In International Conference on Computer Aided Verification, pages 280-301. Springer.
  10. Matt Post and David Vilar. 2018. Fast lexically constrained decoding with dynamic beam allocation for neural machine translation. arXiv preprint arXiv:1804.06609. · arXiv
  11. Lianhui Qin, Sean Welleck, Daniel Khashabi, and Yejin Choi. 2022. Cold decoding: Energy- based constrained text generation with langevin dynamics. In Advances in Neural Information Processing Systems.
  12. Alex Renda, Aspen K. Hopkins, and Michael Carbin. 2023. Can LLMs generate random numbers? evaluating LLM sampling in controlled domains. In ICML 2023 Workshop: Sampling and Optimization in Discrete Space.
  13. Brandon T Willard and Rémi Louf. 2023. Efficient guided generation for large language models. arXiv e-prints, pages arXiv-2307.

Cited by

Metadata

Authors
Park, K., Wang, J., Berg-Kirkpatrick, T., Polikarpova, N., & D'Antoni, L.
Venue
Advances in Neural Information Processing Systems 37
Published
2024
Pages
24547-24568
ISSN
1049-5258 (ISSN-L)
OpenAlex
W4415798509
Cited by
10
References
0
Citations by year
2026: 9 · 2025: 1
FWCI
2.89
Type
conference paper
Language
en
Open access
Licence
cc-by-nc-sa
Locations
  • neural information processing systems (publishedVersion)
  • arXiv (Cornell University) (submittedVersion, cc-by-nc-sa)
  • arXiv (Cornell University)
Funders
National Science Foundation (1918211, 2023222, 1955457, 2422214, 2211968, 2402833, 2200333, 2446711)
Topics
  • Physical Sciences › Computer Science › Artificial Intelligence › Natural Language Processing Techniques
  • Social Sciences › Arts and Humanities › Language and Linguistics › Syntax, Semantics, Linguistic Variation
  • Social Sciences › Psychology › Developmental and Educational Psychology › Language Development and Disorders
Keywords
grammatical inference, natural language generation

About these checks

Registry, retraction, Cites and statistics results are computed, not judged, with one exception: a printed reference that no index lists is read once by a model before it counts as a citation error. Claims are extracted by a model and kept only when their quote appears verbatim in the text; each cited source is then checked, with a model’s help, for whether it says what the claim relies on. Those verdicts can be wrong — read the claim’s quote and the cited source before relying on one.

Statistics and arithmetic are recomputed, not judged.

Confidence bands are shown only for fields calibrated on our annotated test set. None is calibrated yet, so no band is shown.

What counts as a claim ›How we measure confidence ›How we check this ›

Are you an author, or do you see a problem with this page? Request a review

Data sources

Bibliographic data: Semantic Scholar, OpenAlex, Crossref.

Contains information from the Semantic Scholar Academic Graph Datasets, made available under the ODC Attribution License (ODC-BY 1.0).

Semantic Scholar’s data is described in: Kinney, R., et al. (2023). The Semantic Scholar Open Data Platform. arXiv:2301.10140.