元模型引导的大语言模型解码用于一致的领域特定语言生成
Metamodel-Guided LLM Decoding for Consistent DSL Generation
AI总结:
该研究提出MeMoDecode解码框架,结合重试机制,在四个DSL和六个LLM上使DSL一致性平均提升23%,有效解决了LLM生成DSL时的元模型级约束一致性问题。
摘要:
大语言模型(LLM)越来越多地用于生成用领域特定语言(DSL)编写的软件工程制品。正确的DSL实例通常不仅必须符合具体语法,还必须符合由元模型定义的抽象语法,该元模型还包含语义良好性约束。现有的约束解码方法通常仅保证符合具体语法,或仅符合在生成文本上表达的有限一组语义约束,使得在生成过程中难以执行元模型级别的约束一致性。我们提出MeMoDecode:一种解码框架,可同时强制执行DSL的具体语法、抽象语法和良好性约束。具体而言,每当LLM生成一个完整的元模型概念时,MeMoDecode会将当前输出增量映射到部分模型,并验证其是否仍可完成成一致的实例。我们将MeMoDecode与简单的重试机制相结合,该机制在检测到不一致时从最近的可完成快照恢复解码。在合理的后端验证器下,在满足自然假设的对齐指标上,MeMoDecode的性能从未比语法约束解码差。在四个DSL和六个参数范围从0.6B到70B的开放权重LLM上,MeMoDecode实现了最高的一致性,与无约束解码相比,一致性平均提高23%,与语法约束解码相比,平均提高8%。它还提高了基准性能,同时仅产生适度的运行时开销。这些结果表明,元模型引导的解码是在不同DSL和LLM规模的解码过程中强制执行DSL一致性的有效方法。
英文摘要:
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.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。