Skip to main content
QUICK REVIEW

[論文レビュー] Structured Chain-of-Thought Prompting for Code Generation

Jia Li, Ge Li|arXiv (Cornell University)|May 11, 2023
Software Engineering Research被引用数 17
ひとこと要約

SCoT promptingはLLMがプログラム構造(シーケンス、ブランチ、ループ、IO)を用いて中間推論を生成するよう制約し、標準のCoT promptingよりもベンチマークと言語全体でコード生成の精度を向上させる。

ABSTRACT

Large Language Models (LLMs) (e.g., ChatGPT) have shown impressive performance in code generation. LLMs take prompts as inputs, and Chain-of-Thought (CoT) prompting is the state-of-the-art prompting technique. CoT prompting asks LLMs first to generate CoTs (i.e., intermediate natural language reasoning steps) and then output the code. However, CoT prompting is designed for natural language generation and has low accuracy in code generation. In this paper, we propose Structured CoTs (SCoTs) and present a novel prompting technique for code generation, named SCoT prompting. Our motivation is source code contains rich structural information and any code can be composed of three program structures (i.e., sequence, branch, and loop structures). Intuitively, structured intermediate reasoning steps make for structured source code. Thus, we ask LLMs to use program structures to build CoTs, obtaining SCoTs. Then, LLMs generate the final code based on SCoTs. Compared to CoT prompting, SCoT prompting explicitly constrains LLMs to think about how to solve requirements from the view of source code and further the performance of LLMs in code generation. We apply SCoT prompting to two LLMs (i.e., ChatGPT and Codex) and evaluate it on three benchmarks (i.e., HumanEval, MBPP, and MBCPP). (1) SCoT prompting outperforms the state-of-the-art baseline - CoT prompting by up to 13.79% in Pass@1. (2) Human evaluation shows human developers prefer programs from SCoT prompting. (3) SCoT prompting is robust to examples and achieves substantial improvements.

研究の動機と目的

  • 推論をコード構造と整合させることでコード生成を改善する動機付け。
  • 中間ステップを構築するために、シーケンス、分岐、ループ、IO構造を用いる構造化チェーンオブソウト(SCoT)を導入する。
  • SCoT promptingを提案する:最初にSCoTを生成し、次にそのSCoTからコードを作成することで誤差伝播を抑制する。
  • 複数のLLMとプログラミング言語で、ベンチマークデータセットを横断してSCoT promptingを評価する。

提案手法

  • シーケンス、分岐、ループ、入出力(IO)構造からなる構造化チェーンオブソウト(SCoT)を定義する。
  • SCoTを生成するプロンプトと、SCoTからコードを生成するプロンプトの2つを設計する。
  • 誤差蓄積を低減するデバッグステップを含む2段階の生成パイプラインを使用する。
  • 要件ごとに複数の候補を生成するためにニュークレウスサンプリングと固定プロンプトを適用する(Pass@k評価)。
  • HumanEval(Python)、MBPP(Python)、MBCPP(C++)に対して、Zero-shot、Few-shot、CoTベースラインとSCoT promptingを比較する。

実験結果

リサーチクエスチョン

  • RQ1RQ1: ベンチマークとLLM全体で、SCoT promptingはベースラインに対してコード生成の精度(Pass@k)を改善しますか?
  • RQ2RQ2: 開発者はSCoT promptingで生成されたプログラムをベースラインより好むでしょうか?
  • RQ3RQ3: SCoT promptingは例の種(seed)や記述スタイルの選択に対して頑健ですか?
  • RQ4RQ4: 基本的なプログラム構造(シーケンス、分岐、ループ)とIO構造がSCoT promptingの性能に寄与する程度はどのくらいですか?

主な発見

BenchmarkBase ModelPrompting TechniquePass@1Pass@3Pass@5
HumanEvalChatGPTCoT prompting53.2969.7675.52
HumanEvalChatGPTSCoT Prompting60.6473.5377.32
MBPPChatGPTCoT prompting41.8351.0454.57
MBPPChatGPTSCoT Prompting46.9855.3158.36
MBCPPChatGPTCoT prompting53.5163.8467.03
MBCPPChatGPTSCoT Prompting57.0665.7068.70
  • SCoT promptingはCoT promptingよりPass@1を最大でHumanEvalで13.79%、MBPPで12.31%、MBCPPで6.63%改善する。
  • 人間の評価者は正確性、コードの匂い、保守性の点でSCoT promptingによって生成されたプログラムをベースラインより好む。
  • SCoT promptingはLLM(ChatGPTとCodex)および言語(Python、C++)全体で利得を生み、例の種と記述スタイルに対して頑健である。
  • アブレーションでは、3つの基本構造とIO構造のすべてが性能向上に寄与し、基本構造は明確に解ける、整然とした中間推論を支援している。

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

論文設計から論文執筆まで、研究時間を劇的に削減しましょう。

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

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