Design practice · Research feature

StarVector: Generating Scalable Vector Graphics Code from Images and Text

The researchers introduce SVG-Bench, a benchmark across 10 datasets, and 3 tasks: Image-to-SVG, Text-to-SVG generation, and diagram generation.

Adapted from research by Juan A. Rodriguez, Abhay Puri, Shubham Agarwal and colleagues.

arXiv preprint revision · 2025-05-31 · Attribution & reuse
In this article
Editorial illustration of printing plates.

Authors’ overview

Scalable Vector Graphics (SVGs) are vital for modern image rendering due to their scalability and versatility. Previous SVG generation methods have focused on curve-based vectorization, lacking semantic understanding, often producing artifacts, and struggling with SVG primitives beyond path curves. To address these issues, we introduce StarVector, a multimodal large language model for SVG generation. It performs image vectorization by understanding image semantics and using SVG primitives for compact, precise outputs. Unlike traditional methods, StarVector works directly in the SVG code space, leveraging visual understanding to apply accurate SVG primitives. To train StarVector, we create SVG-Stack, a diverse dataset of 2M samples that enables generalization across vectorization tasks and precise use of primitives like ellipses, polygons, and text. We address challenges in SVG evaluation, showing that pixel-based metrics like MSE fail to capture the unique qualities of vector graphics. We introduce SVG-Bench, a benchmark across 10 datasets, and 3 tasks: Image-to-SVG, Text-to-SVG generation, and diagram generation. Using this setup, StarVector achieves state-of-the-art performance, producing more compact and semantically rich SVGs.

Introduction

Vector graphics represent an archetypal form of image representation, where visual compositions are constituted by scalable primitive shapes. For modern image rendering, Scalable Vector Graphics (SVGs) have become the standard for representing vector graphics. The SVG format provides a comprehensive set of primitives and styling options. At its core, the path represents basic curves. Combined with primitives like polygon or ellipse, SVGs define complex designs precisely.

SVG Generation Methods. Early image vectorization efforts primarily relied on traditional techniques such as segmentation and polynomial curve fitting. With advancements in deep learning, new approaches have emerged. For instance, SVG-VAE employs a class-conditional Variational Autoencoder (VAE) to predict a latent style vector and generate SVGs using an LSTM decoder. DeepSVG introduces a hierarchical VAE architecture using transformers for SVG path representation, while Im2Vec converts pixel images into latent representations that can be decoded into paths with a recurrent neural network. However, these methods are limited to basic primitives like paths, resulting in a performance gap compared to traditional image processing methods. Concurrently, BeyondPixels utilizes LLMs to predict command sequences in synthetic SVGs. These trends highlight the potential of LLM models for improved generalization in SVG generation.

Recent results in image generation using diffusion or autoregressive models and the success of text-to-image generation have inspired the research into text-conditioned SVG generation. VectorFusion leverages a strong text-to-image diffusion model to find the SVG via iterative optimization. Some work has focused on SVG editing from textual inputs. CLIPasso uses a CLIP distance loss to iteratively refine SVG from sketches. These solutions are slow due to their iterative nature. IconShop trains a BERT model for text-conditioned SVG generation of icons, but their method is restricted to using paths.

To address these gaps, we introduce SVG-Stack, a large-scale dataset for diverse SVG generation tasks from both images and text, and SVG-Bench, a unified benchmark with datasets, tasks, and metrics tailored for SVGs. Together, they provide a solid foundation for improving SVG model training and evaluation.

SVG-Stack Dataset

To address the lack of large-scale SVG datasets for training foundational SVG models, we introduce SVG-Stack, a dataset containing 2.1 million SVG samples for training, 108k for validation, and 5.7k for testing. Each SVG is paired with its corresponding raster image and descriptive text, making the dataset ideal for multi-modal learning. SVG-Stack is sourced from The Stack, a diverse collection of code samples from various software languages. Our selection builds upon the initial filtering and de-duplication processes conducted in. We perform additional filtering to ensure non-duplicate SVG samples.

