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:
- Severe Token Redundancy: A simple shape can explode into dozens of tokens, quickly exhausting the model's context window and slowing down inference.
- 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.
- 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.
- 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