Skip to main content
QUICK REVIEW

[論文レビュー] Teaching Code LLMs to Use Autocompletion Tools in Repository-Level Code Generation

Chong Wang, Zhang Jian|arXiv (Cornell University)|Jan 12, 2024
Software Engineering ResearchComputer Science被引用数 3
ひとこと要約

この論文では、コード生成中のリポジトリレベルの依存関係エラーを低減するために、プログラム解析に基づく補完ツールをコードLLMに統合するフレームワーク、ToolGenを提案する。関数コーパスに補完ツールを起動するためのマークトークンを挿入し、そのコーパスでLLMを微調整することで、推論時に制約付きグリーディサーチを用いて外部補完ツール(例:Jedi)を起動する。このアプローチにより、3つのコードLLMで依存関係カバレッジが15.2%〜45.8%向上し、静的妥当性率が10.9%〜42.2%向上した。一方で、標準的な類似度メトリクスの性能は維持された。

ABSTRACT

Code large language models (LLMs) face limitations in repository-level code generation due to their lack of awareness of repository-level dependencies (e.g., user-defined attributes), resulting in dependency errors such as undefined-variable and no-member errors. In this work, we introduce ToolGen, an approach that integrates autocompletion tools into the code LLM generation process to address these dependencies. ToolGen comprises two main phases: Trigger Insertion and Model Fine-tuning (Offline), and Tool-integrated Code Generation (Online). During the offline phase, ToolGen augments functions within a given code corpus with a special mark token, indicating positions to trigger autocompletion tools. These augmented functions, along with their corresponding docstrings, are then used to fine-tune a selected code LLM. In the online phase, ToolGen iteratively generates functions by predicting tokens step-by-step using the fine-tuned LLM. Whenever a mark token is encountered, ToolGen invokes the autocompletion tool to suggest code completions and selects the most appropriate one. We conduct comprehensive experiments to evaluate ToolGen's effectiveness in repository-level code generation. To facilitate this evaluation, we create a benchmark comprising 671 real-world code repositories and introduce two new dependency-based metrics: Dependency Coverage and Static Validity Rate. The results demonstrate that ToolGen significantly improves Dependency Coverage by 31.4% to 39.1% and Static Validity Rate by 44.9% to 57.7% across the three LLMs, while maintaining competitive or improved performance in widely recognized similarity metrics such as BLEU-4, CodeBLEU, Edit Similarity, and Exact Match. On the CoderEval dataset, ToolGen achieves improvements of 40.0% and 25.0% in Pass@1 for CodeT5 and CodeLlama, respectively.

研究の動機と目的

  • ユーザー定義の依存関係(関数や属性など)に無知であるため、コードLLMがリポジトリレベルのコード生成において重大な制限を抱えているという問題を解決すること。
  • 現実世界のコード生成で一般的な未定義変数エラーやno-memberエラーなどの依存関係エラーを低減すること。
  • プログラム解析に基づく補完ツール(例:Jedi)をLLMの生成パイプラインに統合し、文脈に応じたコード提案を提供すること。
  • 680の実世界リポジトリから構成されるベンチマークを構築し、リポジトリレベル評価の新規メトリクス「依存関係カバレッジ」と「静的妥当性率」を導入すること。
  • 本手法の多様なコードLLMアーキテクチャおよびモデルスケールにわたる一般化可能性を検証すること。

提案手法

  • 構文的・意味的文脈に基づき、補完を起動すべき位置に特別なマークトークンを挿入することで、コードコーパスを拡張する。
  • 各関数とそのドキュメント文字列をペアとして与えることで、選択されたコードLLMを拡張コーパスで微調整し、適切な位置にマークトークンを生成するように学習させる。
  • 推論時、微調整済みLLMがトークンを段階的に生成する。マークトークンが検出されると、システムは外部補完ツール(例:Jedi)を起動し、有効なコード補完を取得する。
  • 制約付きグリーディサーチを用いて、ツールの提案の中から最も適切な補完を選択し、構文的・意味的整合性を保証する。
  • 2段階のパイプラインを採用:オフラインでのデータ拡張と微調整、その後にオンラインでのツール統合コード生成。
  • プログラム解析を活用して、未完成な関数とプロジェクトの文脈に基づき、利用可能な属性やメソッドを補完ツールが推定可能にする。
Figure 1 : Illustrative Example of LLM Prediction and Tool Completion
Figure 1 : Illustrative Example of LLM Prediction and Tool Completion

実験結果

リサーチクエスチョン

  • RQ1RQ1: コードLLMに補完ツールを統合することで、リポジトリレベルのコード生成における依存関係エラーを顕著に低減できるか?
  • RQ2RQ2: 依存関係カバレッジおよび静的妥当性率という観点で、ToolGenは異なるコードLLMでどのように性能を発揮するか?
  • RQ3RQ3: ToolGenは多様なコードLLMアーキテクチャおよびモデルスケールに一般化可能か?
  • RQ4RQ4: IRベースのツールやプロンプトエンジニアリングを用いる既存手法と比較して、ToolGenはリポジトリレベルの依存関係をどのように処理するか?

主な発見

  • ToolGenは3つの異なるコードLLMで依存関係カバレッジを15.2%〜45.8%向上させ、依存関係関連エラーの顕著な低減を示した。
  • 静的妥当性率は10.9%〜42.2%向上し、生成コードの構文的・意味的整合性の向上を示した。
  • BLEU-4、CodeBLEU、編集類似度といった標準的な類似度メトリクスにおいても、競争力ある性能を維持しており、生成品質の低下は見られなかった。
  • 一般化評価により、異なるコードLLMアーキテクチャおよびモデルスケールにおいて一貫した性能向上が確認され、本手法の堅牢性が裏付けられた。
  • 680の実世界リポジトリから構成されるベンチマークと、依存関係カバレッジおよび静的妥当性率の導入により、リポジトリレベルコード生成のための新たな関連評価基準が提供された。
  • CodeLlamaベースの結果においてデータ漏洩効果が確認されなかったことは、一般化結果がそれを裏付けており、性能向上は事前学習データの重複ではなく、本手法によるものであると示唆された。
(a) Decoder-only Model
(a) Decoder-only Model

この論文を読む

Nubintのビューアで原文を開き、読みながら気になる箇所をすぐに質問できます。

Nubintでこの論文を読む

このレビューはAIが論文の原文をもとに作成しました。引用する前に原文をご確認ください。