Hierarchical SVG Tokenization: Learning Compact Visual Programs for Scalable Vector Graphics Modeling

Ximing Xing, Ziteng Xue, Zhenxi Li, Weicong Liang, Linqing Wang, Zhantao Yang, Tiankai Hang, Zijin Yin, Qinglin Lu, Chunyu Wang, Qian YuarXiv 2026

TL;DR

Autoregressive Large Language Models (LLMs) are increasingly used to generate Scalable Vector Graphics (SVG), but standard text tokenizers treat geometric code like natural language, fragmenting coordinates and bloating sequence lengths. This paper introduces HiVG, a hierarchical tokenization framework that packs drawing commands and their parameters into structurally valid "segment tokens." By treating SVGs as compact visual programs, HiVG reduces sequence lengths by over 60%, eliminates coordinate hallucinations, and achieves state-of-the-art vector graphic synthesis with a fraction of the training budget.

What Problem Does This Paper Address?

When an LLM generates an SVG, it treats the graphic as a string of executable code. However, standard subword tokenizers (like Byte-Pair Encoding) are designed for text, not geometry. They fragment continuous numerical coordinates into discrete, isolated characters—for example, tokenizing the coordinate "100" into "1", "0", and "0".

This fragmentation causes two major issues:

  1. Severe Token Redundancy: A simple shape can explode into dozens of tokens, quickly exhausting the model's context window and slowing down inference.
  2. Spatial Mismatch: The model loses track of the underlying spatial and geometric relationships between numbers, frequently leading to "hallucinated," broken, or unrenderable vector paths.

Methods

HiVG solves these issues by introducing a geometry-aware, hierarchical tokenization pipeline alongside a tailored training strategy:

  • Hierarchical SVG Tokenization: Instead of processing a flat byte stream, HiVG first breaks raw SVG strings into atomic tokens (categorized into structure, commands, coordinates, and attributes). It then uses Structure Segment Learning (SSL) to iteratively merge complete command-parameter groups (e.g., a drawing command and its exact required number of coordinate offsets) into single, composite segment tokens. This ensures that every token boundary aligns with a valid, executable geometric primitive.
Fig. 2: Comparison of SVG tokenization strategies. (a) A generic LLM tok- enizer [2,42] treats SVG as plain text and splits it into subword tokens, producing long token sequences. (b) An SVG-aware tokenizer [32,37] improves structural awareness by tokenizing SVG elements and attributes, but geometric primitives remain fragmented into many numeric coordinate tokens. (c) Our HiVG tokenizer introduces a hierarchical representation that groups drawing commands together with their associated coordi- nates into reusable segment tokens, enabling substantial sequence compression (10 → 7 →2).
  • Hierarchical Mean-Noise (HMN) Initialization: To prevent the model from having to relearn spatial awareness from scratch, new coordinate token embeddings are initialized using a continuous Gaussian-polynomial basis. This injects mathematical ordering signals and spatial priors directly into the LLM's embedding layer.
  • Curriculum Training Paradigm: The model is trained using a three-stage curriculum based on sequence complexity: Stage 1 focuses on Embedding Alignment using short sequences; Stage 2 introduces Structural Abstraction via segment tokens; and Stage 3 scales up to Global Composition using full-length, intricate SVG programs.

Datasets

The authors constructed a massive training corpus of 2.45 million unique SVG samples by merging and deduplicating three prominent open-source repositories:

  • SVGStack
  • SVGX-Dataset
  • MMSVG-Icon

They implemented a rigorous preprocessing pipeline to filter out malformed or unsafe tags, normalize canvas scales to a unified $784 \times 784$ resolution, and convert absolute coordinates into relative offsets to expose recurring geometric patterns.

Key Insights and Ideas

  • Syntax-Constrained Compression: Standard tokenizers merge characters based purely on statistical frequency, which breaks code structure. Restricting token merging strictly to valid geometric command-parameter boundaries guarantees that compressed tokens remain syntactically sound.
  • Relative Coordinates Reveal Motifs: Shifting from absolute canvas coordinates to relative offsets drastically reduces translation variance. This exposes highly repetitive geometric motifs (like specific curves, corners, and arcs) across the dataset, making structural compression highly effective.
  • Continuous Priors for Discrete Tokens: Injecting a continuous mathematical coordinate prior into a discrete embedding space bridges the gap between text-based autoregression and spatial reasoning, stabilizing early-stage model optimization.

Key Results

  • Massive Sequence Compression: HiVG compresses SVG sequence lengths by 62.7% to 63.8% (a $2.68\times$ to $2.76\times$ reduction) compared to standard raw string tokenizers.
  • High Token Efficiency: Due to this compact representation, the model achieves comparable or superior graphic quality while requiring ~2.7× fewer training tokens than baseline autoregressive models.
Fig. 1: Sequence-length compression, token-efficient scaling, and human evaluation. (a) HiVG tokenization compresses SVG sequences by 62.7%–63.8% (2.68×–2.76×). (b) HiVG reaches comparable quality with approximately 2.7× fewer training tokens. (c) HiVG achieves the best human evaluation results, scoring 4.06 in usability and winning 58.9%–70.8% in pairwise comparisons against baselines.
  • State-of-the-Art Fidelity: In Image-to-SVG reconstruction tasks, HiVG-3B achieved an SSIM of 0.896 and an LPIPS of 0.114, significantly outperforming larger specialized models like OmniSVG-8B (SSIM: 0.764, LPIPS: 0.229).
  • Human Preference: In blind evaluations conducted by professional SVG designers, HiVG scored 4.06/5.0 on code usability (editability and semantic layering) and won 58.9% to 70.8% of pairwise matchups against top-tier commercial and open-source baselines.

Limitations and Future Work

While highly effective, the current implementation of HiVG is explicitly tailored to the syntax and command structure of the SVG format. The authors note that future work will focus on extending this hierarchical tokenization philosophy to other structured graphical formats, such as 3D meshes or Computer-Aided Design (CAD) files. Additionally, they plan to explore integrating this tokenization framework directly with end-to-end differentiable rendering objectives to further boost visual fidelity.

Summary updated

BibTeX
@misc{xing2026hierarchical,
  author = {Ximing Xing and Ziteng Xue and Zhenxi Li and Weicong Liang and Linqing Wang and Zhantao Yang and Tiankai Hang and Zijin Yin and Qinglin Lu and Chunyu Wang and Qian Yu},
  title = {{Hierarchical SVG Tokenization: Learning Compact Visual Programs for Scalable Vector Graphics Modeling}},
  year = {2026},
  eprint = {2604.05072},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2604.05072},
}
Figure