cs.AIMar 9, 2026

CoCo: Code as CoT for Text-to-Image Preview and Rare Concept Generation

Authors: Haodong Li, Chunmei Qing, Huanyu Zhang, Dongzhi Jiang, Yihang Zou, Hongbo Peng, Dingming Li, Yuhong Dai, 

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

Explore similar work

CardsList
  1. IV-CoT: Implicit Visual Chain-of-Thought for Structure-Aware Text-to-Image Generation

    Jun 23, 2026Zixuan Li, Haokun Lin, Yicheng Xiao +10T2I GenerationMultimodal Large Language Models

  2. StruVis: Enhancing Reasoning-based Text-to-Image Generation via Thinking with Structured Vision

    Mar 6, 2026Yuanhuiyi Lyu, Kaiyu Lei, Ziqiao Weng +7T2I GenerationVLM Reasoning

  3. Tree-of-Thoughts Reasoning for Text-to-Image In-Context Learning

    Jul 8, 2026Stepanida Alekseeva, Jenifer Kalafatovich, Seong-Whan LeeTree of ThoughtsMultimodal ICL