fontgpt v1
A 176M-parameter decoder-only transformer that draws font glyphs as a pen walk. Each glyph outline is traced by a pen on a 1/128-em grid; the move tokens are compressed with 512 BPE merges (vocab 526). A training sequence is up to 16 glyphs of one font, each conditioned on its character, so the model learns to keep a font's style from one glyph to the next. Give it a font's first few glyphs and it continues in that font, or let it start a new one.
This is an early-decay checkpoint. The run was planned at 26,900 steps; it was cut to 6,749, with the learning rate held constant to step 4,500 and decayed linearly to zero by step 6,749.
Files
| file | what |
|---|---|
fontgpt_v1.pt |
weights, model and data configs, BPE merges and training font names (PyTorch, no optimizer state) |
fontgpt_v1_rl.pt |
the same model after RL (GRPO on rendered-shape rewards); same format, load it with --checkpoint fontgpt_v1_rl.pt |
config.json |
the model and data configs, readable |
tokenizer_merges.json |
the 512 stroke merges |
fonts.txt |
names of the training fonts, usable with --font |
generate.py |
inference: load, draw glyphs, write SVG and PNG |
code/ |
the exact training code (code/COMMIT); generate.py imports it |
metrics.jsonl |
the run's eval rows |
samples/ |
renders from generate.py |
RL-tuned weights (fontgpt_v1_rl.pt)
v1 after a short reinforcement-learning stage: GRPO with rewards computed from the rendered glyph (shape overlap with the
real letter, validity, legibility), 8 updates a round, 4.05M generated tokens, practice prompts from
Google Fonts. Use it exactly like v1: python generate.py --checkpoint fontgpt_v1_rl.pt ....
Held-out fonts (16 fonts, 1,439 glyphs; shape IoU, higher is better; same prompts for both):
| pick | v1 | v1 + RL |
|---|---|---|
| greedy (one drawing) | 0.546 | 0.587 |
| first valid of 8 | 0.555 | 0.601 |
| likeliest valid of 8 | 0.564 | 0.600 |
| consensus of 8 | 0.600 | 0.618 |
| best of 8 (ceiling) | 0.694 | 0.696 |
| greedy runaways | 11.7% | 6.0% |
| diversity among 8 | 0.416 | 0.284 |
| unseen-6 nats per glyph (lower is better) | 135.4 | 143.9 |
RL makes single drawings better and steadier, at the cost of some variety between samples.
Use
pip install torch numpy pillow pyarrow pandas
python generate.py --text "H a m b u r g e f o n s t i v" --out sample # a new font
python generate.py --text "a b c" --font "NAME" --out sample # a training font's style (fonts.txt)
python generate.py --text "a b c" --prime BANK.hand.parquet:WRITER --out sample # continue a font from 6 of its glyphs
Glyphs are space-separated characters. --temperature (default 0.6), --top_k, --greedy and --seed control sampling. It runs on CPU at about 30 s a glyph on 4 cores (more when priming), and much faster on a GPU.
Coordinates are in em units with y growing downward. The SVG and PNG fill each glyph's contours with the even-odd rule.
--prime reads glyphs from a .hand.parquet glyph bank, the training data format (columns writer, label, and the stroke points). Turning a TTF/OTF file into a bank needs the project's data pipeline, which is not included here.
Samples
A completion smoke, not evidence of quality or novelty: generate.py run end to end on CPU from the downloaded repo (seed 0, temperature 0.6), checking that every requested glyph drew ink (non-empty contours and rendered pixels). Primes never include a requested glyph.
a new font, unconditioned:
--text "H a m b u r g e f o n s t i v"a training font's style:
--text "a b c d e" --font "42dotsans|42dotSans[wght]|Bold"a font from a held-out family (never trained on), primed with 6 of its own Latin glyphs (none of them a, g or R):
--text "a g R" --prime data_gf_clean.hand.parquet:"wdxllubrifontjpn|WDXLLubrifontJPN-Regular"
Recipe
- Model: 16 layers, width 768, 12 heads (head dim 64), SwiGLU MLP, U-Net skips, attention gates, 3 value-embedding tables, 8 pen-start bands; 176.4M parameters.
- Optimizer: NorMuon for the matrices (weight decay 0.1, cautious), AdamW for the rest, XSA attention, meta-gradient 0.4.
- Batch: 262,144 padded tokens per update, about 119k real tokens or 1,510 glyphs.
- Schedule: 200 warmup steps, constant to step 4,500, linear decay to step 6,749. That is about 0.80B real tokens.
- Regularisation: dropout 0.1; the source (font identity) label is dropped 90% of the time, so the model mostly works from the glyphs it has drawn.
- Sequences: up to 16 glyphs and 2,560 tokens.
- Data: 16 source files of outline fonts, about 30k fonts and 3.56M training glyphs: Google Fonts (clean and extra glyph sets), scraped freeware fonts (DVF v2, 4 shards plus extra glyph sets), open-foundry and GitHub font pools, Fontsource, League, Velvetyne and Collletttivo.
- Design families held out in
heldout_v1.json(GF families and their clones) are never trained on. - Fonts are balanced by design group within each file (family_power 0).
- Realized sequence shares: Google Fonts 37%, DVF 38%, pools 24%, other libre 2%.
- Design families held out in
Evaluation
- unseen-6: nats per glyph to draw a glyph of a font from a held-out family after 6 of that font's glyphs. Lower is better.
- test loss: nats per token on held-out glyphs of the training fonts (up to 1,000 per source file).
| step | unseen-6 (nats / glyph) | test loss (nats / token) |
|---|---|---|
| 1,500 | 155.30 | 1.9029 |
| 3,000 | 150.86 | 1.8452 |
| 4,500 | 148.93 | 1.8110 |
| 6,000 | 140.77 | 1.6877 |
| 6,749 (final) | 135.42 (6,014 glyphs) | 1.6079 |
Trained on one GPU in about 1.5 hours of training time.
- Downloads last month
- 24


