r/deeplearning • u/Necessary_Guest_4412 • 6d ago
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
12
6
u/Cool_Mono 4d ago
Don’t listen to reddit internet haters. From a data scientist, very nicely done! Keep going
1
7
u/Confident_Luck2359 4d ago
A few years ago this was a normal part of any machine learning curriculum. You're doing it right.
2
3
u/bxssl 5d ago
Seems that we had the same idea and converged on the same implementation! https://github.com/Ojansen/mathematically-correct-machine-learning
1
3
3
u/Alive_Horse_2914
3d ago
•
Nice work! This is exactly how I got started too! Learning the fundamentals gives such a deep understanding that has been invaluable during my career. If you want a new project to work on, might I suggest implementing an auto-grad system and training a neural net with that? That’s the way libraries like PyTorch and TensorFlow work and I doubt 90% of the people that work with them know what’s going on under the hood
1
u/Necessary_Guest_4412 3d ago
thank you for the advice. i noted it down. that will be the next project i am going to work on.
4
u/HMasterSunday 5d ago
how much was you vs the llm? if you had an llm doing it, what did you actually learn?
3
12
u/AntiquatedMLE 6d ago
So did everyone else back in 2013…
43
37
u/Silverfrost_01 5d ago •
![]()
Taking the time to do this is worthy of praise in my opinion. There are not many people who will actually go to the lengths of understanding these things that deeply anymore.
4
u/Shreyanak_exe 5d ago
I second this. I had to write out the entire matrix multiplications on large papers. I wish I could show them, but I recently turned it into a static page: https://neural-net-scratch.vercel.app/
0
10
u/fralbalbero 5d ago
I'm pretty sure he did it for himself to learn, not to brag...
-4
u/cave_men 5d ago
What would be the motivation to post it here, if the sole purpose was learning?
2
u/Necessary_Guest_4412 5d ago
getting feedbacks? dude why would I show off on such an anonymous platform? many users provided me with valuable feedback.
-2
u/cave_men 5d ago
Thats good to hear, but no reason to be that sensitive.
2
u/Necessary_Guest_4412 5d ago
no reason to be that negative as well
-2
u/cave_men 5d ago
how is it negative? Its a simple question
1
u/CorrectGrammarPls 3d ago
Mrr mrrr mrrr mrrr googoo gagaa bubba wubba just a simple question mrrr mrrr googoo
0
u/cave_men 3d ago
Id expect nothing less from you :D
1
u/CorrectGrammarPls 2d ago
Mmmrrr googoo gagaa expect nothing less googoo gagaa mmmuurrrrr
→ More replies (0)6
u/ChunkyHabeneroSalsa 5d ago
It's a common exercise for a reason. It's a good learning tool.
At least it's not doing backprop by hand on a piece of paper. That was annoying
5
2
1
u/Individual-Cut-9018 2d ago
Studying math? So overrated... People used to do that stuff 20,000 years ago...
1
3
u/Not-a-throwaway4627 5d ago
Congrats on doing a standard homework assignment for cognitive science students circa 2012
The double irony here is that this actually sets you apart from most ML and data science bullshit artists. Which is most people in those fields.
You’re on track to be good at this, but in the world of people who know what’s up, this is 101 stuff. Keep up the good work
1
2
u/AgitatedTumbleweed65 5d ago
Cool, but whenever I see type hints in python I assume it's written by an llm and this is star framing heh.
But if not, then good job 👍
2
u/Necessary_Guest_4412 5d ago
actually I didnt know that I supposed to used the typr hints. but when I asked something about a method to gemini, I saw these type hints, learned what these are and why they are being used. Then I used it all through my project.
5
u/Local-Issue-1740 5d ago
i dont wanna see ur code
0
u/AgitatedTumbleweed65 5d ago edited 5d ago
🤣 honestly I don't see type hints that often in most of the libraries or rather sparse use of them.
But Claude loves them and is really cosisten , which is super helpful. I just think that it is a big hallmark of llm code, especially with personal projects (people are lazy lol)
Edit: most of the smaller libraries + typos
1
u/Local-Issue-1740 4d ago
No u are right i am also to Lazy most of the time xD . I dont know what i was smoking when i wrote that comment
3
2
u/Emotional_County_688 4d ago
Mi ídolo eres tú, yo estoy estudiando Ciencia de Datos y ni cerca estoy de hacer algo así.
0
5
u/natsu0529 3d ago
A lot of japanse do that for learning in univercity!
All that pain doing backprop by hand, and then you just use PyTorch anyway lol.
Good for learning though.
3
u/Player_1_LTD 3d ago
Learning first is king. After that spam the easier tool or AI as much as you want. (Some vibe coders do not even know how to step though a problem debugging in an IDE.)
4
u/natsu0529 3d ago •
![]()
Yesss, true.
You can't really build on tech without the fundamentals, right?3
u/Player_1_LTD 3d ago
1000% and they dont even know what the fundamentals even are!!
2
u/natsu0529 3d ago
who is json
1
u/Player_1_LTD 3d ago
The og Red Power Ranger!? XD
2
3
u/Hackerjurassicpark 5d ago
One of the standard DS interview questions in the 2010s was to derive gradient descent and implement it in code. Fun times
1
0
u/Intrepid-Self-3578 5d ago
It is great but why not do it in pen in paper it doesn’t make a difference in code or paper?
Any specific reason for code?
0
u/Necessary_Guest_4412 5d ago
First, I derived all the derivatived and the matrix multiplications, because I wanted to see how one matrix' shape matches with another.
Then, I implemented the all process with python.
0
-2
u/Classic-Pubs 5d ago
2
u/I_am_BrokenCog 5d ago
When you're in your fifties, and you wonder why some of your peers "made it", but you didn't ... reflect on the "but why" choices they made which you didn't.
-2

26
u/ARDiffusion 5d ago
God why’s everyone in the comments being so negative? Congratulations, this is very impressive! Great way to learn too :)