CodeChain: 대표적 서브 모듈을 통한 자기 수정 체인 기반의 모듈형 코드 생성 프레임워크
CodeChain: Towards Modular Code Generation Through Chain of Self-revisions with Representative Sub-modules
October 13, 2023
저자: Hung Le, Hailin Chen, Amrita Saha, Akash Gokul, Doyen Sahoo, Shafiq Joty
cs.AI
초록
대형 언어 모델(LLMs)은 이미 HumanEval이나 MBPP 벤치마크와 같은 간단한 프로그래밍 과제를 해결하는 데 상당히 능숙해졌습니다. 그러나 더 복잡하고 경쟁적인 프로그래밍 과제를 해결하는 것은 여전히 이러한 모델에게는 상당히 어려운 과제로 남아 있습니다. 이는 아마도 모델이 해결책을 단일적인 코드 블록으로 생성하는 경향이 있어, 이를 논리적인 하위 작업과 하위 모듈로 분해하지 않기 때문일 것입니다. 반면, 경험 많은 프로그래머들은 복잡한 과제를 해결하기 위해 본능적으로 추상화된 모듈화된 코드를 작성하며, 종종 이전에 개발한 모듈을 재사용합니다. 이러한 격차를 해결하기 위해, 우리는 CodeChain이라는 새로운 추론 프레임워크를 제안합니다. 이 프레임워크는 일련의 자기 수정(self-revision)을 통해 모듈화된 코드 생성을 유도하며, 각 수정은 이전 반복에서 생성된 대표적인 하위 모듈에 의해 안내됩니다. 구체적으로, CodeChain은 먼저 LLM에게 사고의 연쇄(chain-of-thought) 프롬프트를 통해 모듈화된 코드를 생성하도록 지시합니다. 그런 다음 두 단계를 반복하여 일련의 자기 수정을 적용합니다: 1) 생성된 하위 모듈을 추출하고 클러스터링하여 더 일반적이고 재사용 가능한 구현으로 클러스터 대표를 선택하고, 2) 원래의 사고의 연쇄 프롬프트에 이러한 선택된 모듈 구현을 추가하고 LLM에게 새로운 모듈화된 해결책을 다시 생성하도록 지시합니다. 우리는 LLM이 이전에 개발되고 검증된 하위 모듈을 재사용하도록 자연스럽게 유도함으로써, CodeChain이 생성된 해결책의 모듈성과 정확성을 모두 크게 향상시킬 수 있음을 발견했습니다. 이는 APPS에서 35%, CodeContests에서 76%의 상대적인 pass@1 개선을 달성했습니다. CodeChain은 OpenAI의 LLM뿐만 아니라 WizardCoder와 같은 오픈소스 LLM에서도 효과적인 것으로 나타났습니다. 또한, 우리는 다양한 프롬프트 방법, 클러스터 수, 모델 크기, 프로그램 품질 등에 대한 포괄적인 절제 연구를 수행하여 CodeChain의 성공을 뒷받침하는 유용한 통찰을 제공합니다.
English
Large Language Models (LLMs) have already become quite proficient at solving
simpler programming tasks like those in HumanEval or MBPP benchmarks. However,
solving more complex and competitive programming tasks is still quite
challenging for these models - possibly due to their tendency to generate
solutions as monolithic code blocks instead of decomposing them into logical
sub-tasks and sub-modules. On the other hand, experienced programmers
instinctively write modularized code with abstraction for solving complex
tasks, often reusing previously developed modules. To address this gap, we
propose CodeChain, a novel framework for inference that elicits modularized
code generation through a chain of self-revisions, each being guided by some
representative sub-modules generated in previous iterations. Concretely,
CodeChain first instructs the LLM to generate modularized codes through
chain-of-thought prompting. Then it applies a chain of self-revisions by
iterating the two steps: 1) extracting and clustering the generated sub-modules
and selecting the cluster representatives as the more generic and re-usable
implementations, and 2) augmenting the original chain-of-thought prompt with
these selected module-implementations and instructing the LLM to re-generate
new modularized solutions. We find that by naturally encouraging the LLM to
reuse the previously developed and verified sub-modules, CodeChain can
significantly boost both modularity as well as correctness of the generated
solutions, achieving relative pass@1 improvements of 35% on APPS and 76% on
CodeContests. It is shown to be effective on both OpenAI LLMs as well as
open-sourced LLMs like WizardCoder. We also conduct comprehensive ablation
studies with different methods of prompting, number of clusters, model sizes,
program qualities, etc., to provide useful insights that underpin CodeChain's
success.