Data Processing and Curation. Our data processing begins with extracting SVG samples from TheStack, followed by a comprehensive deduplication process based on filenames, SVG code, and metadata. We utilized CairoSVG for rasterization, removing samples that produced completely white images. To optimize sequence length and improve visualization, we eliminated comments and XML headers from the SVG code.

Data Augmentation. We implement several SVG-specific augmentation techniques to enhance model robustness. Rather than storing static-resolution raster images, we perform rasterization during data collation, enabling dynamic SVG transformations without significant training overhead. Our augmentation pipeline includes modifications to image resolution, rotation, translation, scaling, and color properties. We leverage open-source libraries svgpathtools and bs4 for SVG manipulation. Ablation studies demonstrate that these augmentation techniques significantly improve model performance.

Conclusions

We introduced StarVector, an MLLM that excels in Image-to-SVG and Text-to-SVG generation, delivering superior visual quality, precise line and shape rendering, and optimal SVG primitive usage compared to baselines. To train StarVector, we created SVG-Stack, a diverse dataset that enables generalization across SVG types and primitives. Additionally, we developed SVG-Bench, a unified benchmark with tasks, datasets, and targeted metrics. Our study shows that traditional metrics inadequately capture SVG quality, leading us to propose more effective alternatives.

Limitations and Future Work. StarVector is constrained by its 16k token context, which is inadequate for complex SVGs. It relies primarily on code prediction with minimal visual feedback. Additionally, generation speed is limited by the LLM. Future work may investigate integrating pixel-based signals to overcome these challenges.

Acknowledgements. We sincerely thank Ghazwa Darwiche, Christian Hudon, Fanny Rancourt, and Marie-Ève Marchand for their invaluable administrative and technical support. This work was supported by the Natural Sciences and Engineering Research Council of Canada and Mitacs. Chris Pal acknowledges the Canada CIFAR AI Chair. We also appreciate the human verifiers for their contributions to assessment and data verification.

Generating Synthetic Captions on SVG-Stack

To generate textual instructions for vector images, we process SVG-Stack images using visual captioning models. This approach provides a textual description for each image, enabling us to fine-tune our model to follow textual instructions. For this task, we leverage off-the-shelf AI captioners, specifically BLIP2 and Llava.

Through prompt engineering, we guide these models in performing the captioning task with reasonable quality. The prompt we used is shared in Prompt 8.4. After automatically captioning all SVG samples in SVG-Stack, we compute the CLIP Score for the text-image pairs generated by the two models—producing two captions per image. Using a CLIP Score threshold of 30, we filter out text captions that fall below this threshold.

Data Augmentation for SVG

We introduce several augmentation operations to SVGs to apply slight changes that help our model learn to generate more precise results — for instance, being able to capture exact colors from the image and encode them in hexadecimal code to insert it in the fill attribute of the SVG element. Applying rotations or adding noise to the curve’s control points helps the model learn to precisely capture the position of the edges or thickness of the stroke.

We perform random rotations in an angle range. We perform color changes by first parsing the element’s color using the fill attribute and adding slight white Gaussian noise to the RGB values. We propose curve noise by injecting a small Perlin noise into the control points in Bézier curves. We also experimented with adding Gaussian noise, which resulted in much less natural results. We apply this noise by uniformly sampling a scalar from the interval between 0.01 and 0.05 and use it to scale the noise.

Context Length Limitation

The model’s architecture imposes a clear limitation on context length, which significantly impacts training and testing data pipelines, as well as the skills the model can learn. Our experiments show that the model scales effectively with increasing context lengths, from 8k to 16k, indicating that this limitation must be addressed with techniques for handling longer contexts—an area LLMs are expected to improve. For fair comparisons, we restricted our benchmark tests to a context length of 8k and evaluated all baselines within this setting. However, the benchmarks also provide versions with longer context lengths to assess future models, as increased length generally correlates with more complex SVGs. We did not observe substantial differences in scores between the 4k and 10k token settings, primarily because the data in our benchmark can typically be represented using an average of 3k tokens.

Limitations on Complex SVG Structures

