Skip to main content
QUICK REVIEW

[Paper Review] ToolCoder: Teach Code Generation Models to use API search tools

Kechi Zhang, Zhang, Huangzhao|arXiv (Cornell University)|May 6, 2023
Software Engineering ResearchComputer Science10 citations
TL;DR

ToolCoder integrates API search tools into pre-trained code generation models, enabling automated tool usage for API selection during code generation, yielding consistent gains on public and private library benchmarks. It uses ChatGPT-based data annotation and LoRA-based fine-tuning to enable efficient tool-enabled decoding.

ABSTRACT

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.

Motivation & Objective

  • Motivate and address API selection challenges in code generation models due to vast and private libraries.
  • Introduce a tool-augmented data pipeline to teach models to use API search tools.
  • Propose an efficient fine-tuning approach to enable tool usage during decoding.
  • Demonstrate generalization of ToolCoder on public and private library benchmarks.

Proposed method

  • Annotate a tool-augmented dataset automatically using ChatGPT to insert tool usage calls into source code data.
  • Fine-tune pre-trained code generation models with parameter-efficient tuning (LoRA) targeting API search tool usage.
  • Integrate API search tools into the decoding process during inference, triggering tool calls when the model outputs a tool invocation token.
  • Use two search tool sources: online DuckDuckGo + in-document BM25-based retrieval for private libraries, unified as API search calls with special tokens.
  • Evaluate ToolCoder on five benchmarks (three public: NumpyEval, PandasEval, TorchDataEval; two private: MonkeyEval, BeatNumEval) using pass@k metrics (k=1,10).
  • Compare against general-code-generation baselines and API-oriented baselines, including GPT-3.5 as a strong reference.

Experimental results

Research questions

  • RQ1RQ1: How does ToolCoder perform vs SOTA baselines on public library benchmarks?
  • RQ2RQ2: How does ToolCoder perform on private library benchmarks?
  • RQ3RQ3: What are the contributions of the dataset, training, and inference components (ablation)?
  • RQ4RQ4: What is the code quality and failure mode of ToolCoder-generated solutions?

Key findings

  • ToolCoder achieves at least 6.21% average improvement in pass@1 and 9.64% average improvement in pass@10 over state-of-the-art baselines on public benchmarks.
  • ToolCoder-OnlineTool variant with an online tool achieves strong results and reduces API-selection errors.
  • On private libraries, ToolCoder with documentation search or private-documentation tools demonstrates stable improvements and good generalization.
  • Across five benchmarks, ToolCoder shows average pass@1 improvements of 6.21–19.00% depending on setup, approaching or matching large models on some public benchmarks.
  • LoRA-based fine-tuning enables parameter-efficient learning, with only 0.18–0.09% of parameters trained for CodeGen-350M and CodeGen-2B respectively.
  • An ablation study confirms the effectiveness of data annotation, training, and inference design choices.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.