Letter and Digit Recognition: Train a Neural Network and Test It by Drawing

Train a small neural network in your browser to recognise printed digits and letters, draw a character and see what it thinks with its confidence, look at what its hidden neurons do, test it on fonts it has never seen, and teach it your handwriting. Private: nothing is uploaded.

The network learns from pictures of characters drawn in the fonts on this computer, bent and shifted at random. Nothing is downloaded or uploaded.

1. Draw one character

2. What it thinks

Train the network, then draw.
What the network sees (the drawing shrunk and centred):
How its hidden neurons react:

3. Test it on fonts it has never seen

Which characters does it mix up? (confusion table)

Teach a neural network to read letters and digits

Press Train and a small neural network learns, in a few seconds on your own computer, to recognise printed characters from thousands of pictures it generates in your fonts. Then draw a digit or letter on the pad and watch it guess, with its confidence for each possibility. Because it was trained on printed fonts rather than handwriting it is often wrong about your scribbles; press Teach it this with the right answer and it learns your handwriting from your examples. That is the central lesson of machine learning: the model is only as good as the examples it was trained on.

Questions

How does it turn a drawing into numbers?

Your drawing is cropped to the ink, shrunk to a 14 × 14 grid of grey values (196 numbers, shown as what the network sees) and moved so its centre of mass sits in the middle, so a character drawn small or in a corner looks the same as one drawn big. Those 196 numbers go into the network.

What are the hidden neurons doing?

Each hidden neuron adds up all 196 pixels times its own weights; it learns to fire for a pattern such as a curve at the top or a stroke down the right. The next layer combines these patterns into ten (or 26, or 36) scores, and softmax turns the scores into percentages.

Why is the test on fonts it has never seen?

Some fonts are held back and never used for training. Its accuracy on them shows whether it has learned what a "7" looks like in general or only memorised the training pictures.

Why does it mix up O and 0, or I and 1?

Because in many fonts they really are nearly identical. No amount of training can separate shapes that look the same: that is a limit of the data, not of the network. Try Digits and letters and look at the confusion table.

Is anything uploaded?

No. The pictures are drawn by your browser, the network trains in your browser, and the examples you teach it stay in this browser.

Comments
Advertisement