Built from scratch · Python · NumPy · Summer 2026
NeuralNet
A feedforward neural network built from scratch using only Python and NumPy, no PyTorch, no TensorFlow, no Keras. Forward pass, backpropagation, and mini-batch gradient descent, all hand-derived and hand-coded. Trained on MNIST to 98.0% test accuracy. The digit classifier below runs the network's real trained weights, ported to JavaScript, doing genuine inference on whatever you draw.
Draw a digit, 0 through 9. This isn't a simulation, the actual weights from
mnist_weights.npz were exported and are
running the same forward pass shown in the code tab, just in JavaScript instead
of NumPy.
A neural network is a function with millions of parameters (weights). Training finds parameter values that minimize error on the training data. This one has none of that magic hidden behind a framework, every piece below is code I wrote.
Z = X·W + b, then applies an activation. Input flows through every layer in sequence, producing the final prediction.-sum(true_label · log(predicted_prob)). Combined with softmax, its gradient simplifies beautifully to predictions - labels.N(0, √(2/n)) instead of zero. If every weight started at zero, every neuron in a layer would compute the same output and the network could never differentiate between them.The actual Python source: forward pass, backward pass, loss, and how the Flask app prepares a drawing. The page above goes one step further. It redraws your strokes the way MNIST digits were made (fit in 20x20 pixels, about 2 pixels thick, centred by mass), which makes its guesses much better.
What I learned
I derived it by hand: the gradient of cross-entropy(softmax(z)) with respect to z simplifies to just predictions - labels. Seeing pages of chain-rule algebra collapse into one clean line is why this combination is used everywhere in classification.
If every weight starts at zero, every neuron in a layer computes the same output and receives the same gradient forever, they can never specialize. He initialization keeps gradient magnitudes stable specifically for ReLU layers.
Batch size 1 gives noisy gradient estimates; the full dataset at once is accurate but slow. 32-256 samples turned out to be the sweet spot: fast, and with enough gradient variance to escape local minima.