CodeI/O: Condensing Reasoning Patterns via Code Input-Output Prediction
Junlong Li, Daya Guo, Dejian Yang, Runxin Xu, Yu Wu, Junxian He
2025-02-12
Summary
This paper talks about CodeI/O, a new way to teach AI language models how to reason better by learning from computer code. Instead of just focusing on specific skills like math or coding, CodeI/O helps AI understand broader reasoning patterns that can be applied to many different types of problems.
What's the problem?
Current AI models are good at specific tasks like math or coding, but they struggle with more general reasoning skills. This is because there isn't enough diverse training data to help them learn these broader thinking patterns. As a result, AI models often can't apply their reasoning skills to new or different types of problems.
What's the solution?
The researchers created CodeI/O, which takes computer code and turns it into a format where the AI has to predict what inputs and outputs the code would have. This process is done using natural language, so the AI learns to explain its reasoning in words. By doing this, CodeI/O teaches AI models important thinking skills like planning, searching for solutions, and breaking down problems into smaller parts. They also made an improved version called CodeI/O++ that can check its answers and make them better.
Why it matters?
This matters because it could make AI much better at solving all kinds of problems, not just specific ones they've been trained for. By learning these general reasoning skills, AI could become more flexible and useful in many different fields, from science to everyday problem-solving. It's a big step towards making AI that can think more like humans do, adapting their knowledge to new situations.
Abstract
Reasoning is a fundamental capability of Large Language Models. While prior research predominantly focuses on enhancing narrow skills like math or code generation, improving performance on many other reasoning tasks remains challenging due to sparse and fragmented training data. To address this issue, we propose CodeI/O, a novel approach that systematically condenses diverse reasoning patterns inherently embedded in contextually-grounded codes, through transforming the original code into a code input-output prediction format. By training models to predict inputs/outputs given code and test cases entirely in natural language as Chain-of-Thought (CoT) rationales, we expose them to universal reasoning primitives -- like logic flow planning, state-space searching, decision tree traversal, and modular decomposition -- while decoupling structured reasoning from code-specific syntax and preserving procedural rigor. Experimental results demonstrate CodeI/O leads to consistent improvements across symbolic, scientific, logic, math & numerical, and commonsense reasoning tasks. By matching the existing ground-truth outputs or re-executing the code with predicted inputs, we can verify each prediction and further enhance the CoTs through multi-turn revision, resulting in CodeI/O++ and achieving higher performance. Our data and models are available at https://github.com/hkust-nlp/CodeIO.