Abstract
Generating synthetic images of handwritten text in a writer-specific style is a challenging task, especially in the case of unseen styles and new words, and even more when these latter contain characters that are rarely encountered during training. While emulating a writer's style has been recently addressed by generative models, the generalization towards rare characters has been disregarded. In this work, we devise a Transformer-based model for Few-Shot styled handwritten text generation and focus on obtaining a robust and informative representation of both the text and the style. In particular, we propose a novel representation of the textual content as a sequence of dense vectors obtained from images of symbols written as standard GNU Unifont glyphs, which can be considered their visual archetypes. This strategy is more suitable for generating characters that, despite having been seen rarely during training, possibly share visual details with the frequently observed ones. As for the style, we obtain a robust representation of unseen writers' calligraphy by exploiting specific pre-training on a large synthetic dataset. Quantitative and qualitative results demonstrate the effectiveness of our proposal in generating words in unseen styles and with rare characters more faithfully than existing approaches relying on independent one-hot encodings of the characters.
Introduction
Styled Handwritten Text Generation (HTG) is the process of creating synthetic text images that mimic the unique calligraphic style of a specific writer. This technology serves critical roles in accessibility, such as creating personalized digital fonts for individuals with physical impairments, and in machine learning, where it provides high-quality data augmentation for training Handwritten Text Recognition (HTR) systems.
Despite recent progress, two major hurdles remain. First is the "Long-Tail" Problem: standard datasets are dominated by common characters, leaving capital letters, digits, and punctuation underrepresented. Traditional models treat characters as discrete "one-hot" IDs, meaning they fail to learn the stylistic nuances of rare characters. Second is Style Generalization: extracting the "essence" of a writer's hand—its slant, curvature, and stroke thickness—from a limited sample and applying it to new text is notoriously difficult.
The Core Innovation: Visual Archetypes
The primary contribution of this work is the Visual Archetypes-based Transformer (VATr). Unlike previous models that represent characters as abstract numerical IDs, VATr utilizes Visual Archetypes: 16x16 binary images of characters from the GNU Unifont.
By feeding the model images rather than IDs, VATr exploits geometric similarities between characters. For instance, the circular base of an "o" is geometrically related to the shapes found in "p," "q," or "b." This allows the model to transfer stylistic knowledge from frequently seen characters to rare ones, significantly improving the rendering of the "long-tail" of the character distribution.
Architecture and Training
The VATr framework consists of two main components: a Style Encoder and a Content-Guided Decoder.
- Style Encoder ($\mathcal{E}$): This module uses a ResNet18 backbone and a Transformer encoder to extract style features from a few reference images. To ensure robustness, the encoder is pre-trained on a massive synthetic dataset comprising over 100 million word images generated from 10,400 different fonts.
- Content-Guided Decoder ($\mathcal{D}$): This Transformer-based decoder takes the visual archetypes as queries. Through multi-head cross-attention, it "dresses" the plain archetypes in the writer's specific style, producing a final stylized image via a CNN decoder.
The model is trained using a multi-objective loss function, including adversarial loss for realism, recognition loss for legibility, and style classification loss to maintain writer identity.
Experimental Results
VATr was evaluated on the IAM dataset, the standard benchmark for handwriting research.
- Visual Quality: VATr achieved a Fréchet Inception Distance (FID) of 17.79, outperforming the previous state-of-the-art (HWT) at 19.40.
- Rare Character Performance: For characters appearing fewer than 1,000 times in training, VATr’s FID was 21.36, nearly half that of the HWT baseline (40.95).
- Zero-Shot Generation: The model demonstrated the ability to generate characters entirely absent from the training set, such as Greek letters, by simply providing the corresponding visual archetype.
- Downstream Utility: Using VATr-generated images to augment the training of an HTR model reduced the Word Error Rate (WER) on the Washington dataset from 15.9% to 13.1%.
Conclusion
VATr represents a significant step forward in styled handwriting generation by shifting from abstract character IDs to visual archetypes. This approach not only improves the quality of common text but also solves the long-standing issue of rendering rare and unseen characters. Future work will explore more complex archetypes and the extension of this method to full-page text generation.
Summary updated