让大模型生成代码时自动检查语义正确性,提升可靠性。
Projectional Decoding: Towards Semantic-Aware LLM Generation

- 用动态图结构代替纯文本,边生成边验证代码语义
- 在程序生成任务中显著提高输出的语义有效性
- 适合需要高可靠性的软件自动化场景
大语言模型在软件工程任务中广泛用于生成代码,但确保生成结果的语义正确性仍是核心挑战。现有约束解码方法虽能保证语法正确,或部分语义规则,却缺乏统一的语义表示来支撑代码生成过程中的推理与验证。本文提出投影解码(projectional decoding),一种将领域语义直接融入生成过程的新框架:在生成过程中同时维护一个部分图模型作为主要表征,而非仅依赖文本。该抽象表示可显式捕捉不确定性,原生支持错误检测,并在生成过程中提供可证明的语义有效保证。初步实验在程序生成任务上验证了该方法提升语义有效性的潜力。此外,我们讨论了其在多种软件工程活动中实现可验证自动化的能力。
原文摘要 · Abstract (English)
Large language models (LLMs) are increasingly used to generate software artifacts across many software engineering (SE) tasks, yet ensuring the semantic validity of these artifacts remains a fundamental challenge. Existing constrained decoding techniques can enforce syntactic correctness and, in some cases, specific semantic rules, but lack a general representation that bridges LLM-generated text with the reasoning required for semantic validation in SE. In this paper, we propose projectional decoding, a novel conceptual framework that integrates domain semantics directly into the generation process by maintaining, alongside text, a partial graph model as the primary artifact representation throughout generation. This abstract representation enables incremental semantic validation by explicitly capturing uncertainty and natively supporting error detection, while guiding generation toward semantically valid outputs with provable guarantees. We present preliminary results on a program generation task which demonstrate the potential of this approach to improve the semantic validity of LLM-generated artifacts. We also discuss how projectional decoding can enable verifiable automation with LLMs across various SE activities.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。