解码时语法:基于语法片段细化顺序的受限大语言模型生成
Decode-Time Grammars: Constrained LLM Generation over a Refinement Order of Grammar Fragments
浏览论文内容
中文总结 AI 辅助
研究大语言模型在低资源编程表面生成代码的问题,提出解码时语法方法,通过运行时环境实例化语法片段,经特定策略和算子确保语法语义正确,实现中在多种语言和模型上消除幽灵引用。
中文摘要 AI 辅助
大语言模型在代码编写中占比日益增加,但在处理低资源编程表面时仍很脆弱。本文介绍了解码时语法,即从运行时环境Gamma中实例化的语法片段。通过特定策略为每个空洞选择片段,并使用收紧算子替换开放引用位置。新生成的声明在后续区域解码前进入Gamma,确保语法和语义正确。文中形式化了语法片段,证明了相关属性,还在gproj中实现该方法,在多种语言和模型上消除了幽灵引用。
英文摘要
Large language models now write a growing share of the world's code, increasingly inside agents and serving systems that compile, execute, or dispatch generated code without line-by-line review. This works well for mainstream languages but remains brittle for low-resource programming surfaces such as domain-specific languages, custom library APIs, and command-line tools. Even under grammar-constrained decoding, a model can still produce references invalid in the current environment: a buffer never declared, a column absent from the schema, a function the library does not provide, or an unsupported CLI option. This paper introduces decode-time grammars: grammar fragments instantiated during generation from a runtime environment Gamma. A region-specific policy selects a fragment for each hole, and a tightening operator replaces open reference positions with Gamma-typed slots whose candidates are exactly the names, fields, APIs, or options available at that point. Newly generated declarations enter Gamma before later regions are decoded, so the constraining grammar can depend on the prefix already generated. This ensures not only grammatical correctness but also semantic correctness, by preventing references to undefined symbols. We formalize grammar fragments as environment-indexed grammars ordered by refinement, prove No-Ghost soundness for Gamma-slotted fragments, show that refinement preserves this support-set guarantee, and characterize the boundary of mask-enforceable properties. We implement the approach in gproj with offline grammar induction and online policy resolution. Across TileLang, SQL, and P4, with models from 0.6B to 236B parameters, gproj eliminates ghost references by construction at moderate overhead over standard constrained decoding.
发表机构
- SKLP, Institute of Computing Technology, Chinese Academy of Sciences(SKLP,计算技术研究所,中国科学院)
- University of Leeds(利兹大学)
机构由 AI 辅助整理,请以论文原文为准。