[論文レビュー] Lost in Translation: A Study of Bugs Introduced by Large Language Models while Translating Code
本研究では、5つのプログラミング言語間でのコード翻訳における大規模言語モデル(LLM)の信頼性を調査し、LLMが正しく翻訳するケースは2.1%から47.3%にとどまることを明らかにした。翻訳バグの15の異なるカテゴリを同定し、LLMベースの手法と従来の非LLM手法を比較し、文脈に配慮したプロンプト設計戦略を提案。この戦略により、翻訳の正確性が平均で5.5%向上した。
Code translation aims to convert source code from one programming language (PL) to another. Given the promising abilities of large language models (LLMs) in code synthesis, researchers are exploring their potential to automate code translation. The prerequisite for advancing the state of LLM-based code translation is to understand their promises and limitations over existing techniques. To that end, we present a large-scale empirical study to investigate the ability of general LLMs and code LLMs for code translation across pairs of different languages, including C, C++, Go, Java, and Python. Our study, which involves the translation of 1,700 code samples from three benchmarks and two real-world projects, reveals that LLMs are yet to be reliably used to automate code translation -- with correct translations ranging from 2.1% to 47.3% for the studied LLMs. Further manual investigation of unsuccessful translations identifies 15 categories of translation bugs. We also compare LLM-based code translation with traditional non-LLM-based approaches. Our analysis shows that these two classes of techniques have their own strengths and weaknesses. Finally, insights from our study suggest that providing more context to LLMs during translation can help them produce better results. To that end, we propose a prompt-crafting approach based on the symptoms of erroneous translations; this improves the performance of LLM-based code translation by 5.5% on average. Our study is the first of its kind, in terms of scale and breadth, that provides insights into the current limitations of LLMs in code translation and opportunities for improving them. Our dataset -- consisting of 1,700 code samples in five PLs with 10K+ tests, 43K+ translated code, 1,748 manually labeled bugs, and 1,365 bug-fix pairs -- can help drive research in this area.
研究の動機と目的
- 一般およびコード特化型LLMが5つのプログラミング言語(C、C++、Go、Java、Python)間でコードを翻訳する際の効果性を評価すること。
- LLMによるソースコード翻訳で生じる翻訳失敗の根本的要因を同定し、分類すること。
- 正しさとバグのプロファイルの観点から、LLMベースのコード翻訳と非LLMベースのアプローチを比較すること。
- 翻訳エラーに関する文脈的フィードバックを提供することで、反復的プロンプト設計によるLLMのパフォーマンス向上の可能性を調査すること。
- 今後のLLMベースのコード翻訳研究を支援するため、1,700件のコードサンプル、10,000件以上のテストケース、43,000件以上の翻訳、1,748件のラベル付きバグ、1,365組のバグ修正ペアを含む包括的なデータセットを公開すること。
提案手法
- 5つのプログラミング言語にわたる3つのベンチマークと2つの実世界プロジェクトから1,700件の実行可能コードサンプルを収集した。
- 最先端の一般およびコード特化型LLMを用いて、各コードサンプルを複数のターゲット言語に翻訳した。
- データセットに付随する自動テストスイートを用いて翻訳の正しさを評価し、エッジケースについては手動での検証を実施した。
- 1,748件の失敗した翻訳について手動分析を実施し、15の異なるカテゴリの翻訳バグを同定・ラベル付けした。
- 過去のエラーの兆候を用いてLLMに文脈的フィードバックを提供するプロンプト設計技術を設計・評価した。
- LLMベースの翻訳と非LLMベースのアプローチ(例:トランスパイラー)を比較し、翻訳品質およびエラープロファイルにおける相対的な強み・弱みを評価した。

実験結果
リサーチクエスチョン
- RQ1RQ1.1: 最先端の一般およびコード特化型LLMは、複数のプログラミング言語間でコード翻訳においてどの程度のパフォーマンスを示すか?
- RQ2RQ1.2: 失敗した翻訳の結果はどのようなもので、どのような種類のエラーを示しているか?
- RQ3RQ2.1: LLMベースのコード翻訳に失敗した背後にある根本的要因(翻訳バグ)は何か?
- RQ4RQ2.2: これらのバグカテゴリは、失敗した翻訳においてどの程度広がっているか?
- RQ5RQ2.3: 実世界のプロジェクトにおけるバグと合成ベンチマークにおけるバグは、どのように異なるか?
- RQ6RQ3: 非LLMベースの翻訳手法は、LLMベースの手法と比較して正しさとエラーのプロファイルにおいて、どの程度優れているか?
- RQ7RQ4: エラーの兆候に基づく反復的プロンプト設計によって、LLMベースのコード翻訳パフォーマンスはどの程度向上するか?
主な発見
- LLMベースのコード翻訳は、調査対象のモデルと言語ペア全体で、テストケースのうちたった2.1%から47.3%のケースでのみ正しく機能する。
- 合計15の異なるカテゴリの翻訳バグが同定され、意味的誤解、誤った型処理、誤った制御構造などが含まれる。
- 実世界のプロジェクトでは、合成ベンチマークと比較してより複雑で多様なバグパターンを示しており、実コードはLLMにとってより大きな挑戦であることが示唆された。
- 非LLMベースのアプローチ(例:トランスパイラー)は、正しさの観点でLLMを上回り、特に複雑なコード構造では意味的バグをより少ない数で導入した。
- 本研究で提案されたプロンプト設計技術——過去のエラーの兆候を用いて再翻訳をガイドする——により、平均的な翻訳正確性が5.5%向上した。
- 本研究のデータセット(1,700件のコードサンプル、10,000件以上のテストケース、43,000件以上の翻訳、1,748件のラベル付きバグ、1,365組のバグ修正ペア)は、今後のLLMベースのコード翻訳研究を支援するために公開されている。

より良い研究を、今すぐ始めましょう
論文の読解から最終レビューまで、研究時間を劇的に削減しましょう。
クレジットカード登録不要
このレビューはAIが作成し、人間の編集者が確認しました。