Catena di Codice: Ragionamento con un Emulatore di Codice Potenziato da Modelli Linguistici
Chain of Code: Reasoning with a Language Model-Augmented Code Emulator
December 7, 2023
Autori: Chengshu Li, Jacky Liang, Andy Zeng, Xinyun Chen, Karol Hausman, Dorsa Sadigh, Sergey Levine, Li Fei-Fei, Fei Xia, Brian Ichter
cs.AI
Abstract
Il codice fornisce una struttura sintattica generale per costruire programmi complessi e eseguire calcoli precisi quando abbinato a un interprete di codice. Noi ipotizziamo che i modelli linguistici (LM) possano sfruttare la scrittura di codice per migliorare il ragionamento a Catena di Pensiero (Chain of Thought, CoT) non solo per compiti di logica e aritmetica, ma anche per quelli linguistici (e in particolare, per quelli che sono un mix di entrambi). Ad esempio, consideriamo il caso in cui si chiede a un LM di scrivere un codice che conti il numero di volte in cui rileva sarcasmo in un saggio: il LM potrebbe avere difficoltà a scrivere un'implementazione per "detect_sarcasm(string)" che possa essere eseguita dall'interprete (gestire i casi limite sarebbe insormontabile). Tuttavia, i LM potrebbero comunque produrre una soluzione valida se vengono utilizzati non solo per scrivere il codice, ma anche per "emulare" selettivamente l'interprete generando l'output atteso di "detect_sarcasm(string)" e altre righe di codice (ad esempio, che l'interprete non potrebbe compilare). In questo lavoro, proponiamo Chain of Code (CoC), un'estensione semplice ma sorprendentemente efficace che migliora il ragionamento guidato dal codice nei LM. L'idea chiave è incoraggiare i LM a formattare i sotto-task linguistici in un programma come pseudocodice flessibile, in modo che il compilatore possa rilevare esplicitamente comportamenti non definiti e delegarli alla simulazione con un LM (come "LMulator"). Gli esperimenti dimostrano che Chain of Code supera Chain of Thought e altri baseline su una varietà di benchmark; su BIG-Bench Hard, Chain of Code raggiunge l'84%, un miglioramento del 12% rispetto a Chain of Thought. CoC scala bene sia con modelli grandi che piccoli e amplia la gamma di domande di ragionamento che i LM possono rispondere correttamente "pensando in codice". Pagina web del progetto: 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/.