ToolCoder:教导代码生成模型使用 API 搜索工具
ToolCoder: Teach Code Generation Models to use API search tools
AI总结:
ToolCoder 将 API 搜索工具集成到代码生成模型中,通过 ChatGPT 自动标注数据并微调模型,使其在推理时自动调用搜索工具选择 API,在多个基准上显著优于现有方法且小模型可媲美 GPT-3.5。
摘要:
从自然语言描述中自动生成源代码近年来已成为一个不断发展的研究领域。然而,当前的大规模代码生成模型在为特定上下文选择合适的 API 时,常常遇到困难。这些模型可能会生成不符合需求的 API,或者引用第三方库中不存在的 API,特别是对于不太知名或私有的库。受人类开发者使用工具搜索 API 的过程启发,我们提出了 ToolCoder,这是一种将 API 搜索工具与现有模型集成以辅助代码生成和 API 选择的新方法。为了教会我们的模型使用工具,我们引入了一种使用 ChatGPT 的自动化数据标注方法,将工具使用信息添加到源代码数据中,并对代码生成模型进行微调。在推理过程中,我们将 API 搜索工具集成到生成过程中,以便我们的模型在选择 API 时能够自动使用搜索工具获取建议。我们的实验结果表明,ToolCoder 在五个公共和私有库代码生成基准上表现出优异的性能和泛化能力,与最先进的方法相比,平均 pass@1 指标至少提高了 6.21%,平均 pass@10 指标提高了 9.64%。此外,我们展示了我们相对较小的 ToolCoder 模型可与当前最佳模型之一 GPT-3.5 相媲美,突显了将编程工具纳入代码生成过程的潜力。
英文摘要:
Automatically generating source code from natural language descriptions has been a growing field of research in recent years. However, current large-scale code generation models often encounter difficulties when selecting appropriate APIs for specific contexts. These models may generate APIs that do not meet requirements or refer to non-existent APIs in third-party libraries, especially for lesser-known or private libraries. Inspired by the process of human developers using tools to search APIs, we propose ToolCoder, a novel approach that integrates API search tools with existing models to assist in code generation and API selection. To teach our model to use tools, we introduce an automated data annotation method using ChatGPT to add tool usage information into the source code data and fine-tune code generation models. During inference, we integrate API search tools into the generation process so that our model can automatically use the search tool to get suggestions when selecting an API. Our experimental results demonstrate that ToolCoder exhibits excellent performance and generalization across five public and private library code generation benchmarks, with at least 6.21\% improvement on average pass@1 metrics and 9.64\% improvement on average pass@10 metrics compared to state-of-the-art methods. Furthermore, we show that our relatively small ToolCoder model is comparable to one of the current best models, GPT-3.5, highlighting the potential of incorporating programming tools into the code generation process.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。