Self-Evolving Code-with-Image Reasoning
This paper introduces "Code-with-Image," a training-free self-evolving framework where multimodal models implement visual algorithms in code to solve complex pixel-level tasks, using an executable reflection loop to iteratively refine their reasoning skills and achieve significant performance gains on the CwI-Bench.
Original paper licensed under CC BY 4.0 (http://creativecommons.org/licenses/by/4.0/). This is an AI-generated explanation of the paper below. It is not written or endorsed by the authors. For technical accuracy, refer to the original paper. Read full disclaimer
The Detective's Dilemma: When Seeing Isn't Enough
Imagine you are a detective trying to solve a mystery, but instead of looking at clues, you are staring at a single, high-resolution photograph. In the world of artificial intelligence, this is what "multimodal models" do: they look at images and try to answer questions about them. For a long time, these AI detectives have gotten better by learning to use "tools." If a clue is too small to see, they learn to zoom in. If a text is blurry, they learn to brighten the image. This is called "thinking with images." It's like giving the detective a magnifying glass and a flashlight.
However, there is a catch. Some mysteries aren't solved just by looking harder. Imagine a puzzle where you have to count exactly how many pixels are in a specific pattern, or figure out the precise angle a hidden ring was rotated by. No amount of zooming or brightening will help you "see" the answer with your eyes. You have to calculate it. This is where the old way of thinking hits a wall. The AI can describe the steps to solve the puzzle in words, but words can't do math on a picture. This paper steps into that gap, asking a simple but profound question: What if the AI didn't just describe the solution, but actually wrote a computer program to run the solution?
The Paper's Big Idea: Coding as Thinking
This paper introduces a new way for AI to solve visual puzzles called Code-with-Image. Instead of asking the AI to just "look" at an image and guess the answer, or to use a pre-made list of tools like "crop" or "rotate," the researchers give the AI a blank canvas and a Python interpreter (a tool that runs computer code). The AI's job is to write a program that manipulates the pixels of the image directly to find the answer.
Think of it like this: In the old way, if you asked an AI, "How many red dots are in this picture?", it might try to describe the dots or use a tool to highlight them. In Code-with-Image, the AI has to write a script that says, "Go through every pixel, check if it's red, count it, and print the total." The program is the reasoning. If the code is right, the answer is right. If the code is wrong, the answer is wrong. This shifts the challenge from "seeing" the answer to "building" the answer.
The Problem: AI Can Describe, But Can't Do
The researchers found that even the smartest AI models struggle with this. They tested a massive benchmark called CwI-Bench (Code-with-Image Bench), which contains 30 different types of visual puzzles. These puzzles are designed so that you can't just "look" at them to get the answer; you have to do a multi-step calculation on the pixels.
When the AI tried to solve these puzzles using only words (even with its "thinking" mode turned on), it failed miserably. For example, the top-tier model, GPT-5.6-luna, got less than 30% of the answers right. It could describe the steps perfectly ("I need to rotate the image and count the pixels"), but it couldn't actually do the math. It was like a chef who could describe a recipe in perfect detail but couldn't actually cook the meal.
However, when the researchers gave the AI a Python interpreter and told it to write code to solve the problem, the scores jumped. GPT-5.6-luna's accuracy rose to 43%. The open-source model Qwen3.5-27B went from 12.6% to 32.6%. The code allowed the AI to actually process the image data, turning a guessing game into a calculation.
The Secret Sauce: Teaching Itself to Debug
But here's the kicker: even with the ability to write code, the AI still made mistakes. It would write a program that looked correct but had a tiny, invisible error—like counting one extra pixel or using the wrong number for a rotation. The AI would run the code, get the wrong answer, and then just try to write a new program, often making the same mistake again.
To fix this, the authors created a "self-evolving" loop called Self-Reflection over Executable Reasoning. This is the most playful part of the story. Imagine the AI is a student taking a test. When it gets a question wrong, instead of just moving on, it is forced to:
- Look at its failed test: Read the code it wrote and the wrong answer it got.
- Run a simulation: Re-run the code in a safe "sandbox" to see exactly where it broke.
- Fix the bug: Edit the code to correct the mistake.
- Save the lesson: If the fix works, it saves the corrected code as a "skill" (a piece of text) in a library.
This happens without the AI needing to be retrained or having its brain rewired. It just learns from its own failures. The paper shows that this "self-teaching" loop is incredibly powerful.
- For the GPT-5.6-luna model, using these self-evolved skills boosted its accuracy from 43% to 67%.
- For the Qwen3.5-27B model, it jumped from 32.6% to 55.9%.
Why This Matters: Skills You Can Copy and Paste
One of the coolest findings is that these "skills" are just plain text. They aren't locked inside the AI's brain. The researchers showed that they could take the skills learned by a huge, powerful model (like the 27-billion-parameter model) and paste them into a much smaller, weaker model (a 9-billion-parameter model).
The smaller model, which couldn't solve the problems on its own, suddenly got much better just by reading the "reference guide" written by the bigger model.
- The 9B model went from 11.1% accuracy to 34.5% just by using the skills evolved by the 27B model.
- Even more surprisingly, these skills worked across different types of AI models. A skill learned by one family of models helped a completely different family of models improve.
What This Paper Rules Out
The paper is very clear about what doesn't work. It argues that simply giving an AI a list of tools (like "zoom," "crop," or "search") isn't enough for these specific types of problems. The AI needs to write its own algorithm from scratch. It also shows that just "thinking" harder in words doesn't help; the bottleneck isn't a lack of ideas, but a lack of execution. The AI can describe the algorithm, but without running the code, it can't solve the puzzle.
The Bottom Line
This paper suggests that for visual problems that require precise calculation, the best way for an AI to think is to write code. But the real breakthrough is that these AI models can teach themselves to get better at writing that code by debugging their own mistakes. They don't need a human teacher to fix their code; they just need a sandbox to run it, a mirror to see where they failed, and a little bit of patience to try again.
The results are measured and specific: on a benchmark of 30 task families, self-evolved skills lifted the performance of top models from the low 40s to the high 60s (percent accuracy). While the paper doesn't claim this solves every visual problem, it proves that for tasks where the answer lies in the pixels' math rather than the eye's inspection, coding is the key, and self-reflection is the master key.
Drowning in papers in your field?
Get daily digests of the most novel papers matching your research keywords — with technical summaries, in your language.