Chain of Code: Argumentation mit einem sprachmodell-erweiterten Code-Emulator
Chain of Code: Reasoning with a Language Model-Augmented Code Emulator
December 7, 2023
Autoren: Chengshu Li, Jacky Liang, Andy Zeng, Xinyun Chen, Karol Hausman, Dorsa Sadigh, Sergey Levine, Li Fei-Fei, Fei Xia, Brian Ichter
cs.AI
Zusammenfassung
Code bietet eine allgemeine syntaktische Struktur, um komplexe Programme zu erstellen und präzise Berechnungen durchzuführen, wenn er mit einem Code-Interpreter kombiniert wird – wir stellen die Hypothese auf, dass Sprachmodelle (LMs) das Schreiben von Code nutzen können, um das Chain-of-Thought-Reasoning nicht nur bei logischen und arithmetischen Aufgaben, sondern auch bei linguistischen Aufgaben (und insbesondere bei solchen, die eine Mischung aus beidem sind) zu verbessern. Betrachten wir beispielsweise die Aufforderung an ein LM, Code zu schreiben, der die Häufigkeit von Sarkasmus in einem Essay zählt: Das LM könnte Schwierigkeiten haben, eine Implementierung für "detect_sarcasm(string)" zu schreiben, die vom Interpreter ausgeführt werden kann (die Handhabung der Randfälle wäre unüberwindbar). Dennoch könnten LMs eine gültige Lösung liefern, wenn sie nicht nur zum Schreiben des Codes verwendet werden, sondern auch selektiv den Interpreter "emulieren", indem sie die erwartete Ausgabe von "detect_sarcasm(string)" und anderer Codezeilen generieren (z. B. solche, die der Interpreter nicht kompilieren könnte). In dieser Arbeit schlagen wir Chain of Code (CoT) vor, eine einfache, aber überraschend effektive Erweiterung, die das code-gestützte Reasoning von LMs verbessert. Die zentrale Idee besteht darin, LMs dazu zu ermutigen, linguistische Teilaufgaben in einem Programm als flexibles Pseudocode zu formatieren, sodass der Compiler undefinierte Verhaltensweisen explizit erkennen und zur Simulation an ein LM (als "LMulator") übergeben kann. Experimente zeigen, dass Chain of Code Chain of Thought und andere Baselines in einer Vielzahl von Benchmarks übertrifft; auf BIG-Bench Hard erreicht Chain of Code 84 %, ein Zuwachs von 12 % gegenüber Chain of Thought. CoT skaliert gut mit sowohl großen als auch kleinen Modellen und erweitert den Umfang der Reasoning-Fragen, die LMs durch "Denken in Code" korrekt beantworten können. Projektwebseite: 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/.