TL;DR
MM-ReCoder is a 7B multimodal model that excels at generating Python code to replicate charts from images by learning to self-correct via execution feedback. By utilizing a novel two-stage reinforcement learning strategy with Group Relative Policy Optimization (GRPO), it overcomes the "self-correction paradox"—where standard models actually degrade already-executable code—achieving state-of-the-art performance on chart-to-code benchmarks.
What Problem Does This Paper Address?
The chart-to-code (Chart2Code) task requires a model to take a chart image and write the underlying code (e.g., using Matplotlib) to reproduce it perfectly. Most current Multimodal Large Language Models (MLLMs) are trained via Supervised Fine-Tuning (SFT) on static chart-code pairs. This means they never interact with a real code execution environment during training.
When humans write code, we use an iterative process: write, execute, look at the error or visual output, and fix it. While we can prompt standard MLLMs to perform this multi-turn self-correction, existing open-source models suffer from a strange flaw: if their first-turn code is already executable, trying to "fix" it actually makes the visual quality worse. They only show overall multi-turn gains because they fix basic syntax errors in code that initially failed to run. MM-ReCoder addresses this gap by teaching models how to genuinely improve visual fidelity through iterative execution feedback.
Methods
The authors build MM-ReCoder on top of Qwen2.5-VL-7B using a multi-stage training curriculum:
- Cold Start: The model undergoes initial SFT on a large chart-code dataset, followed by SFT on 7k high-quality, two-turn self-correction trajectories. These trajectories are curated from a massive teacher model (Qwen3-VL-235B) and filtered via rejection sampling to keep only successful corrections.
- Two-Stage Multi-Turn RL (via GRPO): To prevent the model from simply repeating its first-turn answer or gaming the rewards, the authors split reinforcement learning into two distinct stages:
- Stage 1: Shared First Turn: The model samples a single first-turn output online, and then rolls out multiple diverse second-turn candidates. Optimization is applied only to the second turn, forcing the model to explore different correction strategies based on fixed feedback.
- Stage 2: Full-Trajectory Optimization: Both turns are optimized jointly to boost overall coding capability.
- Hybrid Reward Design: They combine a rule-based reward (using hooks into Matplotlib functions to extract exact text, colors, and layout) with a model-based reward (using Qwen2.5-VL-72B to judge visual aspects like clarity, style, and data accuracy).
Datasets
- Chart2Code-160k: Used for initial single-turn SFT and generating the self-correction data.
- ChartMimic: An evaluation benchmark testing chart-to-code generation across execution rate, low-level (rule-based), and high-level (GPT-4o) scores.
- Plot2Code: A benchmark evaluating pass rate and text-matching.
- ChartX: A benchmark evaluating comprehensive chart reasoning via GPT-score.
Key Insights and Ideas
- The Self-Correction Paradox: Off-the-shelf models like Qwen3-VL-8B show a -1.03% score degradation when forced to revise code that already executed successfully. They don't know how to refine style; they only know how to fix syntax errors.
- Disentangling Turns is Crucial: If you optimize both turns from the start with standard RL, the model either learns to just copy-paste its first-turn code (if it worked) or intentionally generates terrible first-turn code to maximize the "improvement bonus" in the second turn. The "Shared First Turn" stage completely mitigates this behavior.
- Rule-Based Rewards are Blind to Layout: Relying solely on rule-based metrics (like checking if all text strings exist) allows models to pass with flying colors even if the text is completely overlapping and unreadable. Incorporating a vision-based reward model acts as a vital sanity check for visual clarity.
Key Results
- State-of-the-Art Performance: MM-ReCoder (7B) achieves a 86.5% low-level score on ChartMimic and a 63.2% text-match score on Plot2Code, outperforming models with over 30x its parameter count (such as Qwen3-VL-235B).
- True Positive Self-Correction: Unlike other models, MM-ReCoder demonstrates true positive self-correction, achieving a +0.30% improvement on already-executable code between turns.
- Multi-Turn Scaling: Multi-turn evaluation shows that performance continues to improve up to 4 turns (reaching a 97.5% execution rate and 86.5% low-level score) before diminishing returns hit.
Limitations and Future Work
- Diminishing Returns: The self-correction capability peaks around the 4th turn; by the 5th turn, the model's low-level score begins to slightly degrade (-0.12%), indicating a limit to its iterative refinement horizon.
- Training Overhead: The RL process requires a large 72B model as a visual reward judge, making the training pipeline computationally heavy (taking over 130 hours on a massive cluster setup).
- Future Directions: The authors suggest extending this multi-turn framework to more general vision-to-code tasks, such as webpage or UI generation.
Summary updated