Metamodel-Guided LLM Decoding for Consistent DSL Generation
作者: Boqi Chen, Aren A. Babikian, José Antonio Hernández López
分类: cs.SE, cs.AI
发布日期: 2026-10-21
备注: 12 pages, 5 figures
💡 一句话要点
提出MeMoDecode以解决DSL生成中的一致性问题
🎯 匹配领域: 支柱九:具身大模型 (Embodied Foundation Models)
关键词: 领域特定语言 大型语言模型 解码框架 一致性约束 软件工程 自动化生成
📋 核心要点
- 现有方法在生成DSL时,通常只能保证与具体语法或有限语义约束的一致性,难以实现元模型级别的约束一致性。
- MeMoDecode框架通过增量映射和重试机制,联合强制执行DSL的具体语法、抽象语法及完备性约束,确保生成的一致性。
- 在四种DSL和六种不同参数规模的LLM上,MeMoDecode在一致性上平均提升23%,在基准性能上也有显著改善。
📝 摘要(中文)
大型语言模型(LLMs)在生成领域特定语言(DSL)软件工程文档方面的应用日益增多。正确的DSL实例不仅需符合具体语法,还需遵循由元模型定义的抽象语法及语义完备性约束。现有的约束解码方法通常只能保证与具体语法或有限的语义约束一致,导致在生成过程中难以强制执行元模型级别的一致性。本文提出MeMoDecode解码框架,能够联合强制执行DSL的具体语法、抽象语法及完备性约束。MeMoDecode通过增量映射当前输出到部分模型并验证其是否能完成一致实例,结合简单的重试机制,确保在检测到不一致时从最近的可完成快照恢复解码。实验结果表明,MeMoDecode在一致性和基准性能上均有显著提升。
🔬 方法详解
问题定义:本文旨在解决在生成领域特定语言(DSL)时,现有方法难以同时保证具体语法、抽象语法及语义完备性约束的一致性问题。现有的约束解码方法通常只能处理具体语法或有限的语义约束,导致生成的DSL实例可能不符合元模型的要求。
核心思路:MeMoDecode框架的核心思路是通过增量映射生成的内容到部分模型,并在每次生成完整的元模型概念时进行一致性验证。若发现不一致,框架会从最近的可完成快照重新开始解码,从而确保生成过程中的一致性。
技术框架:MeMoDecode的整体架构包括生成模块、映射模块和验证模块。生成模块负责生成DSL内容,映射模块将生成的内容映射到部分模型,验证模块则检查当前输出是否能形成一致的DSL实例。
关键创新:MeMoDecode的主要创新在于其能够联合处理具体语法、抽象语法及语义约束,而不是单独处理。这种设计使得生成的DSL实例在元模型级别上保持一致性,克服了传统方法的局限性。
关键设计:在实现中,MeMoDecode结合了简单的重试机制和一个健全的后端验证器,确保在检测到不一致时能够有效恢复解码过程。该框架的设计使得在运行时开销上保持在合理范围内,同时提升了生成的一致性和性能。
🖼️ 关键图片
📊 实验亮点
在四种DSL和六种不同参数规模的LLM上,MeMoDecode在一致性方面的平均提升达到23%,相比于无约束解码和语法约束解码,分别提高了8%。此外,该框架在基准性能上也表现出显著的改善,且运行时开销保持在可接受范围内。
🎯 应用场景
该研究的潜在应用领域包括软件工程、自动化代码生成和DSL设计等。通过确保生成的DSL实例的一致性,MeMoDecode能够提高软件开发的效率和可靠性,未来可能在智能编程助手和自动化测试工具中发挥重要作用。
📄 摘要(原文)
Large language models (LLMs) are increasingly used to generate software engineering artifacts written in domain-specific languages (DSLs). Correct DSL instances usually must comply with not only the concrete syntax but also the abstract syntax defined by a metamodel augmented with semantic well-formedness constraints. Existing constrained decoding approaches typically guarantee compliance only with concrete syntax or with a limited set of semantic constraints expressed over the generated text, making metamodel-level constraint consistency difficult to enforce during generation. We present MeMoDecode: a decoding framework that enforces a DSL's concrete syntax, abstract syntax, and well-formedness constraints jointly. Specifically, whenever the LLM generates a complete metamodel concept, MeMoDecode incrementally maps the current output to a partial model and verifies whether it can still be completed into a consistent instance. We combine MeMoDecode with a simple retry mechanism that resumes decoding from the most recent completable snapshot whenever an inconsistency is detected. Under a sound backend verifier, MeMoDecode never performs worse than grammar-constrained decoding on alignment metrics satisfying natural assumptions. Across four DSLs and six open-weight LLMs ranging from 0.6B to 70B parameters, MeMoDecode achieves the highest consistency, improving consistency by 23% on average over unconstrained decoding and by 8% on average over grammar-constrained decoding. It also improves benchmark performance while incurring only modest runtime overhead. These results show that metamodel-guided decoding is an effective approach for enforcing DSL consistency during decoding across diverse DSLs and LLM scales.