Skip to main content
QUICK REVIEW

[論文レビュー] Can ChatGPT replace StackOverflow? A Study on Robustness and Reliability of Large Language Model Code Generation

Zhong Li, Zilong Wang|arXiv (Cornell University)|Aug 20, 2023
Software Engineering Research被引用数 6
ひとこと要約

この論文では、JavaにおけるAPI誤用に注目して、大規模言語モデル(LLMs)が生成するコードの信頼性と耐障害性を評価するためのベンチマーク「RobustAPI」を紹介している。機能的な正しさがあるにもかかわらず、GPT-4は62%のAPI誤用率を示しており、検証なしにLLMによって生成されたコードを実世界のソフトウェアで使用する際の深刻なリスクを浮き彫りにしている。

ABSTRACT

Recently, the large language models (LLMs) have shown extraordinary ability in understanding natural language and generating programming code. It has been a common practice of software engineers to consult LLMs when encountering coding questions. Although efforts have been made to avoid syntax errors and align the code with the intended semantics, the reliability and robustness of the code generationfrom LLMs have not yet been thoroughly studied. The executable code is not equivalent to the reliable and robust code, especially in the context of real-world software development. The misuse of APIs in the generated code could lead to severe problem, such as resource leaks, program crashes. To make things worse, the users of LLM code generation services are actually the developers that are most vulnerable to these code that seems right -- They are always novice developers that are not familiar with the APIs that LLMs generate code for them. Therefore, they could hardly tell the misuse in the code generated by LLMs, which further facilitates the incorrect code applied in real-world software. Existing code evaluation benchmark and datasets focus on crafting small tasks such as programming questions in coding interviews, which however deviates from the problem that developers would ask LLM for real-world coding help. To fill the missing piece, in this work, we propose a dataset RobustAPI for evaluating the reliability and robustness of code generated by LLMs. We collect 1208 coding questions from StackOverflow on 24 representative Java APIs. We summarize thecommon misuse patterns of these APIs and evaluate them oncurrent popular LLMs. The evaluation results show that evenfor GPT-4, 62% of the generated code contains API misuses,which would cause unexpected consequences if the code isintroduced into real-world software.

研究の動機と目的

  • 機能的な正しさを超えた信頼性と耐障害性を評価するフレームワークの欠如に応えるため。
  • 実世界のソフトウェア開発シナリオにおける一般的なAPI誤用パターンを特定・定量化するため。
  • 広く使われるJava APIに焦点を当て、Stack Overflowからの実際の開発者クエリを反映したベンチマークを構築するため。
  • 一貫した例提示(in-context learning)やAPIルールの埋め込みといったプロンプト戦略が、誤用を低減する効果があるかを評価するため。
  • 今後の信頼性の高いコード生成に関する研究を可能にするために、データセットと評価フレームワークをオープンソース化するため。

提案手法

  • 著者らは、18種の代表的なJava APIに関連するStack Overflowの1,208件の実際のコーディング質問を収集した。
  • 抽象構文木(AST)を用いて正しいAPI使用パターンを構造化されたコールシーケンスとして形式化し、適切な使用シーケンスを定義した。
  • 生成コードのAST構造を期待される使用パターンと照合することで、分析を行うためのカスタム評価ツールを開発した。
  • ゼロショットおよびワンショットプロンプティング設定の下で、GPT-3.5、GPT-4、Llama-2、Vicuna-1.5の4つのLLMを対象にベンチマークを評価した。
  • 機能的な正しさとAPI誤用検出の両方を評価指標として用い、誤用は構造化されたコールシーケンスの違反として定義した。
  • 温度設定とプロンプト工学(例:APIルールの追加)を変更し、誤用の低減に与える影響を評価した。

実験結果

リサーチクエスチョン

  • RQ1コードが文法的に正しく、ユーザーの意図と機能的に整合している場合でも、LLMが生成するコードにおけるAPI誤用はどれほど広範にわたっているのか?
  • RQ2関連する例を提示する一貫した例提示(in-context learning)は、LLMが生成するコードにおけるAPI誤用率を顕著に低減できるのか?
  • RQ3プロンプトに明示的なAPI使用ルールを埋め込むことで、少数の例提示(few-shot prompting)に比べて生成コードの信頼性が向上するのか?
  • RQ4どのJava APIがLLMによって最も誤用されやすく、その主な誤用パターンは何か?
  • RQ5温度設定やモデルアーキテクチャは、API誤用の発生確率にどの程度影響を及えるのか?

主な発見

  • テストされた中で最も高度なモデルであるGPT-4ですら、生成コードにおいて62%のAPI誤用率を示しており、広範な信頼性の問題を示している。
  • ワンショットの関連例を提示しても、GPT-3.5は依然として38.56%の誤用率を維持しており、少数の例提示による改善は限定的であることが示された。
  • プロンプトにAPI使用ルールを埋め込んでも、誤用率の顕著な低減は見られず、GPT-3.5ではこの設定下で65.01%の誤用率を示した。
  • コンパイル失敗率はGPT-4で最も低く(10%未満)、GPT-3.5は特に温度設定が高い場合に高い失敗率を示した。
  • Android APIのActivity.setContentViewは、全モデルにおいて最も低い誤用率を示しており、一部のAPIはLLMにとってより予測可能であることが示唆された。
  • 最も一般的な誤用パターンには、例外処理の欠落、リソースの不適切なクロージャー、メソッドの順序の誤りが含まれる。

より良い研究を、今すぐ始めましょう

論文の読解から最終レビューまで、研究時間を劇的に削減しましょう。

クレジットカード登録不要

このレビューはAIが作成し、人間の編集者が確認しました。