Neural Net From Scratch in Javascript

Train a Mnist classifier or predictor

Mnist Digit Recognition with Javascript Neural Nets

Decoded

Truth Class. Binary Class. Analog. Pred. Binary Pred. Analog

Correct
Close

Notes:

The grid above will scroll through (using the arrow buttons just underneath the matrix) 500 hand written digits from the Mnist Test Set.

It decodes the characters in real time using four separate neural nets that were trained using 60,000 hand drawn characters from the Mnist Training set.

The four neural nets are:

  1. A Classifier that works on a binary representation of the original analog(ish) data
  2. A Classifier that works on the original analog data
  3. A Predictor that works on the binary representation
  4. A Predictor that works on the analog representation

A classifier believes that the answer and the truth are discrete variables and is rewarded for getting the answer right. It uses the visual similarity to achieve that

A predictor believes the answer and the truth are continuous varables. It's rewarded for predicting an answer that is numerically close to the truth. It uses the visual similarity to achieve that.

For that reason, when the predictor is wrong, it's often only 1 or 2 numerically different from the truth.

If you have a mouse (sorry mobile users), and you use chrome (sorry other browser users!) then you can hit the clear button just underneath the matrix and draw your own character.

I've trained the net after centring each character using Centre Of Mass. As soon as you release the mouse button, the decode will kick in.

If it doesn't decode correctly, try centring it using one of the two options

I created this system that works entirely in the browser with no backend and using no libraries. The system created and trained the neural nets which are then used in this screen to decode the characters.

It was completed as a learning exercise

The code for each solution type is identical. The only difference is in the shape of the network defined. A predictor has only one output node. A classifier has one node for each classification.

The truth must be structured accordingly. For a predictor, the truth is just the number. For a classifier, it is an array with the same number of entries as output nodes. The array is zero filled except for the entry corresponding with the correct answer