I have coded a small drawn digit recognition tool in Python, Javascript and PHP. The idea was to learn a bit about this new fashionable concept of artificial neural networks, and not use any machine learning libraries but instead get a feeling for the subject by deriving the equations and building every piece from scratch. I have used the excellent book by Michael Nielsen as my knowledge source. The mathematical theory requires not more than a university course in multivariable calculus, and perhaps a bit of linear algebra, to understand.

I have used the simplest fully-connected neural networks, with the cross-entropy cost function and L2 weight regularization techniques, as well as some hard-to-justify improvisations that I thought might help. The code for learning was written in Python and can be found here. It is not optimized in any particular way, but runs fast enough to train the networks in reasonable time on my cheap personal laptop. A learned network was then ported to PHP, and the app below does some necessary pre-processing of the input image in Javascript.

I have trained several networks. The first two, which I call B1 and B2, will be used if you press the blue buttons below. They are both trained using the classical MNIST database of 60000 scanned images of handwritten digits. The first network one consists of two hidden layers, 100 neurons in the first and 10 in the second. I've achieved a 98.01% accuracy on the MNIST test data set. The network B2 consists of 150, 200 and 100 hidden neurons in the three hidden layers. It incidentally achieved the same 98.01% accuracy as the simpler B1. The two networks B3 and B4 will be used if you press the green buttons below, and these networks are trained using the EMNIST database . This data set is much larger than MNIST as it consists of 240000 images of handwritten digits. The corresponding article describes the structure of the data in EMNIST in detail. B3 consists of one hidden layer of 250 neurons, while B4 is a bit deeper. It has three hidden layers of 300, 250 and 200 neurons in the layers. I've achieved 98.95% and 99.19% accuracy on the EMNIST test data set using the networks B3 and B4 respectively.

In the drawn digit recognition below, the estimates of the networks do sometimes differ. When one fails, sometimes some other succeeds, suggesting that an ensamble of networks could probably improve the results. An average of the networks estimates will be displayed after pressing the vote button below. The pie chart appearing on the right side represents some sort of confidence in the decision that the network made, in the sense that it displays the "probabilities" that the input image is a certain digit. Check yourself how it recognizes digits drawn by you. When I draw the digit, first two networks seem to have some trouble with detecting my "8s", and they often think it is a "3". My "4" sometimes kind of looks like a "9", then this is evidenced in the probabilities in the pie chart. I find that if I put in minimal effort into drawing the digit, the recognition works great except for 8s. Of course, the data used for learning was actual scanned human-handwritten digits, while here we input something drawn on a computer screen, so certain difficulties are understandable.

**Draw in the left box.**