NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

LayoutNUWA: Revealing the Hidden Layout Expertise of Large Language Models

Zecheng Tang, Chenfei Wu, Juntao Li, Nan Duan

Introduction

Graphic layout generation is traditionally treated as a numerical optimization problem. However, this approach often overlooks the semantic relationships between layout elements. LayoutNUWA reframes this challenge as a code generation task. By representing layouts as HTML/SVG code, the model taps into the latent design expertise of Large Language Models (LLMs) to produce visually coherent and semantically sensible layouts, achieving up to a 50% improvement over previous state-of-the-art methods.

The Problem: Semantics vs. Coordinates

Creating an effective layout for a website, magazine, or mobile app requires a deep understanding of semantics. For instance, a "Title" typically belongs at the top, "Buttons" should be grouped logically, and "Images" must not obscure "Text."

Existing models usually treat layout generation as a "numerical tuple" problem, predicting sequences of coordinates like $(x, y, w, h)$. This "semantic-lite" approach ignores the rich, logical relationships between elements that humans intuitively understand. Conversely, LLMs have been trained on millions of lines of web code (HTML/CSS), equipping them with a hidden expertise in structural information. The core challenge LayoutNUWA addresses is unlocking this expertise for automated layout design.

Methodology: Code Instruct Tuning (CIT)

To harness the power of LLMs, the authors introduce Code Instruct Tuning (CIT), a framework that treats layout generation as a code completion exercise. The pipeline consists of three interconnected modules:

LayoutNUWA Pipeline
  1. Code Initialization (CI): Instead of processing raw pixel coordinates, the model uses adaptive quantization to convert continuous numbers into discrete tokens. These are wrapped in an HTML-like template. For example, a layout element is initialized as <rect data-category="title" x="<M>" y="<M>" width="<M>" height="<M>" />, where <M> represents masked values.
  2. Code Completion (CC): This is the core of the system. Using an LLM, the model takes a natural language prompt (e.g., "I want to generate layout in document style...") and the partially masked HTML string. The LLM leverages its formatting knowledge to predict the missing coordinate and size values, completing the code.
  3. Code Rendering (CR): Because the output is standardized code, the final step simply renders the completed HTML/SVG into a visual graphic. This ensures a highly interpretable and transparent generation process.

To prevent the model from merely memorizing sequences, the authors employ a self-consistency strategy, randomly permuting the order of elements during training so the model learns spatial logic rather than a fixed list.

Evaluation and Datasets

LayoutNUWA was evaluated across three diverse benchmarks:

  • RICO: A massive dataset of over 66,000 mobile UI layouts across 25 categories.
  • PubLayNet: Over 360,000 document layouts (articles, reports) featuring 5 categories.
  • Magazine: A smaller, low-resource dataset of roughly 4,000 magazine pages, used to test the model's generalization capabilities when data is scarce.

Key Insights

  • Code as a Semantic Bridge: Code is more than a format; it carries meaning. By using tags like data-category="title", the model explicitly links an element's purpose to its position.
  • Unlocking Hidden Expertise: The paper demonstrates that LLMs inherently understand design principles. When prompted in code, they outperform specialized models built from scratch for layout tasks.
  • Absolute vs. Relative Positioning: Unlike previous models that rely on relative coordinates (which can cause rounding errors and drift), LayoutNUWA uses absolute positions, aligning perfectly with standard web rendering engines.
  • Domain-Agnostic Generalization: Training simultaneously on all datasets actually improved performance on specific tasks, suggesting the model learns universal layout logic.

Results and Performance

LayoutNUWA significantly outperformed baselines across all metrics. On the Magazine dataset, it improved the Frechet Inception Distance (FID)—a metric measuring how realistic the layouts appear—by over 50% compared to the previous state-of-the-art model (LayoutDM).

Qualitative results indicate that LayoutNUWA produces cleaner designs with better grid alignment and significantly fewer instances of accidental overlap compared to GAN or Diffusion-based models. Furthermore, even without fine-tuning, powerful models like GPT-4 exhibited a basic zero-shot understanding of the task when using the CIT framework.

Limitations and Future Work

  • Autoregressive Generation Speed: Because the model generates code token-by-token, it is naturally slower than non-autoregressive models (like certain Diffusion models) that generate entire layouts simultaneously.
  • Error Propagation: If the LLM makes a mistake early in the code generation process, that error can propagate, potentially ruining the spatial arrangement for subsequent elements.
  • Domain Confusion: In a domain-agnostic setting, the model occasionally applies mobile UI design logic to a magazine page, or vice versa. Future work may involve stronger domain constraints in the prompts to mitigate this issue.

Summary updated

BibTeX
@inproceedings{tang2024layoutnuwa,
  author = {Zecheng Tang and Chenfei Wu and Juntao Li and Nan Duan},
  title = {{LayoutNUWA: Revealing the Hidden Layout Expertise of Large Language Models}},
  booktitle = {International Conference on Learning Representations},
  year = {2024},
  url = {https://openreview.net/forum?id=qCUWVT0Ayy},
}
Figure