Generative AI

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

HHaodong LiCChunmei QingHHuanyu ZhangDDongzhi JiangYYihang ZouHHongbo PengDDingming LiYYuhong DaiZZePeng LinJJuanxi TianYYi ZhouSSiqi DaiJJingwei Wu
Published
March 9, 2026
Authors
13
Word Count
8,745

Code-as-reasoning framework generates precise image layouts through executable code and iterative refinement.

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, which is then executed in a sandboxed environment to render a deterministic draft image. The model subsequently 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% over direct generation, while also outperforming other generation methods empowered by CoT. These results demonstrate that executable code is an effective and reliable reasoning paradigm for precise, controllable, and structured text-to-image generation. The code is available at: https://github.com/micky-li-hd/CoCo

Key Takeaways

  • 1

    CoCo uses executable code as chain-of-thought reasoning to generate precise structural layouts before refining images into final results.

  • 2

    Code-driven planning is deterministic and verifiable, solving limitations of abstract natural language descriptions for structured image generation.

  • 3

    CoCo achieves 68.83% improvement on StructT2IBench by combining code execution, draft rendering, and targeted image refinement.

Limitations

  • Existing models required specific training to reliably execute the code-to-image pipeline without errors or failures.

  • The approach's effectiveness on highly abstract or artistic prompts beyond structured visual domains remains unclear.

Keywords

Unified Multimodal ModelsChain-of-Thought reasoningtext-to-image generationexecutable codestructured draft constructionimage editingCoCo-10K datasetStructT2IBenchOneIG-BenchLongText-Bench

More in Generative AI

View all
CoCo: Code as CoT for Text-to-Image Preview and Rare Concept Generation | Paperchime