CoCo: Code as CoT for Text-to-Image Preview and Rare Concept Generation
Organizations: The Chinese University of Hong Kong · South China University of Technology · Institute of Automation, Chinese Academy of Sciences · Nanyang Technological University
Abstract
Recent advancements in Unified Multimodal Models (UMMs) have significantly advanced text-to-image (T2I) generation, particularly through the integration of Chain-of-Thought (CoT) reasoning. However, existing CoT-based T2I methods largely rely on abstract natural-language planning, which lacks the precision required for complex spatial layouts, structured visual elements, and dense textual content. In this work, we propose CoCo (Code-as-CoT), a code-driven reasoning framework that represents the reasoning process as executable code, enabling explicit and verifiable intermediate planning for image generation. Given a text prompt, CoCo first generates executable code that specifies the structural layout of the scene. The code is then executed in a sandboxed environment to render a deterministic draft image. Subsequently, the model refines this draft through fine-grained image editing to produce the final high-fidelity result. To support this training paradigm, we construct CoCo-10K, a curated dataset containing structured draft-final image pairs designed to teach both structured draft construction and corrective visual refinement. Empirical evaluations on StructT2IBench, OneIG-Bench, and LongText-Bench show that CoCo achieves improvements of 68.83%, 54.8%, and 41.23%, respectively, over direct generation, while also outperforming other CoT-enhanced generation methods. These results demonstrate that executable code is an effective and reliable reasoning paradigm for precise, controllable, and structured text-to-image generation.
Figures & tables
| Model | Chart | Graph | Math | Puzzle | Science | Table | Overall |
|---|---|---|---|---|---|---|---|
| Close-resource models | |||||||
| Seedream 4.0 [ 100 ] | 35.79 | 54.08 | 63.33 | 50.89 | 62.59 | 68.94 | 47.52 |
| Nano banana [ 37 ] | 35.55 | 58.96 | 64.81 | 63.87 | 60.75 | 67.20 | 48.45 |
| GPT-Image [ 101 ] | 37.09 | 57.00 | 63.25 | 59.42 | 60.94 | 83.31 | 49.58 |
| Open-resource models | |||||||
| UniWorld-V1 [ 10 ] | 1.71 | 5.52 | 4.72 | 1.58 | 8.82 | 5.25 | 3.20 |
| Method | OneIG-Bench [ 40 ] | LongText-Bench [ 39 ] | ||||
|---|---|---|---|---|---|---|
| English | Chinese | Overall | English | Chinese | Overall | |
| Gen. Only Models | ||||||
| FLUX.1-dev [ 103 ] | 0.523 | - | - | 0.607 | 0.005 | 0.306 |
| HiDream-I1 [ 102 ] | 0.707 | 0.205 | 0.456 | 0.543 | 0.024 | 0.284 |
| Kolors 2.0 [ 106 ] | 0.427 | 0.502 | 0.465 | 0.258 | 0.329 | 0.294 |
| Unified Models | ||||||
T2I Generation
Text-to-image generation creates images from natural-language prompts using generative models, with research focused on fidelity, control, efficiency, and safety.
See all 299 papers