TL;DR
This paper introduces a quasi-self-supervised method to extract "local style awareness" maps from font images using Vision Transformers (ViTs). By training a model to identify whether two different letters belong to the same font, the network learns to focus on fine details like serifs and curvatures rather than global character shapes. Integrating these attention maps into the reconstruction loss of few-shot font generation models significantly improves the fidelity and sharpness of generated text styles.
What Problem Does This Paper Address?
When humans look at a font, we recognize its unique style by looking at fine-grained local details: the sharp edge of a serif, the thickness of a stroke, or the curvature of a corner. However, automated font generation and recognition models often struggle with these aesthetic details. They tend to over-focus on global character shapes (i.e., the structural geometry that makes an 'A' look like an 'A') or broad category boundaries (like Serif vs. Sans-Serif).
To make matters worse, capturing these fine-grained local style traits typically requires tedious, manual pixel-level annotations. This paper addresses this gap by proposing a method to automatically discover and prioritize these style-defining local regions without any manual annotation cost.
Methods
The authors propose a two-step framework: first, learning local style awareness via contrastive learning, and second, using that awareness to guide font generation.
1. Font Identification via Contrastive Learning
The core innovation lies in how the model is trained to find style. Instead of classifying a font by name or category, the model is given a pair of different characters (e.g., a serif 'A' and a sans-serif 'B') and must determine if they belong to the same font family ("Same" or "Not").
Because the input characters are structurally different, the model cannot rely on global shape matching. It is forced to look at local micro-structures—like serifs and stroke endings—to solve the task. The authors use a Vision Transformer (ViT) for this task because its patch-wise self-attention mechanism excels at capturing long-range spatial relationships (e.g., matching the top and bottom serifs of a capital 'I').
2. Extracting and Applying Local Style Awareness
Using an explainable AI technique called attention rollout, the authors extract a fine-grained spatial attention map ($W$) from the trained ViT.
This map is then used to weight the reconstruction loss function of downstream few-shot font generation models: $$L = ||(W + \alpha) \odot (X_{\text{gt}} - X_{\text{gen}})||_1$$
Here, $X_{\text{gt}}$ is the ground-truth target image, $X_{\text{gen}}$ is the generated image, $\odot$ represents element-wise multiplication, and $\alpha$ is a constant (set to 0.1) that ensures regions with low style attention still receive a baseline level of optimization.
Datasets
The authors evaluated their approach using the Google Fonts dataset:
- Filtering: They selected fonts containing the "Latin" character subset and discarded incomplete font families.
- Data Split: The final dataset consisted of 2,094 fonts for training, 230 for validation, and 249 for testing.
- Scope: To avoid the structural complexities of lowercase letters (like small caps), the experiments were restricted to the 26 capital letters.
- Preprocessing: Vector fonts (TTF) were rendered into $224 \times 224$ pixel bitmaps for the identification task and resized to $64 \times 64$ or $80 \times 80$ to match downstream font generation baselines.
Key Insights and Ideas
- The Power of Different Characters: Comparing identical letters (e.g., 'A' vs 'A') makes font identification trivial because the model can just subtract the images. Comparing different letters (e.g., 'A' vs 'B') forces the network to ignore global letter geometry and isolate pure style features.
- ViT vs. CNN (Grad-CAM): Traditional CNNs using Grad-CAM produce highly coarse, blurry attention maps that often bleed into the background. ViT's patch-based attention provides much higher spatial resolution, precisely pinpointing the contours of thin strokes and serifs.
- Task Selection Matters: Training a model on a binary "same/different" font identification task yields much tighter, more distinct style clusters in latent space than training on a standard 4-category font classifier (Serif, Sans-Serif, Handwriting, Display).
Key Results
The proposed weighted loss function was integrated into three baseline few-shot font generation models: FANnet, EMD, and Srivatsan et al.
- Quantitative Improvements: The method consistently boosted performance across metrics that are highly sensitive to local contours, such as Hausdorff distance and Pseudo Hamming Distance (PHD). For example, on the FANnet baseline:
- Hausdorff distance dropped from 7.172 to 5.602 (lower is better).
- PHD dropped from 1083 to 803 (lower is better).
- Qualitative Improvements: Visually, the weighted loss prevented common generation artifacts. It successfully preserved thin strokes from disappearing and accurately rendered sharp, distinct serifs where standard $L_1$ losses produced blurry or missing edges.
Limitations and Future Work
- Hyperparameter Sensitivity: Balancing the weight between local style features and global character structure relies heavily on tuning the constant $\alpha$. Improper tuning can cause the model to neglect overall letter legibility.
- Noise in Unimportant Regions: In characters where stroke width naturally varies but isn't a defining style trait (such as the curve of a 'J'), the attention mechanism can occasionally introduce unwanted noise or deformations.
- Future Directions: The authors plan to extend this local style awareness framework to non-Latin scripts and explore its utility in broader applications like font style transfer, style analysis, and domain adaptation.
Summary updated