코드 체인: 언어 모델 강화 코드 에뮬레이터를 활용한 추론
Chain of Code: Reasoning with a Language Model-Augmented Code Emulator
December 7, 2023
저자: Chengshu Li, Jacky Liang, Andy Zeng, Xinyun Chen, Karol Hausman, Dorsa Sadigh, Sergey Levine, Li Fei-Fei, Fei Xia, Brian Ichter
cs.AI
초록
코드는 코드 인터프리터와 결합할 때 복잡한 프로그램을 구축하고 정밀한 계산을 수행하기 위한 일반적인 구문 구조를 제공합니다. 우리는 언어 모델(LM)이 코드 작성 능력을 활용하여 논리 및 산술 작업뿐만 아니라 언어적 작업(특히 둘을 혼합한 작업)에 대한 Chain of Thought(CoT) 추론을 개선할 수 있다고 가정합니다. 예를 들어, LM에게 에세이에서 감지된 풍자의 횟수를 세는 코드를 작성하도록 요청하는 경우를 생각해 보겠습니다. LM은 인터프리터가 실행할 수 있는 "detect_sarcasm(string)"의 구현을 작성하는 데 어려움을 겪을 수 있습니다(예외 상황을 처리하는 것은 불가능할 수 있음). 그러나 LM이 코드를 작성하는 데만 사용되는 것이 아니라 "detect_sarcasm(string)" 및 기타 코드 라인의 예상 출력을 생성하여 인터프리터를 선택적으로 "에뮬레이트"하는 데 사용된다면 여전히 유효한 솔루션을 생성할 수 있습니다(예: 인터프리터가 컴파일할 수 없는 코드). 본 연구에서는 LM의 코드 기반 추론을 개선하는 간단하지만 놀라울 정도로 효과적인 확장인 Chain of Code(CoT)를 제안합니다. 핵심 아이디어는 LM이 프로그램 내의 언어적 하위 작업을 유연한 의사코드로 포맷화하도록 장려하여 컴파일러가 명시적으로 정의되지 않은 동작을 포착하고 이를 LM(즉, "LMulator")로 시뮬레이션할 수 있도록 하는 것입니다. 실험 결과, Chain of Code는 다양한 벤치마크에서 Chain of Thought 및 기타 베이스라인을 능가하는 것으로 나타났습니다. BIG-Bench Hard에서 Chain of Code는 84%를 달성했으며, 이는 Chain of Thought 대비 12%의 향상입니다. CoT는 대형 및 소형 모델 모두에서 잘 확장되며, LM이 "코드로 생각"함으로써 올바르게 답변할 수 있는 추론 질문의 범위를 넓힙니다. 프로젝트 웹페이지: https://chain-of-code.github.io/.
English
Code provides a general syntactic structure to build complex programs and
perform precise computations when paired with a code interpreter -- we
hypothesize that language models (LMs) can leverage code-writing to improve
Chain of Thought reasoning not only for logic and arithmetic tasks, but also
for linguistic ones (and in particular, those that are a mix of both). For
example, consider prompting an LM to write code that counts the number of times
it detects sarcasm in an essay: the LM may struggle to write an implementation
for "detect_sarcasm(string)" that can be executed by the interpreter (handling
the edge cases would be insurmountable). However, LMs may still produce a valid
solution if they are used not only to write the code, but also to selectively
"emulate" the interpreter by generating the expected output of
"detect_sarcasm(string)" and other lines of code (e.g., that the interpreter
could not compile). In this work, we propose Chain of Code (CoT), a simple yet
surprisingly effective extension that improves LM code-driven reasoning. The
key idea is to encourage LMs to format linguistic sub-tasks in a program as
flexible pseudocode that the compiler can explicitly catch undefined behaviors
and hand off to simulate with an LM (as an "LMulator"). Experiments demonstrate
that Chain of Code outperforms Chain of Thought and other baselines across a
variety of benchmarks; on BIG-Bench Hard, Chain of Code achieves 84%, a gain of
12% over Chain of Thought. CoT scales well with large and small models alike,
and broadens the scope of reasoning questions that LMs can correctly answer by
"thinking in code". Project webpage: https://chain-of-code.github.io/.