atlas

Research map / Large language models / Language, safety and interpretability

Grammar-Aligned Decoding

NeurIPS 2024 · Large language models › Language, safety and interpretability · approach: Parallel and early-exit decoding · 7 citations (OpenAlex)

Read the paperCheck your idea against 108,967 papers

AI-extracted summary. Written by AI from the paper's full text. Numbers and claims can be wrong or missing context, so check the paper before you cite or build on it.

Shows that grammar-constrained decoding distorts the LLM's distribution and proposes ASAp, an adaptive sampling algorithm that iteratively refines expected-future-grammaticality estimates so sampling converges to the LLM distribution conditioned on the grammar.

Problem

Grammar-constrained decoding (GCD) forces LLM outputs to satisfy a CFG but greedily masks tokens, so outputs are grammatical yet have likelihoods not proportional to the LLM's conditional distribution, biasing sampling toward low-quality outputs.

Approach

Formalize grammar-aligned decoding (GAD) as sampling from the LLM distribution restricted to the grammar, and approximate the expected future grammaticality (EFG) by an upper bound built from previously observed samples' next-token probabilities; repeated sampling tightens the bound so the sampler converges to the target distribution.

Key results

Measured effects reported in the paper

What was changedWhereMeasuredEffect
Use ASAp instead of GCD, updating expected-future-grammaticality estimates from prior samplesMistral-7B constrained decoding · INV-BV benchmarkscorrect samples: ASAp produces correct samples 38% more often than GCD (geomean)Helped
Use ASAp instead of GCD, updating expected-future-grammaticality estimates from prior samplesMistral-7B constrained decoding · SLIA benchmarks both tools can solvecorrect samples: ASAp produces correct samples 73% less often than GCD (geomean)Hurt
Use ASAp instead of GCDMistral-7B constrained decoding · SLIA/name-combine-4-longcorrect samples: 12 -> 1588Helped
Use ASAp instead of GCDMistral-7B constrained decoding · SLIA/lastnamecorrect samples: 1526 -> 285Hurt
Use ASAp instead of GCDMistral-7B constrained decoding · INV-BV/find_inv_eq_bvlshr0_4bitcorrect samples: 228 -> 635Helped
Use ASAp instead of GCDMistral-7B constrained decoding · INV-BV/find_inv_bvule_bvurem1_4bitcorrect samples: 227 -> 143Hurt
Use ASAp instead of GCDMistral-7B constrained decoding · SLIA and INV-BV downstream solution generationcorrect samples: ASAp produces correct samples 38% more often than GCD (geomean); 73% less oftenMixed
Fine-tune the base model on task-specific datasets before comparing ASAp with GCDMistral-7B · INV-BV4sum of least squares difference from target expectations: 0.677 -> 0.051Helped
Fine-tune the base model on task-specific datasets before comparing ASAp with GCDMistral-7B · CPsum of least squares difference from target expectations: 0.278 -> 0.201Helped

Surprising findings

Limitations

Experimental setup

Datasets: SyGuS SLIA benchmarks SyGuS INV-BV benchmarks Penn TreeBank constituency parsing (CP) problems

Benchmarks: SyGuS SLIA (15 problems) SyGuS INV-BV (15 problems) Constituency parsing (6 problems) Illustrative binary-string example

Metrics: KL divergence to GAD target distribution expectation of distribution vs. LLM expectation number of correct solutions out of 2000 samples

Baselines: GCD (grammar-constrained decoding)

Builds on: grammar-constrained decoding (Geng et al.) Transformers-CFG rejection sampling

Closest papers by meaning

Writing a paper in this area? scime draft is a free LaTeX editor with AI included, real-time co-authors and a check of your references and venue rules before you submit. It also imports OpenAI Prism projects.

Open scime draft

Get the next scime Dispatch and a monthly field update

Free. We send a confirmation link first; every email has a one-click unsubscribe. Privacy