AutomaTikZ: Text-Guided Synthesis of Scientific Vector Graphics with TikZ

Jonas Belouadi, Anne Lauscher, Steffen Eger

Introduction

While AI models like DALL-E and Stable Diffusion excel at generating realistic photos and digital art, they struggle significantly with scientific figures. Most current text-to-image models generate raster graphics (bitmaps), which become pixelated when zoomed in and lack searchable text. Scientific communication, however, demands vector graphics—precise, scalable, and geometrically accurate diagrams.

To bridge this gap, researchers have introduced AutomaTikZ, a novel framework that enables Large Language Models (LLMs) to generate high-quality scientific vector graphics from text descriptions. By utilizing TikZ—a high-level graphics language for LaTeX—as an intermediate step, and introducing the massive DaTikZ dataset, the researchers developed models that produce more accurate and human-like figures than general-purpose giants like GPT-4.

The Challenge of Vector Graphics

Generating low-level vector code (like SVG) is incredibly difficult for AI. The code is often excessively long, repetitive, and lacks a clear semantic structure that language models can easily parse. The authors propose a "Goldilocks" solution: using TikZ. TikZ is a high-level graphics language that is human-readable and abstract enough for an LLM to understand (e.g., \draw (0,0) circle (1);), yet it compiles directly into perfect, publication-quality vector graphics.

Methodology: LLaMA and CLiMA

The researchers developed two primary models to tackle this text-to-TikZ translation:

  1. Fine-tuned LLaMA: The team took the open-source LLaMA model and trained it specifically on TikZ code paired with descriptive captions.
  2. CLiMA (CLIP inside LLaMA): This flagship model augments LLaMA with multimodal CLIP embeddings. By adding a projection layer, CLiMA can "see" visual concepts in the input, helping it better align the generated drawing with the user's textual request.
The CLiMA architecture uses CLIP embeddings to interpret captions and guide LLaMA in generating TikZ code, which is then compiled into scientific figures.

A major technical hurdle in generating code is that a single syntax error can break the entire drawing. To mitigate this, the authors introduced an iterative resampling method. If the generated TikZ code fails to compile, the model does not start over from scratch; instead, it backtracks to the last valid line and tries again, making the generation process significantly more robust and efficient.

The DaTikZ Dataset

The backbone of this framework is DaTikZ, the first large-scale dataset of its kind. It contains nearly 120,000 TikZ drawings paired with descriptive captions. The data was meticulously gathered from four main sources: curated examples from educational websites, real-world Q&A from TeX Stack Exchange, TikZ code extracted directly from ArXiv preprints, and artificial examples generated by GPT-4 to help the model learn basic geometric shapes.

Key Insights and Results

In both automatic and human evaluations, the specialized AutomaTikZ models outperformed commercial heavyweights.

  • Multimodal Grounding Matters: CLiMA outperformed text-only models because the CLIP embeddings provided a visual "anchor," helping the model understand spatial relationships that are difficult to describe in words alone.
  • Beware of "Typographic Attacks": The researchers found that general-purpose models like GPT-4 and Claude 2 often "cheat." Instead of drawing a complex concept, they might simply write the caption text inside the image. This artificially boosts their similarity scores in some automatic metrics but fails to produce a useful scientific figure.
  • Quantitative Superiority: CLiMA and LLaMA achieved significantly better scores in metrics like CrystalBLEU (code similarity) and KID (image quality) compared to GPT-4 and Claude 2.
Radar charts demonstrating that CLiMA and LLaMA (left) generally outperform GPT-4 and Claude 2 (right) across various quantitative metrics, including CrystalBLEU and KID.

In "Best-Worst Scaling" tests, human experts consistently rated CLiMA's outputs as being more similar to human-created figures and better aligned with the input captions than the commercial alternatives.

Limitations and Future Work

Despite these impressive results, there are still hurdles to clear:

  • Context Window: The models were trained with a 1200-token limit. This restricts their ability to generate extremely complex, multi-page, or highly detailed TikZ documents.
  • Low-Resource Language: Compared to mainstream programming languages like Python or Java, TikZ code is relatively rare on the internet. Better pre-training on a wider variety of TeX-related data could further boost performance.
  • Caption Quality: While data augmentation improved captions, automating scientific figure descriptions remains notoriously difficult. Future work will explore enriching these descriptions using the surrounding text from the original research papers.

Summary updated

BibTeX
@inproceedings{belouadi2024automatikz,
  author = {Jonas Belouadi and Anne Lauscher and Steffen Eger},
  title = {{AutomaTikZ: Text-Guided Synthesis of Scientific Vector Graphics with TikZ}},
  booktitle = {International Conference on Learning Representations},
  year = {2024},
  url = {https://openreview.net/forum?id=v3K5TVP8kZ},
}
Figure