arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2406.11925cs.SEcs.AIcs.CL
收藏

DocCGen:基于文档的受控代码生成

DocCGen: Document-based Controlled Code Generation

IIT Bombay(印度理工学院孟买分校);IBM Research(IBM研究院)

Sameer Pimparkhede, Mehant Kammakomati, Srikanth Tamilselvam, Prince Kumar, Ashok Pon Kumar, Pushpak Bhattacharyya

AI总结:

DocCGen 提出一种基于文档的两步框架,先通过库文档匹配检测正确库,再利用文档中的模式规则约束解码,从而改善 LLM 在 Ansible YAML 和 Bash 等结构化 DSL 上的代码生成质量。

摘要:

近期发展表明,大型语言模型(LLMs)在 C++、Java 和 Python 等资源丰富的通用语言的自然语言(NL)到代码生成任务上取得了最先进的性能。然而,由于领域特定的模式、语法和定制化内容通常在预训练阶段未被 LLMs 所见,它们在 YAML、JSON 等结构化领域特定语言(DSLs)中的实际应用受到限制。已有工作尝试通过相关示例的上下文学习或微调来缓解这一挑战,但这些方法存在 DSL 样本有限和提示敏感等问题,而企业通常维护着良好的 DSL 文档。因此,我们提出 DocCGen,这是一个通过将结构化代码语言的 NL 到代码生成任务分解为两步过程来利用此类丰富知识的框架。首先,它利用与 NL 查询最匹配的库文档来检测正确的库。然后,它利用从这些库文档中提取的模式规则来约束解码过程。我们在两种复杂的结构化语言——Ansible YAML 和 Bash 命令上评估了我们的框架,包含两种设置:域外(OOD)和域内(ID)。我们的大量实验表明,DocCGen 在所有六项评估指标上一致地改善了不同规模的语言模型,减少了结构化代码中的语法和语义错误。我们计划开源数据集和代码,以推动受约束代码生成领域的研究。

英文摘要:

Recent developments show that Large Language Models (LLMs) produce state-of-the-art performance on natural language (NL) to code generation for resource-rich general-purpose languages like C++, Java, and Python. However, their practical usage for structured domain-specific languages (DSLs) such as YAML, JSON is limited due to domain-specific schema, grammar, and customizations generally unseen by LLMs during pre-training. Efforts have been made to mitigate this challenge via in-context learning through relevant examples or by fine-tuning. However, it suffers from problems, such as limited DSL samples and prompt sensitivity but enterprises maintain good documentation of the DSLs. Therefore, we propose DocCGen, a framework that can leverage such rich knowledge by breaking the NL-to-Code generation task for structured code languages into a two-step process. First, it detects the correct libraries using the library documentation that best matches the NL query. Then, it utilizes schema rules extracted from the documentation of these libraries to constrain the decoding. We evaluate our framework for two complex structured languages, Ansible YAML and Bash command, consisting of two settings: Out-of-domain (OOD) and In-domain (ID). Our extensive experiments show that DocCGen consistently improves different-sized language models across all six evaluation metrics, reducing syntactic and semantic errors in structured code. We plan to open-source the datasets and code to motivate research in constrained code generation.

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

↑