PenGPT: A Generative Transformer for Handwriting and Sketches

PenGPT is a pair of small transformers that write and draw in pen strokes: a 6M-parameter model that produces print and cursive handwriting and can adopt the hand of a writer it has never seen from a few of their words, and a 54M-parameter model that draws sketches from a typed text prompt. Its author, Sam Greydanus, describes the project as his first that follows the Bitter Lesson, with roughly 80% of the effort going into data, 15% into training speed, and 5% into architecture.

The project is a follow-up to a 2025 cursive transformer that Greydanus built with Zach Wimpee, which learned only one hand (his own) from 3,500 trackpad-written words. PenGPT asks whether one ordinary transformer can hold a pen in many hands and draw as well as write.

How PenGPT represents handwriting and sketches as tokens

PenGPT uses one tokenizer for both handwriting and drawings, and the modality-specific part of the system is only ten symbols plus a byte-pair-encoding merge count. Pen points snap to a grid, so a word becomes a walk in eight directions plus pen-down and pen-up. Byte-pair encoding then merges common runs of moves into tokens: the word "world" goes from 156 raw moves to 47 tokens, and sequences end up 3.2x shorter.

Everything after the tokenizer is a plain decoder that cross-attends to its conditioning input. For handwriting the model is told the text to write; for drawings it is told a SigLIP 2 vector, so a typed phrase can stand in for a picture.

The datasets behind PenGPT

PenGPT's handwriting data contains 495,590 words by 1,255 writers, and its drawing data contains 477,670 sketches from ten public datasets. Almost nobody records pen strokes, so Greydanus built the handwriting corpus from scans, mostly from two research collections plus old letters and diaries from public archives. A vision-language model finds legible pages and transcribes them, the pages are cut into words, InkSight traces each word back into strokes, and a set of checks discards bad traces. Between a third and a half of the words survive this pipeline.

For drawings, the source pool included Quick, Draw!, which has 50 million sketches; PenGPT kept the best 0.5% of it. The datasets themselves are not being released, but the paper's appendix explains how to build them.

Training setup and speed

The handwriting model trains in about 8 minutes and the sketch model in about 35 minutes on an 8-GPU node. The blog post describes the node as 8xA100; in the Hacker News comments, the author writes that he trained the models on an 8xH100. Either way, the comparison the author draws is with his previous Cursive Transformer, which took upwards of 10 hours on a single A100 and only ever learned one hand.

What the ablation tables show

PenGPT's results are reported as nats per pen move on held-out data (lower is better), a style rank measuring how well the model identifies whose hand it is continuing (1 is perfect, 8.5 is chance), and an OCR legibility rate. Base rows vary by about 0.001 between seeds. Rows above the line in each table compare PenGPT against other approaches; rows below the line each change one thing about PenGPT.

Handwriting results

Handwriting Score change Style rank Legible
Graves-style LSTM, same tokens +0.029 2.2 49%
ScribeTokens BPE, 60x the vocabulary −0.001 1.9 53%
PenGPT 0.716 1.9 54%
A tenth of the data +0.050 3.0 47%
No augmentation +0.028 2.0 52%
One word per sequence +0.009 6.0 52%
No pen position +0.001 1.9 52%
No BPE merges −0.010 – 55%
Twice the parameters −0.004 1.9 55%
Real ink 66%

Drawing results

Drawings Score change Matches label Matches caption
sketch-rnn-style LSTM, same tokens +0.049 40% 20%
Trained on Quick, Draw! only +0.002 74% 37%
PenGPT 0.591 76% 43%
No augmentation +0.013 4% 6%
No pen position +0.008 74% 40%
Half the layers, half the width +0.022 62% 31%

Data and conditioning dominate the results

Cutting the data degrades every metric, and dropping augmentation makes the drawing model stop following its prompts entirely — matching captions falls from 43% to 6%. Training on one word per sequence destroys the model's ability to pick up a hand, moving style rank from 1.9 to 6.0.

The architectural ideas barely register

Telling the model where its pen is does almost nothing for handwriting (+0.001). The BPE merges the author was proud of make the score slightly worse (−0.010) and buy only speed. A vocabulary sixty times larger changes nothing (−0.001), and doubling the model's parameters changes nothing (−0.004). An LSTM on the same tokens is a bit behind on handwriting and still picks up new hands, though on drawings, where sequences are several times longer, it falls well behind.

How PenGPT picks up a new hand from a few words

PenGPT's few-shot style adaptation requires no style encoder and no fine-tuning: each training sequence holds up to four words by one writer, which teaches the model that later words look like earlier ones. At sampling time, you hand it a few real words and it continues in that hand. This is how the 21 held-out writers shown at the top of the post were generated — the model read one to three real words by each writer and carried on.

The same trick works from a photograph. Because a photo contains no strokes, the pipeline traces a few of its words with InkSight and fits one new writer vector to those traces with the rest of the model frozen. The post demonstrates this on a letter by the poet Sara Teasdale and on a paragraph someone printed on a NIST form in 1989.

