paper-with-me

Papers

Automata-based constraints for language model decoding

2024-07-11 · Terry Koo, Frederick Liu, Luheng He

Language models (LMs) are often expected to generate strings in some formal language; for example, structured data, API calls, or code snippets. Although LMs can be tuned to improve their adherence to formal syntax, this does not guarantee conformance, especially with smaller LMs suitable for large-scale deployment. In addition, tuning requires significant resources, making it impractical for uncommon or task-specific formats. To prevent downstream parsing errors we would ideally constrain the LM to only produce valid output, but this is severely complicated by tokenization, which is typically both ambiguous and misaligned with the formal grammar. We solve these issues through the application of automata theory, deriving an efficient closed-form solution for the regular languages, a broad class of formal languages with many practical applications, including API calls or schema-guided JSON and YAML. We also discuss pragmatic extensions for coping with the issue of high branching factor, and extend our techniques to deterministic context-free languages, which similarly admit an efficient closed-form solution. Previous work on this topic (Willard and Louf, 2023) layers bespoke solutions onto automata, leading to problems with speed, correctness, and extensibility. Instead, we reformulate the entire task in terms of automata so we can leverage well-studied and well-optimized algorithms. Our system compiles constraints ~7,000x faster, is provably correct, and can be extended in a modular fashion.

📄 PDF Abstract BibTeX arXiv:2407.08103

Code (0)

등록된 구현이 없습니다.

Tasks

Language ModelingLanguage Modellingmodelvalid

Similar Papers 제목 키워드 기반

Mitigating Bias in Locally Constrained Decoding via Tractable Proposals

2026-06-01 · Meihua Dang, Linxin Song, Honghua Zhang, Jieyu Zhao 외 arxiv

Generations from large language models often fail to conform to desired constraints such as JSON schema. Existing locally constrained decoding (LCD) approaches enforce constraints by myopically masking out next tokens, r…

EPIC: Efficient and Parallel Inference under CFG Constraints for Diffusion Language Models

2026-05-30 · Hyundong Jin, Yo-Sub Han arxiv

Controlling language model outputs is essential for ensuring structural validity, reliability, and downstream usability, and diffusion language models are no exception. Recent advances in diffusion language model decodin…

WGRAMMAR: Leverage Prior Knowledge to Accelerate Structured Decoding

2025-07-22 · Ran Wang, Xiaoxuan Liu, Hao Ren, Gang Chen 외 arxiv

Structured decoding enables large language models (LLMs) to generate outputs in formats required by downstream systems, such as HTML or JSON. However, existing methods suffer from efficiency bottlenecks due to grammar co…

Finite Automata Can be Linearly Decoded from Language-Recognizing RNNs

2019-05-01 · ICLR 2019 5 · Joshua J. Michalenko, Ameesh Shah, Abhinav Verma, Swarat Chaudhuri 외

We study the internal representations that a recurrent neural network (RNN) uses while learning to recognize a regular formal language. Specifically, we train an RNN on positive and negative examples from a regular langu…

Clustering

Representing Formal Languages: A Comparison Between Finite Automata and Recurrent Neural Networks

2019-02-27 · Joshua J. Michalenko, Ameesh Shah, Abhinav Verma, Richard G. Baraniuk 외

We investigate the internal representations that a recurrent neural network (RNN) uses while learning to recognize a regular formal language. Specifically, we train a RNN on positive and negative examples from a regular …

Clustering