Chain of Code: Reasoning with a Language Model-Augmented Code Emulator
Li, Chengshu, Liang, Jacky, Zeng, Andy, Chen, Xinyun, Hausman, Karol, Sadigh, Dorsa, Levine, Sergey, Fei-Fei, Li, Xia, Fei, Ichter, Brian
–arXiv.org Artificial Intelligence
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 semantic 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 not only write code, but also selectively "emulate" the interpreter by generating the expected output of "detect_sarcasm(string)" and other lines of code that cannot be executed. In this work, we propose Chain of Code (CoC), a simple yet surprisingly effective extension that improves LM code-driven reasoning. The key idea is to encourage LMs to format semantic sub-tasks in a program as flexible pseudocode that the interpreter 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. CoC 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.
arXiv.org Artificial Intelligence
Dec-7-2023
- Country:
- Africa
- Kenya > Nairobi City County
- Nairobi (0.04)
- Middle East
- Egypt > Cairo Governorate
- Cairo (0.04)
- Morocco
- Casablanca-Settat Region > Casablanca (0.04)
- Marrakesh-Safi Region > Marrakesh (0.04)
- Egypt > Cairo Governorate
- South Africa
- Gauteng > Johannesburg (0.04)
- Western Cape > Cape Town (0.04)
- Kenya > Nairobi City County
- Asia
- China > Beijing
- Beijing (0.04)
- India
- Karnataka > Bengaluru (0.04)
- Maharashtra > Mumbai (0.04)
- Japan > Honshū
- Kansai > Kyoto Prefecture
- Kyoto (0.04)
- Kantō > Tokyo Metropolis Prefecture
- Tokyo (0.04)
- Kansai > Kyoto Prefecture
- Middle East
- Israel > Jerusalem District
- Jerusalem (0.04)
- Republic of Türkiye > Batman Province
- Batman (0.04)
- Israel > Jerusalem District
- Singapore (0.04)
- Taiwan > Taiwan Province
- Taipei (0.04)
- Thailand
- Bangkok > Bangkok (0.04)
- Chiang Mai > Chiang Mai (0.04)
- China > Beijing
- Europe
- Estonia > Harju County
- Tallinn (0.04)
- Czechia > Prague (0.04)
- France > Occitanie
- Haute-Garonne > Toulouse (0.04)
- Finland > Uusimaa
- Helsinki (0.04)
- Norway > Eastern Norway
- Oslo (0.04)
- Holy See > Vatican City (0.04)
- Greece > Ionian Islands
- Corfu (0.04)
- Portugal > Lisbon
- Lisbon (0.04)
- Austria > Tyrol
- Innsbruck (0.04)
- Monaco (0.04)
- Denmark > Capital Region
- Copenhagen (0.04)
- Poland
- Masovia Province > Warsaw (0.04)
- Pomerania Province > Gdańsk (0.04)
- Albania > Tirana County
- Tirana (0.04)
- Slovenia > Central Slovenia
- Municipality of Ljubljana > Ljubljana (0.04)
- Germany > Bavaria
- Upper Bavaria > Munich (0.04)
- Netherlands > North Holland
- Amsterdam (0.04)
- Spain > Galicia
- Madrid (0.04)
- Sweden > Stockholm
- Stockholm (0.04)
- Estonia > Harju County
- North America
- Haiti (0.04)
- The Bahamas (0.14)
- Jamaica > St. James
- Montego Bay (0.04)
- Canada
- Newfoundland and Labrador > Labrador (0.04)
- Quebec > Montreal (0.04)
- United States
- Montana (0.04)
- California
- Alameda County > Berkeley (0.04)
- Los Angeles County > Los Angeles (0.04)
- San Diego County > San Diego (0.04)
- San Francisco County > San Francisco (0.04)
- Santa Clara County > Palo Alto (0.04)
- New Mexico > Bernalillo County
- Albuquerque (0.04)
- Illinois > Cook County
- Chicago (0.04)
- Utah > Salt Lake County
- Salt Lake City (0.04)
- Louisiana > Orleans Parish
- New Orleans (0.04)
- New York (0.04)
- Hawaii > Honolulu County
- Honolulu (0.04)
- Nevada > Clark County
- Las Vegas (0.04)
- Indiana > Marion County
- Indianapolis (0.04)
- Florida > Orange County (0.04)
- Minnesota > Hennepin County
- Minneapolis (0.04)
- Barbados (0.14)
- Belize (0.04)
- Mexico > Mexico City
- Mexico City (0.04)
- Montserrat (0.04)
- Grenada (0.04)
- Oceania > New Zealand
- North Island > Auckland Region > Auckland (0.04)
- South America
- Argentina > Pampas
- Buenos Aires F.D. > Buenos Aires (0.04)
- Chile
- Ecuador > Pichincha Province
- Quito (0.04)
- Peru > Cusco Department
- Cusco Province > Cusco (0.04)
- Argentina > Pampas
- Africa
- Genre:
- Research Report (0.50)
- Technology: