arXiv:2606.21619cs.SEcs.LG2026-06

约束解码中的对齐问题会严重降低代码生成正确率。

The Alignment Problem in Constrained Code Generation

  • 发现约束器与语言模型、目标语言之间存在对齐问题
  • 不完整约束器使功能正确率下降最高达97%
  • 适合关注代码生成可靠性与形式化保证的研究者

大型语言模型在代码生成中表现强劲,但常出现语法或类型错误导致编译失败。约束解码通过构造方式减少编译错误,间接提升功能性正确性。然而,现有研究忽视了约束解码中的关键问题:约束器(如类型)、语言模型与目标语言(如TypeScript)之间的对齐性。对齐偏差源于约束器的不完整(拒绝合法程序)或不严谨(允许非法程序),前者扭曲语言模型分布,损害生成质量。我们使用七种语言模型、两种目标语言、两种约束器,在三个基准上评估不同不完整程度下的表现。结果显示,当约束器不完整时,无约束解码在功能正确性上显著优于约束解码;不完整约束导致模型进入低概率程序区域,引发超时,功能正确率下降最高达97%。本工作揭示了约束解码中对齐失衡的负面影响,为设计具形式化保障的代码生成系统提供了量化指导。

原文摘要 · Abstract (English)

Large Language Models (LLMs) have demonstrated strong capabilities in code generation, but their outputs frequently contain syntax or type errors that result in compilation failures. Constrained decoding has been proposed as a solution to mitigate compilation errors by construction, improving functional correctness as a byproduct. However, previous works overlook a critical aspect of constrained decoding: the alignment between constrainer (e.g., types), language model and the target specification language (e.g., TypeScript). Misalignment is caused by the constrainer being incomplete--rejecting programs that belong to the target--or unsound--allowing programs that are not part of the target. The bias created by incompleteness distorts the language model distribution, and can be detrimental for code generation. We evaluate this hypothesis using seven language models, two target languages, two constrainers, enforcing types and syntax during decoding, and we study how language models react to varying levels of incompleteness. On three benchmarks, when the constrainer is incomplete, unconstrained decoding significantly outperforms constrained decoding in terms of functional correctness. Incompleteness pushes the model into low-probability regions of the program space, causing the generation to frequently time out, and reducing functional correctness by up to 97%. These contributions make the community aware of the negative effects of misalignment in constrained decoding, and provide quantitative insights on how to design constrainers that are beneficial for code generation systems with formal guarantees.

代码生成语言模型约束解码对齐问题

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。