CoCo: Code as CoT for Text-to-Image Preview and Rare Concept Generation
Abstract
Recent advancements in Unified Multimodal Models (UMMs)have significantly advanced text-to-image (T2I) generation, particularlythrough the integration of Chain-of-Thought (CoT) reasoning. How-ever, existing CoT-based T2I methods largely rely on abstract natural-language planning, which lacks the precision required for complex spa-tial layouts, structured visual elements, and dense textual content. In thiswork, we propose CoCo (Code-as-CoT), a code-driven reasoning frame-work that represents the reasoning process as executable code, enablingexplicit and verifiable intermediate planning for image generation. Givena text prompt, CoCo first generates executable code that specifies thestructural layout of the scene, which is then executed in a sandboxed en-vironment to render a deterministic draft image. The model subsequentlyrefines this draft through fine-grained image editing to produce the fi-nal high-fidelity result. To support this training paradigm, we constructCoCo-10K, a curated dataset containing structured draft–final imagepairs designed to teach both structured draft construction and correc-tive visual refinement. Empirical evaluations on StructT2IBench, OneIG-Bench, and LongText-Bench show that CoCo achieves improvements of+68.83%, +54.8%, and +41.23% over direct generation, while also out-performing other generation methods empowered by CoT. These resultsdemonstrate that executable code is an effective and reliable reasoningparadigm for precise, controllable, and structured text-to-image genera-tion. The code is available at: https://github.com/micky-li-hd/CoCo