StarVector encounters challenges with complex SVG structures, intricate shapes, and detailed illustrations primarily due to limitations in its architecture. Currently, the model’s image encoder handles images by simply padding and resizing them to fixed dimensions of 224 or 384 pixels. This approach may not adequately capture the nuances of complex diagrams. A potential improvement would be to implement a dynamic image processing system akin to those found in newer Vision-Language Models (VLMs), which could enhance the model’s ability to interpret and generate intricate SVGs more effectively. Additionally, improving data cleaning processes is crucial, as the model sometimes produces hallucinated information due to noise in the input data, such as URLs or base64-encoded images. Addressing these issues through architectural enhancements and more robust data preprocessing could significantly improve StarVector’s performance on complex SVG tasks.

Generalization to Non-Standard SVGs

StarVector’s ability to generalize to non-standard SVGs—those not represented in its main training distribution—poses a significant challenge. While the model performs well on common styles and primitives encountered during training, it struggles with more unique or unconventional SVGs. This is primarily due to the model’s training data, which tends to focus on widely used shapes and designs. As a result, StarVector may exhibit a bias towards these common styles, leading to suboptimal performance when faced with SVGs that feature unusual structures or less frequent elements.

To assess StarVector’s generalization capabilities, we evaluated its performance on various datasets that include non-standard SVGs. The results indicate that while the model can produce reasonable outputs for some non-standard examples, it often falls short in accurately capturing the intricacies of less familiar styles. This limitation suggests that the model’s training set lacks sufficient diversity to encompass the full range of potential SVG designs.

To address these concerns, future work should focus on expanding the training dataset to include a wider variety of SVG styles and structures. Incorporating data from niche applications and artistic domains could enhance the model’s ability to generate SVGs across a broader spectrum of design elements. Additionally, techniques such as domain adaptation and transfer learning could be explored to improve generalization to non-standard SVGs, allowing StarVector to adapt more effectively to unfamiliar inputs.

Analysis of SVG Primitives

This section examines how StarVector leverages SVG primitives to produce more compact and semantically accurate SVGs. In contrast to prior models constrained to using only path primitives, StarVector effectively utilizes the entire range of SVG primitives, including parametrically defined shapes, gradients, and text elements.

This enhanced capability stems from its ability to operate directly within the SVG code space, facilitated by its multimodal, transformer-based architecture, which integrates visual and textual inputs. StarVector generates SVG code that closely resembles the input raster image while maintaining semantic awareness, enabling the use of symmetry, parametric shapes, and text. Prior methods, limited to first-order path primitives, lack this semantic understanding, resulting in less compact and less expressive SVG representations.

Human Evaluation

Spearman correlation analyses between model metrics and human evaluations further emphasize this gap. MSE shows weak correlations (0.0596 and -0.1002), indicating its inadequacy as a predictor of human preferences. In contrast, DinoScore exhibits significantly stronger correlations, with values of -0.6193 and 0.6214. Moreover, a robust correlation of 0.7577 between differences in DinoScore and human evaluation scores highlights DinoScore as a more reliable metric for assessing SVG quality in alignment with human judgment.

Large Language Model

We consider several aspects when choosing the LLM to handle the SVG code generation. First, we require an LLM that can handle large token contexts during training, as SVG code samples are typically of long lengths (i.e., between 1,000-4,000 tokens for the most common SVG datasets but growing arbitrarily for much more complex vector graphics). Second, we need fast decoding during the generation of these large contexts. Finally, we would benefit from models that have been extensively pre-trained on general coding tasks to avoid early training costs.

We empirically find the StarCoder family to be the most suitable choice for our requirements. StarCoder offers a pre-trained model with 1B parameters (starcoderbase-1b) and a context length of 8k tokens, making it ideal for smaller-scale experiments while maintaining efficient generation speeds. The model employs Multi-Query Attention and a Fill-in-the-Middle objective, trained on 1 trillion tokens, with a context window of 8192 tokens. Its compact size ensures compatibility with GPUs, facilitating data parallelism during training—a crucial benefit when fine-tuning all network parameters, including the memory-intensive image encoder.

