UniCoder: Unified Visual-to-Code Generation via Symbolic Rewards and Reference-Guided Code Optimization

Yaozhi Zheng, Yilei Jiang, Manyuan Zhang, Yuxuan Wan, Kaituo Feng, Tianshuo Peng, Bo Zhang, Xiangyu YuearXiv 2026

TL;DR

UniCoder is a unified reinforcement learning framework designed to master visual-to-code generation tasks, such as translating scientific plots, SVGs, and webpages into executable code. By introducing symbolic attribute rewards and a reference-injection strategy, it overcomes the traditional RL pitfalls of coarse reward signals and exploration stagnation. The resulting 8B-parameter model outperforms all open-source baselines and achieves performance competitive with top-tier proprietary models like GPT-5.

What Problem Does This Paper Address?

Translating visual designs into functional, executable code (Visual-to-Code generation) requires pixel-precise accuracy. While Multimodal Large Language Models (MLLMs) excel at high-level layouts via Supervised Fine-Tuning (SFT), they often plateau when it comes to fine-grained details, frequently hallucinating coordinates, text labels, or color codes.

Reinforcement Learning (RL) could theoretically fix this by optimizing for direct feedback, but it faces two massive roadblocks:

  1. The Reward Alignment Paradox: Global semantic metrics (like CLIP scores) are too coarse—they might give a high score to a chart that matches the color scheme but contains completely wrong data points. Conversely, pixel-level metrics (like Mean Squared Error) are too brittle, penalizing structurally perfect code over invisible rendering artifacts like font anti-aliasing.
  2. Exploration Stagnation: The search space for executable code is incredibly sparse. Early in training, models often generate code with minor syntax errors that fail to render entirely, leading to zero rewards, collapsed gradient variance, and a total "cold start" stagnation.
Figure 1: Limitations of CLIP-based visual rewards for Visual-to-Code generation. (a-b) Semantic Error Cases: Generated outputs receive high CLIP scores (0.91 and 0.94) despite containing critical errors, such as wrong axis labels and shifted data points in scientific plots, incorrect prices and product names in webpages. These examples demonstrate that CLIP captures global visual similarity but fails to enforce fine-grained element-level alignment. (c) Exploration Stagnation: Training with vanilla GRPO shows reward stagnation and high variance, indicating the model struggles to explore effectively across heterogeneous coding paradigms (Python/SVG/HTML).

Methods

UniCoder builds upon Group Relative Policy Optimization (GRPO) and introduces two novel mechanisms to solve these RL bottlenecks:

  • Symbolic Attribute Alignment: To decouple structural intent from rendering noise, UniCoder uses a lightweight auxiliary LLM (Qwen-2.5-3B) as an Attribute Extractor. This module parses the generated code into discrete symbolic attributes (e.g., hex colors, text labels, axis limits). The model is then rewarded based on the Soft Recall of these attributes against the ground truth, allowing for partial credit (e.g., getting the colors right even if the labels are wrong).
  • Reference-Guided Code Optimization (Reference Injection): To combat exploration stagnation, UniCoder monitors the rollout groups during training. If the maximum reward in a group falls below a certain threshold, the lowest-performing candidate is force-replaced with the ground-truth reference code. This acts as a "performance anchor," raising the group mean and forcing the optimizer to heavily penalize the failed exploration paths, transforming blind search into guided imitation.
Figure 2: Overview of the proposed framework. The model processes diverse visual inputs (Scientific Plots, SVGs, Webpages) to generate corresponding executable code. To ensure high-quality generation, we employ a multi-faceted reward mechanism consisting of: (1) Attribute Reward for fine-grained symbolic alignment, (2) Execution Reward to verify code compilability, and (3) Visual Reward (e.g., CLIP score) for semantic consistency. These rewards guide the Policy Update via a reference-guided group computation strategy.

Datasets

The authors curated a unified instruction-tuning dataset to foster cross-task generalization, drawing from:

  • MSRL: For Python scientific plot generation.
  • SVG-Stack: For scalable vector graphics creation.
  • Web2Code: For hierarchical webpage structures.

For evaluation, they tested the model against authoritative, domain-specific benchmarks: ChartMimic (chart-to-code), UniSVG (SVG translation), Design2Code, and ScreenBench (webpage-to-HTML synthesis).

Key Insights and Ideas

  • Decoupling Intent from Pixels: The core "aha moment" is that code shouldn't be evaluated by how its pixels render or how a vision model perceives it globally, but by the symbolic properties embedded within the code itself.
  • The Anchor Effect: Injecting a single perfect reference trajectory into a failing group of rollouts completely alters the optimization landscape. Instead of getting stuck with zero-gradient updates, the model receives a strong contrastive signal that explicitly tells it what not to repeat, stabilizing the entire training process.

Key Results

UniCoder (built on a Qwen3-VL-8B backbone) achieved state-of-the-art results across the board:

  • Open-Source Dominance: It consistently outperformed larger or similarly scaled open-source models (including InternVL3.5-8B and Qwen2.5-VL-7B) across all four benchmarks.
  • Rivaling Proprietary Models: On the Design2Code benchmark, UniCoder achieved a Block alignment score of 0.865, outperforming Gemini-3-Pro (0.852) and GPT-5 (0.855).
  • Ablation Validation: Removing the Reference Injection caused the execution rate on ChartMimic to plummet from 86.4% to 79.6%, proving its necessity for training stability. Removing the Attribute Reward led to sharp declines in fine-grained metrics like position and color accuracy.
Figure 3: Training reward curves of our method. We report four metrics: (a) Execution Rate measures the fraction of generated code that compiles and renders successfully; (b) Visual Reward captures the CLIP similarity between rendered outputs and ground truth images; (c) Attribute Reward quantifies the element-level alignment via our proposed attribute extraction mechanism; (d) Overall Reward is the weighted combination of the three components (Rtotal = w1Rexec + w2Rvis + w3Rattr). All metrics show consistent improvement throughout training, demonstrating the effectiveness of our Reference-Guided GRPO framework.

Limitations and Future Work

While highly effective, UniCoder is currently limited to static visual reconstruction. The framework does not yet account for interactive user interfaces, animations, mobile applications, or complex runtime behaviors where code correctness depends on dynamic execution. Additionally, extending UniCoder to entirely new visual domains requires manually adapting the attribute schema and prompting the auxiliary LLM to extract those new domain-specific properties.

Summary updated

BibTeX
@misc{zheng2026unicoder,
  author = {Yaozhi Zheng and Yilei Jiang and Manyuan Zhang and Yuxuan Wan and Kaituo Feng and Tianshuo Peng and Bo Zhang and Xiangyu Yue},
  title = {{UniCoder: Unified Visual-to-Code Generation via Symbolic Rewards and Reference-Guided Code Optimization}},
  year = {2026},
  eprint = {2606.31732},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2606.31732},
}
Figure