Eleven months teaching a CNN to read handwriting
RethinkLit is a literacy app I built for kids in their first few years of school. In one activity a child hears a sentence, writes it on an iPad, and the app checks each letter. So I needed something that could look at a wobbly letter drawn with a finger and decide it was a b.
I worked on that from July 2025 until about June 2026. This is pieced together from the git history.
Starting with EMNIST
EMNIST is the handwritten-letter version of MNIST, hundreds of thousands of 28×28 greyscale letters. By late July 2025 I had a small CNN trained on it in Keras, exported to TensorFlow.js and running in the browser.
Getting it to run took a few days. Keras 3 and TensorFlow.js didn't agree on the model format, so I went from a model.json that wouldn't load to weights that loaded fine and gave rubbish. I ended up writing scripts to dump the layer weights so I could compare them.
Then it ran, and it was confidently wrong about my handwriting. I built a debug page that showed an EMNIST sample next to my canvas drawing after preprocessing, so I could see what the model was being given. Pages like that turned out to be the most useful thing I built all year, although it took me far too long to use them properly.
My own handwriting
EMNIST is adult handwriting, scanned from forms in the US. My users were five to eight years old and writing on glass. Two days after the first model ran I had a page, only ever run on my own machine, where I could pick a letter, draw it and save it as a training sample. By the end there were about 1,500 of them, all mine. The model was never trained on children's writing, which was a privacy decision as much as a technical one.
On the first weekend in August I also tried generating training data from the Victorian Modern Cursive font, the handwriting style taught in Victorian schools, and packaged it up to train on a GPU in Google Colab. I'm not sure it ever helped. A font gives you the letter a child is aiming for, and my problem was always the letter they actually produce.
"Model is working amazing!"
That's the real commit message, from 10 August 2025. Recognition went from frustrating to good in a day, and I didn't retrain anything. Every change in that commit was in the code either side of the model.
Each letter now got centred by where its ink was instead of by its bounding box, so a d with a long stem stopped getting pushed off to one side. Padding dropped from 10 pixels to 5, and contrast stretching meant faint strokes still registered. Segmentation, the part that decides where one letter ends and the next starts, switched from averages to medians, learnt about the dot on an i and the cross on a t, and stopped treating strokes as touching unless they overlapped by at least 3 pixels. On top of all that sat a beam search over readings of the whole word, nudged towards real words. And because the app knows what the child was asked to write, it could use the expected letters to break ties.
For a model this small I think preprocessing matters about as much as the architecture. The network only ever sees what you hand it.
A bigger model, on a server
By October I'd swapped the simple CNN for a small residual network with three residual blocks and about 1.5 MB of weights.
inputs = layers.Input(shape=(28, 28, 1))
x = conv_bn_relu(inputs, 32)
x = residual_block(x, 32)
x = layers.MaxPooling2D(2)(x)
x = residual_block(x, 64)
x = layers.MaxPooling2D(2)(x)
x = residual_block(x, 128)
x = layers.GlobalAveragePooling2D()(x)
x = layers.Dense(256, activation="relu")(x)
x = layers.Dropout(0.5)(x)
x = layers.Dense(128, activation="relu")(x)
x = layers.Dropout(0.3)(x)
outputs = layers.Dense(26, activation="softmax")(x)The training data changed too. EMNIST's Letters split lumps upper and lower case into the same class, and my lowercase a kept coming back as Q. Moving to the ByClass split and keeping only the 26 lowercase classes got rid of that. It suited the app anyway, since the kids were mostly writing lowercase.
Around the same time the model moved out of the browser and into a Firebase Cloud Function in Sydney. Running it in the browser was neat, but children's handwriting is personal information and I wanted to be able to say exactly where it was processed. One function in one Australian region made that a simple sentence to write, and a true one.
Being fair to a six-year-old
At 94% on a test set, the model was still going to tell some kids a letter was wrong when their teacher would have accepted it. So I changed what the app counted as correct. A letter passed if the expected letter was anywhere in the model's top five guesses with at least 5% confidence. I also added a small table of letters that are easy to mix up, like c, e and o, or m, n and w, and used it to correct a prediction when the expected letter was one of the usual suspects.
That can sound like cheating. But the app already knew which word the child had been asked to write, and throwing that information away would have been odd.
The bug that was there from the start
In May 2026 I finally went after something that had been bugging me for months. A few letters were wrong with complete confidence. My n came back as u pretty much every time, and b came back as q 97% of the time.
I wrote a script that drew every training image the way the model received it.

Before. My custom n samples (columns 2, 4, 6 and 8) reach the model as u-like shapes, and my b looks like an upside-down q.
EMNIST stores its images transposed, so everything going into the model has to match that orientation. My collection page had been rotating each sample before saving it. The training loader then applied what was meant to be the inverse and wasn't, and the live pipeline flipped everything again on the way in. My n samples had been taught as u shapes from the start. The model had learnt exactly what I gave it.

After. Samples are saved upright and transformed in one place, and now line up with the EMNIST samples beside them.
The fix was small. While I was in there I found a second bug I'd never have guessed. macOS file systems are case-insensitive by default, so my custom/A/ and custom/a/ folders were the same folder, and uppercase and lowercase samples had been mixed together on disk.
After that I split it into two models, one per case. The lowercase one scored 93.6% on held-out data and the uppercase one 98.2%, probably because capitals are more distinct from one another.
Speed, and punctuation
In June 2026 I fixed the speed. Listen & Write was sending each letter to the server separately, one after another. Inference took about 0.4 seconds, but most of each round trip was network overhead, so a long sentence meant a long wait. Sending the whole sentence in one request, with the model kept in memory across the batch, made the wait roughly the same however long the sentence was.
When the app started marking punctuation I kept the CNN out of it on purpose. Squashing a mark into a 28×28 box throws away its size and where it sits against the line, and that's most of what separates a full stop from a comma or an apostrophe. A few dozen lines of plain geometry did the job better.
What I'd do differently
I'd draw the model's input on day one. The orientation bug was sitting in a picture I could have made in July 2025.
I wrote elastic deformation and stroke-width augmentation, which are supposed to help a lot with handwriting, and never wired either of them into training. My test set was carved out after the train/validation split, which leaks a little and probably flatters the numbers above.
And every accuracy figure in this post comes from held-out samples, not from kids on iPads. The number I actually cared about was how often a child got marked wrong for a letter a teacher would have accepted. I never measured it properly, so I don't know what it was.