Skip to content
AI.info

Research

TikZilla: Scaling Text-to-TikZ with High-Quality Data and Reinforcement Learning

Overview Research area: Artificial intelligence for scientific figure generation — specifically, generating TikZ graphics code from natural-language descriptions using large language models. Technical

TikZilla: Scaling Text-to-TikZ with High-Quality Data and Reinforcement Learning
arXiv
2603.03072
Published
2026-03-03
Authors
Christian Greisinger, Steffen Eger

AI summary

Overview

Research area: Artificial intelligence for scientific figure generation — specifically, generating TikZ graphics code from natural-language descriptions using large language models.

Technical level: Advanced. The paper assumes familiarity with supervised fine-tuning, reinforcement learning (GRPO), and image-embedding reward models, though the core ideas are explained here in plain language.

Scope: The paper builds a much larger, cleaner Text-to-TikZ dataset (DaTikZ-V4), adds LLM-based code repair and vision-language-model descriptions, and trains small Qwen-based models (TikZilla, 3B and 8B parameters) with supervised fine-tuning followed by reinforcement learning using a domain-specific image-encoder reward model.

What This Paper Is About

TikZ is the standard way scientists draw precise, publication-ready figures in LaTeX, but writing TikZ by hand is difficult and models that translate text into TikZ often produce code that will not compile, contains irrelevant content, or gets spatial relationships wrong. The core problem is data: existing Text-to-TikZ datasets are small and their captions are too thin to reconstruct the actual figure. The paper's goal is to fix both the data and the training method, so that even small open models can generate faithful TikZ figures from descriptions.

Key Contributions

  1. Caption quality analysis. The authors had annotators examine 200 DaTikZ-V3 samples and showed quantitatively that raw scientific captions are too sparse for figure reconstruction, motivating the use of VLM-generated descriptions instead.

  2. DaTikZ-V4 dataset. A dataset of over 2M unique TikZ samples (2,000,880 total), sourced from arXiv (1,471,083), GitHub (413,178), TeX StackExchange (97,909), synthetic data (13,514) and curated data (5,196), quadrupling the scale of prior datasets. Roughly 5,500 GitHub repositories were cloned, yielding over 400,000 unique TikZ samples.

  3. Data quality pipeline. Improved rule-based filtering (including dynamic LaTeX package detection and recursive subfigure extraction), VLM-generated figure descriptions with Qwen2.5-VL-7B-Instruct over around 1.3M compilable samples, and an LLM debugging pipeline that repaired 600K of 1.3M uncompilable TikZ samples in a first pass using Qwen-32B.

  4. A domain-specific reward model and the TikZilla models. The image encoder of DeTikZify-V2 is retrained end-to-end on DaTikZ-V4 and used as the reward model for reinforcement learning. TikZilla is released as a family of small open-source Qwen models (3B and 8B) trained with SFT followed by RL.

Main Findings

  • Automatic metrics: TikZilla-3B-RL reaches 0.385 and TikZilla-8B-RL 0.384 average score (AVG), both above GPT-5 at 0.365 and GPT-4o at 0.320.
  • Comparison to TikZero-Plus-10B: TikZilla-3B-RL improves by +0.085 on CLIPScore and +0.334 on DreamSIM, achieves a 37% higher compilation rate, and needs 261 fewer average tokens.
  • Compilation rates: RL-trained models reach 95–98% compilation, up from lower baselines (TikZilla-3B at 89%, Qwen2.5-3B at 52%).
  • Human evaluation: With 9 expert annotators (6 PhD, 2 postdoc, 1 faculty) rating outputs on a 5-point Likert scale, GPT-5 scored highest on textual alignment (4.18) and tied with TikZilla-8B-RL on image evaluation (3.48 vs. 3.46). TikZilla-3B-RL scored 3.40 (text) and 3.30 (image). RL boosted both Qwen models by +0.75 and +0.67 points, while base models lagged 1.5–2 points behind. Annotator agreement was Cohen's κ = 0.814 for text and 0.794 for image.
  • Metric–human correlation: Spearman's ρ was 0.260 for CLIP, 0.307 for 1-TED, 0.586 for DreamSIM, and 0.714 for the paper's reward model, validating the domain-specific reward design.
  • Captions vs. descriptions: At inference, GPT-4o reaches 0.315 AVG with VLM descriptions versus 0.270 with raw captions; training on descriptions also beats training on captions (0.289 vs. 0.279 for Qwen2.5-3B).
  • Debugging matters: Training only on first-try compilable code yields 0.288 AVG versus 0.324 with the full LLM-debugged dataset.
  • Reward model ablations: The retrained R_Sim reward gives the strongest AVG (0.498 for TikZilla-3B-RL), ahead of DreamSIM (0.474) and CLIP image reward (0.463). Retraining DeTikZify-V2 on DaTikZ-V4 improved the reward model (0.389 vs. 0.375) and its human correlation (0.714 vs. 0.698).
  • Scaling behavior: Performance rises sharply from 6.25% to 25% of the dataset, then improves more gradually up to the full dataset.
  • Out-of-distribution results: On the SPIQA benchmark (397 test cases from test-A and test-B splits, described with GPT-4o), TikZilla-3B-RL reaches 0.193 CLIP and 0.637 DreamSIM with 97% compilation, outperforming GPT-5 (0.115 CLIP, 0.432 DreamSIM, 60% compilation).

