TL;DR
When Multimodal Large Language Models (MLLMs) fail at complex STEM problems, the culprit is usually poor visual perception rather than weak reasoning. To fix this, CodePercept introduces a "code-as-perception" paradigm, training MLLMs to translate STEM diagrams into executable Python code. By grounding visual understanding in precise code semantics, CodePercept significantly boosts MLLM performance across major STEM benchmarks.
What Problem Does This Paper Address?
Artificial intelligence has made massive strides in text-based reasoning, but solving visual problems in Science, Technology, Engineering, and Mathematics (STEM) remains a major hurdle for MLLMs. When a model fails to solve a geometry puzzle or interpret a physics chart, it has been historically difficult to diagnose why: did it fail to reason through the steps, or did it simply misperceive the image?
The authors discover that perception is the primary bottleneck. Traditional natural language captions suffer from what they call descriptive aphasia—words are simply too ambiguous to precisely capture exact coordinates, complex 3D spatial relationships, or intricate geometric structures. Furthermore, existing benchmarks evaluate perception indirectly through final problem-solving accuracy, which only checks if a model caught problem-relevant details rather than assessing its holistic visual comprehension.
Methods
To overcome the limitations of natural language, CodePercept establishes executable Python code (specifically using the matplotlib library) as a structured, deterministic medium for visual perception. If a model can write code that perfectly reconstructs an image, it proves complete visual comprehension.
The CodePercept framework consists of two main training tasks:
- Code-Grounded Caption Generation: Instead of relying on hallucination-prone text descriptions, the model uses ground-truth executable code to verify and refine natural language captions, ensuring exact counts and spatial configurations.
- STEM Image-to-Code Translation: The model is trained to directly translate a visual diagram into clean, explanatory Python code that can render the exact same image.
The training pipeline operates in two stages:
- Stage 1: Supervised Finetuning (SFT): Jointly trains the model on image-captioning and image-to-code translation tasks to align visual, linguistic, and symbolic code representations.
- Stage 2: Reinforcement Learning (RL): Uses Group Relative Policy Optimization (GRPO) to optimize code generation. It rewards the model based on code format, successful execution, code-level semantic similarity, and visual similarity of the rendered output compared to the original image.
Datasets
The authors introduced two major resources to the community:
- ICC-1M: A large-scale dataset containing over 1 million high-quality Image-Caption-Code triplets. It was built using three parallel pipelines: direct image reproduction, conceptual diversification (abstracting a scientific principle and rendering it in new visual contexts), and specialized solid geometry synthesis using parametric templates to overcome standard LLM spatial deficiencies.
- STEM2Code-Eval: A new, manually curated benchmark of 1,000 images spanning mathematics, physics, chemistry, and electrical engineering. Unlike standard benchmarks, it directly evaluates visual perception by challenging models to generate code that reproduces the input image.
Key Insights and Ideas
- Perception is the True Lever: Through a systematic scaling analysis where perception (image-to-text) and reasoning (text-to-answer) were scaled independently, the authors proved that improving a model's perception capacity consistently yields higher performance gains than scaling its reasoning capacity.
- Code as a Grounding Modality: Code acts as an ideal bridge for multimodal learning. It eliminates the ambiguity of human language by providing precise, mathematical definitions of visual primitives (lines, points, colors, shapes) that can be deterministically executed and verified.
Key Results
The authors evaluated CodePercept across six prominent STEM benchmarks (including MathVision, MathVista, and DynaMath) using a captioner-solver setup.
- Problem-Solving Boost: Integrating CodePercept-SFT models as image captioners consistently improved downstream problem-solving accuracy. For example, CodePercept-8B-S1 outperformed its base model (Qwen3-VL-8B-Instruct) by an average of 3.0%, even surpassing much larger models like Qwen2.5-VL-72B.
- Superior Image Reconstruction: On the new STEM2Code-Eval benchmark, CodePercept models achieved massive gains in code execution rates and image similarity scores. CodePercept-32B-R1 achieved an execution success rate of 95.90% and an overall average score of 65.75, nearly doubling the performance of standard baseline models.
Limitations and Future Work
Not discussed in the paper.
Summary updated