arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2303.14542cs.SE
收藏

组合来自多个源的上下文以生成特定于文档的代码示例

Combining Contexts from Multiple Sources for Documentation-Specific Code Example Generation

Junaed Younus Khan, Gias Uddin

摘要:

代码示例是优秀文档的关键部分。它帮助开发人员轻松理解文档并使用相应的代码单元(例如,方法)正确。然而,许多官方文档仍然缺乏(好的)代码示例,这是几项研究发现的常见文档问题之一。因此,在本文中,我们考虑自动代码示例生成的文档,一个方向探索现有的研究。我们采用Codex,一个基于GPT-3的模型,在自然语言和程序设计语言上进行预训练,从源代码和作为输入的文档中生成代码示例。我们对40种scikit-learn方法的初步调查显示,这种方法能够生成良好的代码示例,其中72.5%的代码示例执行时没有错误(可通过性),82.5%的代码示例正确处理了目标方法和文档(相关性)。我们还发现,在输入中加入错误日志(由编译器在执行失败的代码示例时产生)进一步将可通过性从72.5%提高到87.5%。因此,我们的调查设置文档特定的代码示例生成的基础,并保证在未来的深入研究。

英文摘要:

Code example is a crucial part of good documentation. It helps the developers to understand the documentation easily and use the corresponding code unit (e.g., method) properly. However, many official documentation still lacks (good) code example and it is one of the common documentation issues as found by several studies. Hence in this paper, we consider automatic code example generation for documentation, a direction less explored by the existing research. We employ Codex, a GPT-3 based model, pre-trained on both natural and programming languages to generate code examples from source code and documentation given as input. Our preliminary investigation on 40 scikit-learn methods reveals that this approach is able to generate good code examples where 72.5% code examples were executed without error (passability) and 82.5% properly dealt with the target method and documentation (relevance). We also find that incorporation of error logs (produced by the compiler while executing a failed code example) in the input further improves the passability from 72.5% to 87.5%. Thus, our investigation sets the base of documentation-specific code example generation and warrants in-depth future studies.

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

↑