Methodology in Plain English

The authors start by checking whether ordinary figure captions are good enough to rebuild a figure — they are not, according to annotator ratings and text-similarity metrics. So they assemble a much larger dataset of TikZ code from arXiv, GitHub, TeX StackExchange, and synthetic sources, then clean it: they standardize the code into a standalone document class, detect and include the LaTeX packages a figure needs, split subfigures, and remove code depending on external files. Because much of the code does not compile (arXiv code succeeds only 31.3% of the time), they feed the code and its error message to an LLM that tries to repair it across iterations, with Qwen3-32B recovering 49.40% of errors in one pass and 59.04% after three rounds. Every figure that compiles is then described in detail by a vision-language model.

With that data, training happens in two stages. First, supervised fine-tuning teaches the model TikZ syntax from description–code pairs. Second, reinforcement learning treats the model as a policy that generates candidate TikZ programs, renders them, and scores them. The scoring uses an image encoder taken from an inverse-graphics model (DeTikZify-V2) that was retrained on the new larger dataset; it compares ground-truth and generated figure embeddings using Earth Mover's Distance to get a semantic similarity reward between 0 and 1, plus a format reward for valid document structure. The encoder stays frozen during RL to prevent reward hacking. The RL algorithm is a variant of GRPO with token-level normalization (Dr.GRPO), decoupled clipping thresholds (ε_low = 0.2, ε_high = 0.28 from DAPO), no KL penalty (β = 0), and sampling at temperature 1.0 with top_p 0.9.

Why This Matters

This work shows that careful data construction and a semantically grounded reward signal can let small open models match far larger proprietary systems on a demanding structured-generation task, reducing reliance on costly closed models and making results reproducible.

Real-world applications:

  • Scientific writing: Researchers can draft precise TikZ figures directly from a paragraph of description, cutting the time spent hand-coding diagrams.
  • Manuscript and thesis preparation: Authors working in LaTeX can convert figure sketches or textual plans into publication-ready vector graphics.
  • Education and tutorials: Instructors can generate illustrative diagrams for lecture notes, textbooks, and problem sets from plain-language prompts.
  • Figure reproduction and accessibility: Tools that re-draw figures from captions or descriptions, for example when converting between formats or improving figure accessibility.

Industry relevance: The pipeline (large-scale code data, LLM-based repair, VLM captioning, and reward models built from inverse graphics) transfers to other structured generation tasks such as LaTeX tables, CAD, and flowcharts. The released models and datasets on Hugging Face and GitHub give practitioners an open, efficient alternative to proprietary figure-generation APIs, and the strong correlation between the paper's reward model and human ratings (ρ = 0.714) suggests a template for evaluating other visual program-generation systems.

Future Directions

  • Better descriptions: The authors note that VLM-generated descriptions can omit or hallucinate details, which may bias training and occasionally reinforce errors during reward optimization; more reliable annotation methods are needed.
  • Fine-grained rewards: More precise reward functions could address cases where descriptions diverge from the underlying figure.
  • Metrics aligned with human perception: The paper observes that CLIP (ρ = 0.260) and TED (ρ = 0.307) correlate only weakly with human scores, so better automatic metrics remain an open problem.
  • Extending to other structured domains: Applying the same recipe to LaTeX tables, CAD, or flowcharts where programmatic fidelity matters.
  • Open questions raised by the results: Why models, especially GPT-5, score higher on textual than image alignment is unresolved, as is whether explicit code-efficiency rewards would add to the natural length reduction observed under the semantic reward.

Target Audience

Researchers and engineers working on code generation, multimodal generation, and reinforcement learning from reward models; NLP groups studying scientific document processing; and practitioners who build tools for LaTeX workflows or automatic figure creation. It is also relevant to dataset builders interested in large-scale data cleaning, LLM-based code repair, and vision-language annotation pipelines.

Authors’ abstract

Large language models (LLMs) are increasingly used to assist scientists across diverse workflows. A key challenge is generating high-quality figures from textual descriptions, often represented as TikZ programs that can be rendered as scientific images. Prior research has proposed a variety of datasets and modeling approaches for this task. However, existing datasets for Text-to-TikZ are too small and noisy to capture the complexity of TikZ, causing mismatches between text and rendered figures. Moreover, prior approaches rely solely on supervised fine-tuning (SFT), which does not expose the model to the rendered semantics of the figure, often resulting in errors such as looping, irrelevant content, and incorrect spatial relations. To address these issues, we construct DaTikZ-V4, a dataset more than four times larger and substantially higher in quality than DaTikZ-V3, enriched with LLM-generated figure descriptions. Using this dataset, we train TikZilla, a family of small open-source Qwen models (3B and 8B) with a two-stage pipeline of SFT followed by reinforcement learning (RL). For RL, we leverage an image encoder trained via inverse graphics to provide semantically faithful reward signals. Extensive human evaluations with over 1,000 judgments show that TikZilla improves by 1.5-2 points over its base models on a 5-point scale, surpasses GPT-4o by 0.5 points, and matches GPT-5 in the image-based evaluation, while operating at much smaller model sizes. Code, data, and models will be made available.

Read the original paper