r/learnmachinelearning • u/Necessary_Guest_4412 • 6d ago
Project I built a neural network from scratch using only NumPy.
I wanted to know what actually happens inside loss.backward().
So I built a neural network with nothing but NumPy. Every gradient derived on paper, every layer written by hand, every derivative checked numerically.
98.05% on MNIST.
Code and derivations: https://github.com/Meckmin/mnist-numpy-from-scratch
138
Upvotes
33
u/Background-Funny1237 5d ago edited 5d ago
my brother, you are overfitting
edit: val loss has been stagnating for the last 15 epochs while train loss gets lower and lower, this is why it seems like overfitting to me
1
u/kbr89 5d ago
A largest relative gradient error below 4e-9 is what makes the 98% believable, and it's more than most from-scratch repos do. A network with one hidden layer lands near 98% on MNIST, so the next things to learn come from changing the problem more than from tuning this one:
Also, as another commenter pointed out, if the validation loss has flattened while the training loss keeps falling, early stopping or a little weight decay is worth trying before adding capacity.
0
u/Exact-Contact-3837 5d ago
How does this have so many likes, I made this post about a month ago and I've just not stopped seeing just more and more "...from scratch" posts on this sub with ridiculous amounts of likes. Reddit is falling bruh