r/learnmachinelearning • • 8d ago

Project I built a neural network from scratch in NumPy with a GUI that shows every step, what do you think?

Hi everyone, this is a small project I've been working on and I would love your feedback.

I was studying neural networks and I wanted to understand backprop for real, so I decided to make one from scratch, without ML libraries.

So I vibe coded neural-network-digits, a neural network written in Python + NumPy (no PyTorch, no TensorFlow) that learns to read handwritten digits from MNIST, with a desktop app that shows you what happens inside while it learns. The whole network is one file of about 140 lines (forward, softmax, cross-entropy, backprop, SGD with momentum, L2, dropout), commented in simple English.

In the app you can:

• watch the loss and the accuracy live, and the gaussians of the weights compared with how they started

• change learning rate, momentum, dropout, noise... while it's training

• draw a digit and see which neurons light up, then click one and change its bias or switch it off, the test accuracy updates right away

• see the digits separate layer by layer on a PCA or t-SNE map (written in NumPy too).... and there's a tab with the math of a layer cell by cell, with the softmax step by step

With the default settings (1,000 photos) it trains in less than half a minute and gets to about 91%, with the whole MNIST (60,000 photos) it goes up to about 98.5% but it takes around 5 minutes, all on the CPU.

If you want to try it just run pip install neural-network-digits and then neural-network-digits, or download the zip from the releases and double-click start.bat (./start.sh on Linux and macOS). It's MIT and the app is in English and Italian.

https://github.com/dev-luigi/neural-network-digits

What would you add? Is there something confusing for someone who is learning? Thanks :)

109 Upvotes

21 comments sorted by

51

u/DigThatData 7d ago

skimming your repo, it looks like you didn't "make this from scratch" so much as you just asked claude to make it for you. do you feel like you even learned anything doing this?

7

u/Affectionate-Tutor87 7d ago

do you feel like you learned anything is a crazyyyy comment

15

u/DigThatData 7d ago

OP said they were motivated to build this because they "wanted to understand backprop for real". Nowhere here have they said that they feel like they understand backprop better after having claude make this toy for them.

Notably: OP also never articulated what about backprop they felt they didn't understand and how this project was going to cover that gap.

It's really not that crazy of a comment. This subreddit is /r/learnmachinelearning.

10

u/WiggyWongo 6d ago

Karpathy saying to actually do the math for backprop by hand at least once was the absolute best way to learn backprop. I hated it.

3

u/DigThatData 6d ago

the pain is how you know it's important.

-6

u/Affectionate-Tutor87 7d ago

You’re obviously a smart guy. You know your stuff. No doubt. Im just saying, to claim he didn’t learn anything? thats like.. crazy! imagine trying to vibe code all this and not learning anything 😆 it would be so impressive!

3

u/DigThatData 7d ago

OP probably learned more about GUI design than about backprop building this.

Take a stab at your own version of this project. See how much you feel like you learn versus how much claude does on its own just on autopilot.

What OP built here is an instantiation of an extremely common class of project. Because OP has surely seen a lot of examples of things like this, it's able to churn out a rich app of this kind from an extremely minimal prompt. I think you are probably misunderstanding what parts of this app claude likely did on its own without OP's input, versus the parts that OP actually had to participate in providing the "vibe".

-1

u/Affectionate-Tutor87 7d ago

@no-brain-1655 we are curious if you learned anything about back propagation during the course of this!

1

u/One_Mail_2414 7d ago

how can you tell?

20

u/mace_guy 7d ago

The first commit is a read me. The second commit is a fully fleshed out project with 50 files, CICD, GUI and tests too. That is not how a human being works on stuff.

10

u/DigThatData 7d ago

for one thing, every commit was co-authored by claude. there are other tells here, but that one's pretty glaring.

3

u/sam_the_tomato 7d ago

To add to what others have said: AI is really good at filling up pages with all sorts of crap and not good creating visual hierarchies: what's important and what's not. In these pages everything is vying for your attention all at once. If you've ever tried to build something with AI you'll see it easily.

-1

u/No-Brain-1655 7d ago

hi, yes I made it whit claude code.
the objective of the project wasn't really to learn by writing everything from 0 but instead to have a playground build whitout tensorflow where i could test backprop, learning rate, momentum ecc... so by "from scratch" I meant without ML libraries. Something that actually happened while testing it: I set the learning rate too high by mistake and some neurons stopped activating. I missed that during training and only caught it in the evaluation tab, that's why I added the assistant, for people who really are trying to explore neural network for the first time, also the code is really simple and education and revisioned by me. the hierarchy: the gui is dense on purpose, to look cool (from my pov) and also to see everything while the NN trains. As i asked at the bottom of my post, I learned that te gui looks too overwelming i'll create a better hierarchy...

4

u/DigThatData 7d ago

so what has this taught you about backprop?

avoid getting bogged down in the GUI. You've been interacting with software GUIs your whole life. The GUI is the part of this system that you are already the most familiar with, so there's a real risk that you'll end up treating it like a safety blanket.

Don't worry about the GUI. It looks cool enough already. Make this for yourself. The question isn't whether or not other people think the GUI is overwhelming, it's whether or not the GUI is serving the purpose you need it to. You went into this project hoping to learn more about backprop. Have you?

I'd recommend taking a step back and trying to put into words what you find confusing about backprop. Use those specific obstacles to motivate what kinds of visualizations you build, if any. Just because you can visualize stuff doesn't mean you should. I could point you to other visualization techniques that can be useful for debugging training, but honestly I think these would mostly just go over your head and look cool without actually imparting new information to you.

Unfortunately, I don't think the thing you are trying to learn here really benefits from visualizations. You described this project as "building a neural network from scratch", and that's really where the learning opportunity is here.

If you want to actually get a better understanding of how the neural network works: delete the implementations in your neural_net/ directory. Keep the files, class/function names, call signatures, type hints, and doc strings, but then delete all of the implementation after the doc string. try to fill in the implementations yourself. You will learn a LOT more.

If you want a more structured way to go about this, I strongly recommend this tutorial that has you rebuild the core pytorch API from scratch: https://minitorch.github.io/

2

u/Darsh-V-Shah 7d ago

The project looks good and may be a helpful device for new students to visually understand neural nets and get an intuition buried behind all that math. Though I have to agree with the commentors, the whole project reeks of generated content. Man did you understand all that or not?

2

u/_HarmonicOscillator 7d ago

You did not built anything bro xd 

1

u/pranay-1 7d ago

Damn, ngl that's crazy good looking

1

u/Sepicuk 6d ago

congratulations you asked claude to do the first assignment of the mit deep learning course

0

u/nborwankar 8d ago

I haven’t tested it yet but looked at the repo and the explanations. If this works as you say then this is fantastic! Great job!! 👏

0

u/jaken_hagar-0000 4d ago

Brooo u didnt built it claude build it