Refactoring Programs Using Large Language Models with Few-Shot Examples

要約

複雑さが軽減され、より単純なプログラムは、保守性を高め、安全でバグのないプログラムを簡単に作成できる重要な要素です。
ただし、作業負荷が高く、動作中のプログラムが壊れるリスクがあるため、プログラマはコードのリファクタリングを行うことに消極的であり、そのため、潜在的な学習経験の損失も引き起こします。
これを軽減するために、大規模言語モデル (LLM) である GPT-3.5 を使用して、ユーザーが作成した Python プログラムのより複雑でないバージョンを提案する応用例を示します。これは、ユーザーがより良いプログラムの作成方法を学ぶことを奨励することを目的としています。
ワンショット例によるプロンプトの事前評価に基づいて、ターゲットのプログラミング問題ごとに最適なコードリファクタリング例を選択することにより、LLM の少数例によるプロンプトを活用する方法を提案します。
定量的評価では、それぞれ 10 個の候補を生成することでプログラムの 95.68% をリファクタリングでき、その結果、意味的に正しい生成されたプログラムのみをフィルタリングした後、平均循環的複雑度が 17.35% 減少し、平均行数が 25.84% 減少したことが示されています。
また、定性評価ではコード整形能力に優れている一方、コメントの削除や翻訳などの不要な動作も見られます。

要約(オリジナル)

A less complex and more straightforward program is a crucial factor that enhances its maintainability and makes writing secure and bug-free programs easier. However, due to its heavy workload and the risks of breaking the working programs, programmers are reluctant to do code refactoring, and thus, it also causes the loss of potential learning experiences. To mitigate this, we demonstrate the application of using a large language model (LLM), GPT-3.5, to suggest less complex versions of the user-written Python program, aiming to encourage users to learn how to write better programs. We propose a method to leverage the prompting with few-shot examples of the LLM by selecting the best-suited code refactoring examples for each target programming problem based on the prior evaluation of prompting with the one-shot example. The quantitative evaluation shows that 95.68% of programs can be refactored by generating 10 candidates each, resulting in a 17.35% reduction in the average cyclomatic complexity and a 25.84% decrease in the average number of lines after filtering only generated programs that are semantically correct. Furthermore, the qualitative evaluation shows outstanding capability in code formatting, while unnecessary behaviors such as deleting or translating comments are also observed.

arxiv情報

著者 Atsushi Shirafuji,Yusuke Oda,Jun Suzuki,Makoto Morishita,Yutaka Watanobe
発行日 2023-11-20 11:43:45+00:00
arxivサイト arxiv_id(pdf)

提供元, 利用サービス

arxiv.jp, Google

カテゴリー: cs.AI, cs.CL, cs.PL, cs.SE パーマリンク