一种评估大语言模型生成约束领域特定语言代码能力的框架
A framework for assessing the capabilities of code generation of constraint domain-specific languages with large language models
AI总结:
本文提出一种评估框架,用于评估大语言模型生成约束领域特定语言代码的能力,发现LLMs在Python上的表现优于OCL和Alloy,并探讨了改进代码生成的方法。
摘要:
大型语言模型(LLMs)可以用于支持软件开发任务,例如通过代码补全或代码生成。然而,当考虑较少使用编程语言如领域特定语言(DSLs)时,其有效性会显著下降。在本文中,我们提出了一种通用框架,用于评估LLMs生成DSL代码的能力。生成的代码从规范性和正确性两个方面进行评估。该框架应用于一种特定类型的DSL,即约束语言,我们的实验重点是OCL和Alloy,并将结果与在Python上获得的结果进行比较。实验结果表明,总体而言,LLMs在Python上的表现优于OCL和Alloy。例如,开源LLMs可能无法生成与约束相关的代码,因为这需要同时管理约束和其定义的领域模型。此外,一些改进代码生成过程的方法,如代码修复(让LLM修复错误代码)或多次尝试(为每个编码任务生成多个候选代码),可以提高生成代码的质量。同时,其他决策如提示模板的选择影响较小。所有这些维度都可以通过我们的评估框架系统地分析,从而决定为特定任务设置代码生成的最佳方法。
英文摘要:
Large language models (LLMs) can be used to support software development tasks, e.g., through code completion or code generation. However, their effectiveness drops significantly when considering less popular programming languages such as domain-specific languages (DSLs). In this paper, we propose a generic framework for evaluating the capabilities of LLMs generating DSL code from textual specifications. The generated code is assessed from the perspectives of well-formedness and correctness. This framework is applied to a particular type of DSL, constraint languages, focusing our experiments on OCL and Alloy and comparing their results to those achieved for Python, a popular general-purpose programming language. Experimental results show that, in general, LLMs have better performance for Python than for OCL and Alloy. LLMs with smaller context windows such as open-source LLMs may be unable to generate constraint-related code, as this requires managing both the constraint and the domain model where it is defined. Moreover, some improvements to the code generation process such as code repair (asking an LLM to fix incorrect code) or multiple attempts (generating several candidates for each coding task) can improve the quality of the generated code. Meanwhile, other decisions like the choice of a prompt template have less impact. All these dimensions can be systematically analyzed using our evaluation framework, making it possible to decide the most effective way to set up code generation for a particular type of task.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。