Table of Contents
Fetching ...

From Tokens to Numbers: Continuous Number Modeling for SVG Generation

Michael Ogezi, Martin Bell, Freda Shi, Ethan Smith

TL;DR

This work tackles the inefficiency of tokenizing continuous SVG coordinates by introducing Continuous Number Modeling (CNM), which treats numerical attributes as first-class continuous values embedded via Fourier features. The model learns two parallel tasks—structural token prediction and numerical attribute regression—via a joint objective and uses a Number Encoder/Decoder to bridge between discrete SVG syntax and continuous geometry. After supervised fine-tuning, CNM is refined with reinforcement learning using a composite perceptual reward, yielding improvements in SSIM, DINOv2 similarity, and LPIPS' while significantly reducing sequence length and training time. On SVG-Stack, CNM achieves higher perceptual fidelity with a 32% training speedup and introduces SVGFloat as an efficient binary-friendly storage format, demonstrating practical benefits for scalable, high-quality vector generation.

Abstract

For certain image generation tasks, vector graphics such as Scalable Vector Graphics (SVGs) offer clear benefits such as increased flexibility, size efficiency, and editing ease, but remain less explored than raster-based approaches. A core challenge is that the numerical, geometric parameters, which make up a large proportion of SVGs, are inefficiently encoded as long sequences of tokens. This slows training, reduces accuracy, and hurts generalization. To address these problems, we propose Continuous Number Modeling (CNM), an approach that directly models numbers as first-class, continuous values rather than discrete tokens. This formulation restores the mathematical elegance of the representation by aligning the model's inputs with the data's continuous nature, removing discretization artifacts introduced by token-based encoding. We then train a multimodal transformer on 2 million raster-to-SVG samples, followed by fine-tuning via reinforcement learning using perceptual feedback to further improve visual quality. Our approach improves training speed by over 30% while maintaining higher perceptual fidelity compared to alternative approaches. This work establishes CNM as a practical and efficient approach for high-quality vector generation, with potential for broader applications. We make our code available http://github.com/mikeogezi/CNM.

From Tokens to Numbers: Continuous Number Modeling for SVG Generation

TL;DR

This work tackles the inefficiency of tokenizing continuous SVG coordinates by introducing Continuous Number Modeling (CNM), which treats numerical attributes as first-class continuous values embedded via Fourier features. The model learns two parallel tasks—structural token prediction and numerical attribute regression—via a joint objective and uses a Number Encoder/Decoder to bridge between discrete SVG syntax and continuous geometry. After supervised fine-tuning, CNM is refined with reinforcement learning using a composite perceptual reward, yielding improvements in SSIM, DINOv2 similarity, and LPIPS' while significantly reducing sequence length and training time. On SVG-Stack, CNM achieves higher perceptual fidelity with a 32% training speedup and introduces SVGFloat as an efficient binary-friendly storage format, demonstrating practical benefits for scalable, high-quality vector generation.

Abstract

For certain image generation tasks, vector graphics such as Scalable Vector Graphics (SVGs) offer clear benefits such as increased flexibility, size efficiency, and editing ease, but remain less explored than raster-based approaches. A core challenge is that the numerical, geometric parameters, which make up a large proportion of SVGs, are inefficiently encoded as long sequences of tokens. This slows training, reduces accuracy, and hurts generalization. To address these problems, we propose Continuous Number Modeling (CNM), an approach that directly models numbers as first-class, continuous values rather than discrete tokens. This formulation restores the mathematical elegance of the representation by aligning the model's inputs with the data's continuous nature, removing discretization artifacts introduced by token-based encoding. We then train a multimodal transformer on 2 million raster-to-SVG samples, followed by fine-tuning via reinforcement learning using perceptual feedback to further improve visual quality. Our approach improves training speed by over 30% while maintaining higher perceptual fidelity compared to alternative approaches. This work establishes CNM as a practical and efficient approach for high-quality vector generation, with potential for broader applications. We make our code available http://github.com/mikeogezi/CNM.
Paper Structure (44 sections, 14 equations, 7 figures, 5 tables)

This paper contains 44 sections, 14 equations, 7 figures, 5 tables.

Figures (7)

  • Figure 1: The training architecture for CNM: We train on raster-SVG pairs. The SVG path is split into two sequences: a token sequence with [NUM] placeholders and a float sequence. Both sequences are embedded and fused, but maintain two distinct losses mediated by $\lambda$: cross-entropy for the tokens and MSE for the floats. Detailed expansions of the Number Encoder (Figure \ref{['fig:number_encoder']} in Appendices) and Number Decoder (Figure \ref{['fig:number_decoder']} in Appendices) are provided.
  • Figure 2: The inference architecture for CNM: A raster image is provided as input, and we generate [NUM] and normal tokens. When a [NUM] is encountered, we decode its last hidden state to a scalar value and add it to a float buffer. This value is re-embedded for the next step. At the end of the generation, we consolidate the normal tokens and the float values to produce a final SVG.
  • Figure 3: Byte-level comparison of standard SVG vs. SVGFloat. In standard SVG, all content is ASCII (1 byte per character). In SVGFloat, structural syntax remains ASCII, but numeric values are stored as raw binary floats (4 bytes for float32, 2 bytes for float16 or bfloat16). Bracketed segments [bin] indicate binary-encoded floats with fixed byte size regardless of decimal precision. Note: In SVGFloat, separators between consecutive numbers are omitted; the fixed byte width disambiguates boundaries.
  • Figure 4: Qualitative comparison on the SVG-Stack test set. The figure contrasts our model (SFT + RL) with training-based baselines (StarVector, OmniSVG) . The ground-truth example contains thin strokes and small spatial offsets that require precise geometric prediction. Baselines either omit or distort these elements, whereas our method preserves stroke geometry and layout without over-smoothing. We provide more qualitative samples in Appendix \ref{['app:qualitative']}.
  • Figure 5: The Number Encoder architecture: The encoder takes a raw number $n_i$, normalizes it to $v_i$, noises it to $\tilde{v}_i$ (if in training mode), applies the Fourier Feature Mapping with $\gamma(.)$, and projects to the transformer's input embedding space via the MLP with $g_\phi(.)$. The Number Encoder, in context, can be found in Figure \ref{['fig:training']}, for training, and Figure \ref{['fig:inference']}, for inference.
  • ...and 2 more figures