arXiv:2602.17688cs.LGcs.PL2026-02

用语法树结构引导扩散模型生成可执行代码,提升准确性。

AnCoder: Anchored Code Generation via Discrete Diffusion Models

  • 以抽象语法树为结构先验,锚定关键语法元素生成顺序。
  • 在HumanEval上达78.4分,超越自回归基线,且参数更少。
  • 适合需要高可靠性代码生成的场景,如自动化编程工具。

扩散语言模型为代码生成提供了有吸引力的替代方案,支持复杂程序逻辑的全局规划与迭代优化。然而,现有方法未能尊重编程语言的严格结构,常生成无法运行的错误代码。为此,我们提出AnchorTree框架,通过代码原生的层次化结构先验显式锚定扩散过程。具体而言,该框架利用抽象语法树(AST)优先处理语法和语义显著的标记,如关键字(如if、while)和标识符(如变量名),从而建立结构骨架,引导后续生成。我们通过AnCoder系列模型验证该框架,结果表明,结构锚定的扩散模型提供了一条高效生成高质量代码的路径,具有更低的参数量和更高的生成质量。

原文摘要 · Abstract (English)

Diffusion language models offer a compelling alternative to autoregressive code generation, enabling global planning and iterative refinement of complex program logic. However, existing approaches fail to respect the rigid structure of programming languages and, as a result, often produce broken programs that fail to execute. To address this, we introduce AnchorTree, a framework that explicitly anchors the diffusion process using structured, hierarchical priors native to code. Specifically, AnchorTree uses the abstract syntax tree to prioritize resolving syntactically and semantically salient tokens, such as keywords (e.g., if, while) and identifiers (e.g., variable names), thereby establishing a structural scaffold that guides the remaining generation. We validate this framework via AnCoder, a family of models showing that structurally anchored diffusion offers a parameter-efficient path to high-quality code generation.

代码生成扩散模型语法树

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