Skip to main content
QUICK REVIEW

[논문 리뷰] Structured Chain-of-Thought Prompting for Code Generation

Jia Li, Ge Li|arXiv (Cornell University)|2023. 05. 11.
Software Engineering Research인용 수 17
한 줄 요약

SCoT 프롬프트는 LLM이 프로그램 구조(순서, 분기, 루프, 및 입출력)를 사용하여 중간 추론을 생성하게 하여 표준 CoT 프롬프트보다 벤치마크와 언어 전반에 걸쳐 코드 생성 정확도가 높아진다.

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 구조를 이용하는 Structured CoT(SCoT)를 도입하여 중간 단계를 구축합니다.
  • SCoT 프롬 prompting: 먼저 SCoT를 생성한 뒤 코드를 구현하여 에러 전파를 감소합니다.
  • 여러 LLM과 프로그래밍 언어에서 벤치마크 데이터셋을 대상으로 SCoT prompting을 평가합니다.

제안 방법

  • Structured Chain-of-Thought(SCoT)를 시퀀스, 분기, 루프, 입출력 구조로 구성한다.
  • SCoT를 생성하는 프롬프트와 SCoT에서 코드를 생성하는 두 가지 프롬프트를 설계한다.
  • 오류 누적 감소를 위한 디버깅 단계를 포함한 두 단계 생성 파이프라인을 사용한다.
  • 주성 채택(nucleus sampling) 및 고정 프롬트를 사용하여 요구사항당 여러 후보를 생성한다(Pass@k 평가).
  • HumanEval(Python), MBPP(Python), MBCPP(C++)에서 Zero-shot, Few-shot 및 CoT 베이스라인과 비교한다.

실험 결과

연구 질문

  • RQ1RQ1: SCoT 프롬 prompting이 벤치마크와 LLM 전반에서 베이스라인 대비 코드 생성 정확도(Pass@k)를 향상시키는가?
  • RQ2RQ2: 개발자들이 Baselines보다 SCoT 프롬 prompting으로 생성된 프로그램을 더 선호하는가?
  • RQ3RQ3: SCoT 프롬 prompting은 예시 시드와 작성 스타일의 선택에 강건한가?
  • RQ4RQ4: 기본 프로그램 구조(순서, 분기, 루프) 및 IO 구조의 기여도가 SCoT 프롬 prompting 성능에 어떤 영향을 미치는가?

주요 결과

벤치마크기본 모델프롬프트 기법Pass@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은 HumanEval에서 CoT 프롬 prompting보다 Pass@1을 최대 13.79% 향상시키고, MBPP에서 12.31%, MBCPP에서 6.63%를 향상시켰다.
  • 인간 평가자들은 정확성, 코드 냄새, 유지 관리 용이성 측면에서 SCoT 프롬 prompting으로 생성된 프로그램을 베이스라인보다 선호한다.
  • SCoT 프롬 prompting은 다양한 LLM(ChatGPT 및 Codex)과 언어(Python, C++)에서 이득을 가져오며 예시 시드 및 작성 스타일에 대해 강건하다.
  • 소거 분석에 따르면 세 가지 기본 구조와 IO 구조가 모두 기여하며, 기본 구조가 해결 가능하고 잘 구성된 중간 추론에 명확한 도움을 준다.

더 나은 연구,지금 바로 시작하세요

연구 설계부터 논문 작성까지, 연구 시간을 획기적으로 줄여보세요.

카드 등록 없음 · 무료 플랜 제공

이 리뷰는 AI가 만들고, 인간 에디터가 검토했습니다.