A small transformer that writes and sketches from text. The attempt was 80% data, 15% speed and 5% architecture: my archetypal project that follows the Bitter Lesson.

Left. One expression in the hands of 21 writers who were held out of training. The example peruse one to three genuine words by all of them and carried on in their hand. Right. Drawings from typed prompts. I picked these by eye from the finest third of the samples; there are unpicked ones additional down.
Last twelvemonth Zach Wimpee and I trained a small GPT to write cursive. It worked but it lone knew one hand (mine) and it learned from 3,500 words that I wrote on a trackpad.
So here’s the apparent next question: can one small, average transformer study to clasp a pen in many of hands and diagram as fine as write? PenGPT is my attempt. There are two models. A 6M-parameter one writes imprint and cursive and picks up the handwriting of person it has never seen from a few of their words. A 54M-parameter one draws from a content prompt.
Then I took the item distinct to discover out why it works. The answer wasn’t what I expected.
How it works

The entire recipe. Pen points break to a grid (b) so a term becomes a stroll in eight directions affirmative pen-down and pen-up. Byte-pair encoding merges average runs of moves into tokens (c): this "world" goes from 156 moves to 47 tokens. Everything alternatively is a plain decoder that cross-attends to what it's told.
That’s it for the modality-specific part: ten symbols and a merge count. The identical tokenizer handles handwriting and drawings. For handwriting the example is told the text; for drawings it’s told a SigLIP 2 vector so a typed expression can remain in for a picture.
The data
Almost nobody records pen strokes so I made the handwriting data from scans: 495,590 words by 1,255 writers, mostly from two investigation collections affirmative old alphabet and diaries from community archives. A vision-language example finds legible pages and transcribes them, the pages get cut into words, InkSight traces all term rear into strokes and a set of checks throws out bad traces. Between a third and a fractional of the words survive.
The drawings are 477,670 sketches from ten community datasets. Quick, Draw! has 50 myriad and I kept the finest 0.5%. I’m not releasing the datasets but the paper’s appendix explains how to build them.

Every author the example knows, saying hello. Each one is placed by its learned vector, alongside imprint on the remaining and cursive on the right. Nobody told the example which was which. Color is the origin the pages came from.
Training a model
I compared PenGPT alongside older approaches afterward changed one item at a period and retrained. Here are the rows I established most interesting; the document has the rest.
| Handwriting | Score change | Style rank | Legible |
|---|---|---|---|
| Graves-style LSTM, identical 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 term 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% |
| Drawings | Score change | Matches label | Matches caption |
|---|---|---|---|
| sketch-rnn-style LSTM, identical 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, fractional the width | +0.022 | 62% | 31% |
Rows complete the row are comparisons alongside another approaches; rows below it all alter one item concerning PenGPT. Score is nats per pen move on held-out data, lesser is better; the basis rows change by concerning 0.001 between seeds. Style position is how fine the example tells whose hand it is continuing (1 is perfect, 8.5 is chance). Legible is how frequently an OCR example says a sampled term exactly. The example columns are how frequently SigLIP 2 picks a drawing's own immediate out of a few hundred.
Data and how you display it. Those are the big rows. Cut the data and everything gets worse. Drop augmentation and the example example stops following its prompts entirely. Train on one term at a period and the example can no longer choice up a hand: manner position goes from 1.9 to 6.0.
The clever parts barely register. Telling the example anywhere its pen is does nothing for handwriting. The BPE merges I was arrogant of create the mark slightly worse; they buy speed (sequences are 3.2x shorter) and that’s all. A vocabulary sixty times larger changes nothing. Doubling the example changes nothing.
Even the transformer is optional, kind of. An LSTM on the identical tokens is a bit rearward on handwriting and motionless picks up new hands. On drawings, anywhere sequences are multiple times longer, it falls fine behind.
Samples
Enough tables. Here’s what the two models make.

Forty-eight of the 1,192 hands it trained on. The top two rows are sampled greedily so the differences there are all the writer. Further downward the heat rises and the alphabet loosen.
The example example takes a few controls furthermore the prompt. One of them is how much ink to use.

Six prompts, alongside additional ink requested from remaining to right. The home gains a door, afterward windows, afterward a flue and the racket's strings rotate into a cross-hatch. At the far correct the example has run out of parts to add and starts going complete its own lines.
It can additionally diagram several things it was never shown as lengthy as a blend of two acquainted ideas volition do.

