arXivDaily arXiv每日学术速递 周一至周五更新
arXiv周末暂无论文更新,休息一下吧,周末愉快~~
arXiv 2501.06283cs.SEcs.AIcs.CLcs.LOcs.PL
收藏

Dafny作为代码生成的感知验证中间语言

Dafny as Verification-Aware Intermediate Language for Code Generation

Massachusetts Institute of Technology(麻省理工学院);Amazon(亚马逊公司)

Yue Chen Li, Stefan Zetzsche, Siva Somayyajula

AI总结:

针对大语言模型生成代码易出错的问题,提出引导LLM先生成可自动验证的Dafny中间表示,验证通过后编译为目标语言,全程自然语言交互,在HumanEval基准上测试了原型性能。

摘要:

利用大语言模型(LLM)从自然语言提示生成源代码是一项热门且颇具前景的技术,应用场景广泛。该技术的局限之一在于,生成的代码有时会存在错误,且往往较为隐蔽,尽管呈现给用户时看似正确。本文探讨了形式化方法助力提升LLM生成代码质量的途径。我们并未让LLM直接输出目标语言代码,而是提出引导LLM先生成一种不透明的中间表示,该表示采用感知验证语言Dafny编写,可依据约定的规范自动验证正确性。随后,正确的Dafny程序会被编译为目标语言代码并返回给用户。整个流程中所有用户与系统的交互均通过自然语言完成,Dafny代码始终不会对外暴露。本文介绍了当前的原型系统,并报告了其在HumanEval Python代码生成基准上的性能表现。

英文摘要:

Using large language models (LLMs) to generate source code from natural language prompts is a popular and promising idea with a wide range of applications. One of its limitations is that the generated code can be faulty at times, often in a subtle way, despite being presented to the user as correct. In this paper, we explore ways in which formal methods can assist with increasing the quality of code generated by an LLM. Instead of emitting code in a target language directly, we propose that the user guides the LLM to first generate an opaque intermediate representation, in the verification-aware language Dafny, that can be automatically validated for correctness against agreed on specifications. The correct Dafny program is then compiled to the target language and returned to the user. All user-system interactions throughout the procedure occur via natural language; Dafny code is never exposed. We describe our current prototype and report on its performance on the HumanEval Python code generation benchmarks.

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

↑