arXivDaily arXiv每日学术速递 周一至周五更新
​通知:联邦节假日调休:哥伦布日 / 原住民日(Columbus Day / Indigenous Peoples' Day),今日(13日)无更新。
arXiv 2606.22586cs.AIcs.SE

Text2DSL:基于大语言模型的领域特定语言代码生成

Text2DSL: LLM-Based Code Generation for Domain-Specific Languages

RTU MIREA --- Russian Technological University(俄罗斯技术大学);Academy of the Federal Guard Service of the Russian Federation(俄罗斯联邦警卫局学院)

Alexander V. Kozachok, Alexander M. Nazimov, Shamil G. Magomedov

AI总结:

提出Text2DSL任务,将自然语言描述自动转换为领域特定语言(DSL)代码;构建PolkitBench数据集,通过结构化上下文(BNF语法、API规范等)显著提升LLM生成代码的语法和结构有效性。

摘要:

领域特定语言(DSL)被广泛用于管理操作系统安全策略,但手动编写此类语言的规则需要高专业知识且容易出错。本文将从自然语言描述自动生成DSL代码的任务——Text2DSL——形式化为一个独立的问题类别,区别于Text-to-SQL和通用代码生成。我们引入了PolkitBench数据集,包含4,204个经过验证的自然语言到Polkit规则的配对,每个配对通过三级基于AST的流水线进行验证。在两个不同规模和来源的MoE模型(GigaChat-10B-A1.8B,1.8B活跃参数;Nemotron-3-Nano-30B-A3B,3B活跃参数)上进行的受控提示实验表明,结构化上下文(BNF语法、API规范、允许的标识符词汇表)对于基于LLM的DSL代码生成至关重要。在两个模型上,提供上下文将语法有效性提升至98.6-99.4%,结构有效性提升+9.7至+35.5个百分点,CodeBLEU分数提升+60%至+95%。这种效果在不同规模和来源的模型之间的一致性表明,对于Text2DSL类问题,将形式化的目标语言规范注入提示上下文是无需模型微调即可实现高质量生成的稳健促成因素。

英文摘要:

Domain-specific languages (DSLs) are widely used for managing operating system security policies, yet manually authoring rules in such languages demands high expertise and is error-prone. This paper formalises the task of automatic DSL code generation from natural language descriptions - Text2DSL - as a distinct problem class, separate from Text-to-SQL and general-purpose code generation. We introduce the PolkitBench dataset comprising 4,204 verified natural-language-to-Polkit-rule pairs, each validated through a three-level AST-based pipeline. Controlled prompt experiments on two MoE models of different scale and provenance - GigaChat-10B-A1.8B (1.8B active parameters) and Nemotron-3-Nano-30B-A3B (3B active) - demonstrate the critical role of structured context (BNF grammar, API specification, permitted identifier vocabulary) for LLM-based DSL code generation. Across both models, supplying context raises syntactic validity to 98.6-99.4%, structural validity by +9.7 to +35.5 pp, and the CodeBLEU score by +60% to +95%. The consistency of the effect across models of different scale and provenance indicates that, for the Text2DSL class of problems, injecting a formal target-language specification into the prompt context is a robust enabling factor for high-quality generation without model fine-tuning.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