Prompts that appear nowhere in the training data, one family per row: a visage or legs on an object, wheels and wings, hats and ears and one item shaped akin another. I picked these from multiple tries each. None of them depends on term order, which turns out to matter (see the end of the post).
Picking up a new hand
The trick is nearly embarrassingly simple. Each training sequence holds up to four words by one writer. That teaches the example that afterward words appearance akin before ones so at sampling period you hand it a few genuine words and it keeps going. No manner encoder, no fine-tuning. That’s how the 21 hands at the top of this article were written.
It additionally plant from a photo. There are no strokes in a photo so I trace a few of its words alongside InkSight and fit one new author vector to the traces, alongside the remainder of the example frozen.

Two hands learned from photos: a letter by the author Sara Teasdale and a paragraph person printed on a NIST form in 1989. From the top: the photo, words established in it, the model's copy of those words and new content in that hand. The printed copy keeps "genera", a term the cutting stage clipped. The example copies what it's given.
Reading the letters

What the cross-attention heads read. (a) A few heads in layers 3 to 5 fastener onto one position: this letter, the next letter or both. (b) Silencing the "this letter" caput expenses additional than any other. (c) That caput strolling through "letter" and "toward" as the pen writes them. Look at the t: it gets peruse twice, formerly for the stem and again for the cross and in cursive the cross doesn't arrive until the term is finished.
One caput in tier 4 puts 81% of its notice on the letter being written. I looked for heads that specialize in cursive or imprint and established none; all caput says the identical positions in both.
Do you need captions?
Captions are the costly part of the example data. Since SigLIP puts pictures and content in the identical space, perchance you could train on image vectors solitary and category a immediate at the end?

Eight held-out phrases, all drawn formerly by three models, nothing picked. Top: trained on pictures, labels and captions. Middle: pictures and labels. Bottom: pictures only.
You can’t. The picture-only example has the best likelihood of the three and it draws scribbles. The logic is geometric: SigLIP’s vectors for sketches sit in a narrow cone, nearly at correct angles to its vectors for text. A example that has lone seen the cone is misplaced whenever you hand it a sentence. Labels are adequate to diagram labels (78%) but lone captions get you phrases (43% against 10%).
What it can’t do

Forty random labels, one diagram each, nothing picked. This is the honest type of the fig at the top.
The example example blends but doesn’t bind. A teapot alongside a visage is fine. Who wears the hat is not and “facing left” gives the identical example as “facing right” since the sole vector it’s told is near to a bag of words (those two captions have a cosine similarity of 0.999). Sampled handwriting is additionally small legible than the genuine thing, 54% against 66%. And since most of the handwriting was traced from scans, its blow command is a model’s conjecture and not a record.
Closing thoughts
If you appearance complete my blog, you’ll notice that many of my projects revolve about clever ideas. I cut in affection alongside them since they were elegant. That isn’t a flaw in itself but I think Rich Sutton was prudent to notify concerning it in The Bitter Lesson. It really is bitter and it has taken me additional period than I’d akin to acknowledge to clasp it.
I think this article is my archetypal stage in the correct direction. The results are engaging and the project was a pleasance to activity on. And yet there was no clever architectural idea rearward it. About 80% of my attempt went into construction the biggest, cleanest datasets imaginable and doing many of norm authority on them. Another 15% went into finding a decent 8xA100 node and getting my models to train accelerated and in parallel on it: 8 minutes for the handwriting example and concerning 35 for the diagram model. My former attempt, the Cursive Transformer, took upwards of 10 hours on an A100 and lone always learned one hand. The tokenizer I used current is much simpler and far small elegant but it fair works.
The bitter instruction kills or sidelines a lot of beautiful investigation ideas. It’s akin gravity: it constrains you and most of the period it’s a extremely bad idea to combat back. But as I obtain it and commencement to activity with it, I discover things to admire. As a physicist I’m fascinated by the emerging discipline of scaling laws. And as a beloved of existence discipline I akin the idea of putting a ton of activity into the data and afterward exactly expanding a example on it, as you would an organism. Then you get to engage alongside it, study what it’s capable of and study how it works. Seen this way, the bitter instruction has its own charm.