What the cross-attention heads read

One attention head in layer 4 puts 81% of its attention on the letter currently being written, and silencing that head costs more than silencing any other. A few heads in layers 3 to 5 lock onto a single position — this letter, the next letter, or both. The "this letter" head steps through words such as "letter" and "toward" as the pen writes them; the letter t is read twice, once for the stem and again for the cross, and in cursive the cross does not come until the word is finished. Greydanus looked for heads that specialize in cursive or print and found none: every head reads the same positions in both.

Why the drawing model needs captions, not just image vectors

Captions are the expensive part of the drawing data, and PenGPT shows you cannot replace them with image vectors alone. A model trained on SigLIP picture vectors only achieves the best likelihood of the three variants tested and still draws scribbles. The reason is geometric: SigLIP's vectors for sketches sit in a narrow cone that is nearly at right angles to its vectors for text, so a model that has only seen the cone is lost when handed a sentence. Labels are enough to draw labels (78% match), but only captions get you phrases (43% against 10%).

What PenGPT cannot do

The drawing model blends concepts but does not bind them. A teapot with a face is fine, but who wears the hat is not, and "facing left" produces the same drawing as "facing right" because the single conditioning vector behaves close to a bag of words — those two captions have a cosine similarity of 0.999. Sampled handwriting is less legible than real ink, 54% against 66%. And because most of the handwriting data was traced from scans, its stroke order is a model's guess rather than a record of how a human actually wrote.

The drawing model can produce some things it was never shown, as long as a blend of two familiar ideas will do: a face or legs on an object, wheels and wings, hats and ears, and one thing shaped like another. None of those outputs depends on word order. The model also exposes a control for how much ink to use — as more ink is requested, a house gains a door, then windows, then a chimney, and a racket's strings turn into a cross-hatch, until at the far right the model runs out of parts to add and starts going over its own lines.

The Bitter Lesson framing

Greydanus frames PenGPT as his first project that follows Rich Sutton's Bitter Lesson, and he is explicit that the results came from data rather than clever architecture. In his own words:

The results are interesting and the project was a pleasure to work on. And yet there was no clever architectural idea behind it. About 80% of my effort went into building the biggest, cleanest datasets possible and doing lots of quality control on them. Another 15% went into finding a decent 8xA100 node and getting my models to train fast and in parallel on it.

He adds that the tokenizer he used here is much simpler and far less elegant than his previous one, but that it just works, and that the Bitter Lesson "is like gravity: it constrains you and most of the time it's a very bad idea to fight back." As a physicist he says he is fascinated by the emerging science of scaling laws, and as a lover of biology he likes the idea of putting a ton of work into data and then "literally growing a model on it, as you would an organism."

What the Hacker News discussion added

Commenters largely focused on the data-over-architecture message and on practical uses of the model.

On the Bitter Lesson, commenter keyle wrote that the most interesting part was the author's admission that no clever architectural idea was behind the project, adding:

I spend way too much time on trying to out-clever existing solutions, when a clean application of known approaches would serve best.

The author replied in the thread that his own demonstration is modest, and credited tooling for making the data work tractable:

Given that I only trained these on an 8xH100 it's not exactly the most spectacular illustration of the Bitter Lesson. All I can say is that historically I always wanted to impress people with better model architectures or training techniques. This time I just put all my energy into data. Agentic workflows + good open weight vision models + cheap multimodal AI APIs make data quality filtering / caption generation really smooth

Several commenters described intended applications. One said they are building an OCR model to parse handwritten medical prescriptions and could use PenGPT to generate synthetic training data. Another said they are building a presentation model and consider graphical real-time presentation an under-served capability of existing models. A third said they are building an app to teach handwriting with Rokid glasses.

Other comments raised limitations and small observations:

  • Commenter charcircuit said it is bothersome that the model does not know the proper strokes for cursive characters, which matches the author's own caveat that traced stroke order is a model's guess.
  • Commenter alanwreath reported that Spanish input is handled poorly, citing the Spanish for "teach me" ("enséñame"), and suggested contributing other languages would be interesting.
  • Commenter seantang001 reported premature stopping on some inputs, giving the example string !2/23\4/5.4;3;5l=3asfa913k391aslkf9a'a;s.":>"}+-=;.a.
  • Commenter wat555 noted the model is not good at drawing a pelican riding a bicycle.
  • Commenter k2xl highlighted that the model fits in 50MB.
  • Commenter cush speculated about whether training on what they called awful 2000s handwriting affected performance.
  • Commenter Tadpole9181 argued that technical blog posts of this kind often read as machine-polished and would benefit from being run through other state-of-the-art models and read carefully before publishing.
  • Commenter fraywing singled out the phrase "stroke tokens" as a notable idea, and commenter ex1fm3ta placed the work in the lineage running back to the original MNIST dataset.

Sources