Skip to main content
QUICK REVIEW

[論文レビュー] CATCODER: Repository-Level Code Generation with Relevant Code and Type Context

Zhiyuan Pan, Xing Hu|arXiv (Cornell University)|Jun 5, 2024
Software Testing and Debugging TechniquesComputer Science被引用数 3
ひとこと要約

CatCoderは、静的型付き言語向けのリtrieval増強型コード生成フレームワークであり、静的解析から得られる型コンテキストと関連コードの両方を統合することで、リポジトリレベルのコード生成を向上させる。微調整や外部データベースを必要とせず、LLMのファインチューニングなしで、RepoCoderより最大17.35%高いpass@kスコアを達成し、多様なLLMにおいて一貫した向上を示す。

ABSTRACT

Large language models (LLMs) have demonstrated remarkable capabilities in code generation tasks. However, repository-level code generation presents unique challenges, particularly due to the need to utilize information spread across multiple files within a repository. Specifically, successful generation depends on a solid grasp of both general, context-agnostic knowledge and specific, context-dependent knowledge. While LLMs are widely used for the context-agnostic aspect, existing retrieval-based approaches sometimes fall short as they are limited in obtaining a broader and deeper repository context. In this paper, we present CatCoder, a novel code generation framework designed for statically typed programming languages. CatCoder enhances repository-level code generation by integrating relevant code and type context. Specifically, it leverages static analyzers to extract type dependencies and merges this information with retrieved code to create comprehensive prompts for LLMs. To evaluate the effectiveness of CatCoder, we adapt and construct benchmarks that include 199 Java tasks and 90 Rust tasks. The results show that CatCoder outperforms the RepoCoder baseline by up to 14.44% and 17.35%, in terms of compile@k and pass@k scores. In addition, the generalizability of CatCoder is assessed using various LLMs, including both code-specialized models and general-purpose models. Our findings indicate consistent performance improvements across all models, which underlines the practicality of CatCoder. Furthermore, we evaluate the time consumption of CatCoder in a large open source repository, and the results demonstrate the scalability of CatCoder.

研究の動機と目的

  • 既存のリtrievalベースのアプローチが、リポジトリレベルのコード生成において、しばしばファイル間依存関係を捉えられず、不足したコンテキストにより幻覚現象を引き起こすという限界を解決すること。
  • 静的解析によるクラスのフィールドやメソッドシグネチャから得られる型コンテキストが、静的型付き言語におけるコード生成を向上させる補完的情報源として機能するかどうかを検討すること。
  • モデルの微調整や外部データベースを必要とせず、LLMベースのコード生成を向上させる実用的で汎用性の高いフレームワークを設計すること。
  • Rustにおけるリポジトリレベルのコード生成のための新しいベンチマークを構築し、評価すること。

提案手法

  • CatCoderは、RepoCoderなどの先行研究と同様に、リポジトリ内から関連コードスニペットをリtrievalするメカニズムを用いる。
  • 既存の静的アナライザーを活用し、メソッドシグネチャからの依存関係を分析することで、対象クラスのフィールドやメソッドシグネチャなどの型コンテキストを抽出する。
  • 抽出された型コンテキストのテキスト表現を生成し、LLMのプロンプトに統合する。
  • リtrievedコードと型コンテキストを統合して、LLMに送るための包括的で包括的なプロンプトを構築し、コンテキスト認識を強化する。
  • このアプローチは、ファイナライズされたLLMの上に構築されており、微調整や学習の必要がない。
  • フレームワークは、実際のオープンソースリポジトリから抽出された199件のJavaおよび90件のRustタスクから構成される新しいベンチマークを用いて評価された。

実験結果

リサーチクエスチョン

  • RQ1関連コードに加えて型コンテキストを統合することで、静的型付き言語におけるリポジトリレベルのコード生成の正確性が向上するか?
  • RQ2pass@kスコアの観点から、CatCoderはRepoCoderのような最先端のリtrievalベースのベースラインと比較してどの程度の性能を示すか?
  • RQ3CatCoderは、コード専用モデルおよび汎用モデルを含む、さまざまなLLMにどの程度汎用的に適用可能か?
  • RQ4CatCoderは、Rustのようなあまり一般的でない静的型付き言語におけるコード生成を効果的に支援できるか?

主な発見

  • CatCoderは、評価されたベンチマークにおいて、RepoCoderベースラインを最大17.35%上回るpass@kスコアを達成し、顕著な性能向上を示した。
  • フレームワークは、コード専用モデルおよび汎用モデルを含む、すべてのテスト対象のLLMでpass@kスコアを向上させ、その汎用性を確認した。
  • 型コンテキストの統合により、コードリtrievalを補完する意味のある補助情報が得られ、幻覚現象が軽減され、コードの正しさが向上した。
  • 本研究では、Rustにおけるリポジトリレベルのコード生成のための最初のベンチマークを提示した。
  • CatCoderは、モデルの微調整や外部データベースを一切必要とせず、実世界での展開に実用的である。

この論文を読む

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

Nubintでこの論文を読む

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