The second generation, StarCoder2, extends the context length to 16,384 tokens, presenting an exciting avenue for exploring training on SVGs with longer context requirements. For this, we leverage the 7B parameter version (starcoder2-7b), which incorporates a sliding window attention mechanism of 4,096 tokens and was trained on over 3.5 trillion tokens of code using the same Fill-in-the-Middle objective. This enhanced context capacity and training scale make it a promising candidate for scaling SVG-based experiments.

Image Encoder

Note that the image encoder is used exclusively for the Image-to-SVG task and is not employed during the Text-to-SVG task. For Image-to-SVG, images must be projected into a representation with the same dimensionality as that of the LLM. We train the model to enable the LLM to ingest these representations and generate SVG code sequentially.

We explore several image encoders based on different paradigms. VQGAN is based on learning to project images to discrete tokens. First, we fine-tune an Imagenet -pretrained VQGAN on the SVG-Stack dataset with the VQ-adversarial reconstruction task. We find that using the features before the quantization yields better results. ConvNext is a convolutional backbone, which we extract features before pooling. We start from a LAION-2B -pretrained checkpoint. Finally, ViT CLIP is based on the Visual Transformer (ViT) and is well prepared for autoregressive tasks. We extract all output representations. We use a LAION-2B pre-trained model. During the training of StarVector, all the parameters of the image encoders are updated. We find that the best choice is using CLIP. We consider that the gains in performance come from CLIP using more visual tokens (257) than the other image encoders.

Additional results comparing image encoders can be found in Figures 19 and 22. These results show the boost in precision obtained when using CLIP. VGQAN and ConvNext often fail to capture the image’s shape and the path’s trajectory. We note that ConvNext performs better than VQGAN. These differences are also due to the differences in the number of parameters. The CLIP ViT-L/14 model that we use consists of 290M parameters, VQGAN consists of 29M, and ConvNext consists of 179M parameters.

Training

This task enables the model to learn the concept of drawing with SVG vectors that resemble the input image. Importantly, this training can occur without supervision in the image domain (i.e., without pixel loss), relying solely on categorical cross-entropy loss for the LLM vocabulary introduced by the next-token prediction task.

In the second stage, we fine-tune the checkpoint from the first stage, which has learned SVG syntax through the Image-to-SVG task, on the Text-to-SVG task. During this phase, the image encoder is disregarded, as it becomes a Text-to-text task where the text instructions and SVG codes can be tokenized and processed directly by the LLM.

Training Details. We trained StarVector-1B on 1 node of 8 A100 80GB GPUs using Accelerate with DeepSpeed stage 2 and StarVector-8B on 8 nodes of 8 H100 80GB GPUs with Fully Shared Data Parallel (FSDP). For Image-to-SVG, we used total batch sizes of 128 and 512 for StarVector-1B and -8B, respectively, a learning rate of 1e-5, and the AdamW optimizer. To optimize memory and computation, we employed bf16 precision, FlashAttention2, and gradient checkpointing. StarVector-1B took 7 days to train, while StarVector-8B took 10 days, with both models completing 2 epochs.

Generation

Here, we describe how to sample SVG code from our model. As a decoder-only LLM, StarVector first computes the key-value (KV) cache using the visual tokens from the image and then produces the initial set of output logits. This stage is often quick because the model can process the entire visual token sequence simultaneously. The selected token from the output logits is then input back into the model, which generates logits for the subsequent token. This process is iteratively repeated until the model produces the desired quantity of tokens. Our approach uses architectural improvements for fast decoding, such as FlashAttention and Multi-Query Attention. We leverage vLLM to improve inference speed.

We perform a grid search on SVG-Emoji and SVG-Icons validation sets to select the correct sampling temperature. The choice of temperature does not strongly impact the results. However, a 1-point increase in performance is observed on CD for SVG-Emoji using temperatures close to 1.0.

Are the SVGs valid and compilable? A common issue when generating SVGs with our approach is that the maximum token length of the LLM might not be sufficient to complete the SVG code, leading to compilation errors. We find that 85% of the generated SVG fit within the context length and compile successfully. The remaining incomplete samples are post-processed with cairosvg to produce a complete and compilable SVG. However, in some cases, parts of the image may be lost during this process. With this technique, 100% of the generated SVGs are valid and compilable.