News for hackers. Stuff that matters.
Re:Neural Networks from Scratch by minihat on Monday October 11, 2021 @10:48AM (#28828919)
Each time I teach neural nets to an engineer, there's only a 50% chance they can write down the chain rule. Colah's blog on backprop used to be my favorite resource to leave them with (https://colah.github.io/posts/2015-08-Backprop).

The explanation of the calculus in this tool is equally fantastic. And the art is very cute.

There are many ways to skin a cat, of course, but this is as good a tutorial as I've seen for getting you through backprop as fast as possible.

Re:Neural Networks from Scratch by baron_harkonnen on Monday October 11, 2021 @01:07PM (#28830515)
Given the current state of automatic differentiation I'm not so sure it's even necessary or particularly useful to focus on backpropagation any more.

While backprop has major historic significance, in the end it's essentially just a pure calculation which no longer needs to be done by hand.

Don't get me wrong, I still believe that understanding the gradient is hugely important, and conceptually it will always be essential to understand that one is optimizing a neural network by taking the derivative of the loss function, but backprop is not necessary nor is it particularly useful for modern neural networks (nobody is computing gradients by hand for transformers).

IMHO a better approach is to focus on a tool like JAX where taking a derivative is abstracted away cleanly enough, but at the same time you remain fully aware of all the calculus that is being done.

Especially for programmers, it's better to look at Neural Networks as just a specific application of Differentiable Programing. This makes them both easier to understand and also enables the learner to open a much broader class of problems they can solve with the same tools.

Re:Neural Networks from Scratch by medo-bear on Monday October 11, 2021 @01:51PM (#28830964)
Backpropagation is a particular implementation of reverse mode auto-differentiation, and it is the basis for all implementaions of DL models. It is very strange for me to read this as though it is very obvious and commonly accepted fact, which I don't think it is.
Re:Neural Networks from Scratch by baron_harkonnen on Monday October 11, 2021 @03:20PM (#28831932)
> to read this as though it is very obvious and commonly accepted fact

I'm not entirely sure what you're referring to by "this" but assuming you mean my comment, I think what I'm saying is very much up for debate and not an "obvious and commonly accepted fact". Karpathy has a very reasonably argument that directly disagrees with what I'm suggesting [0]. Of course he also agrees that in practice nobody will every use backprop directly.

Whether it's JAX, TF, PyTorch, etc the chain rule will be applied for you. I'm arguing that I think it's helpful to not have to worry about the details of how your derivative is being computed, and rather build an intuition about using derivatives as an abstraction. To be fair I think Karpathy is correct for people who are going to be learning to explicitly be experts in Neural Networks.

My point is more that given how powerful our tools today are for computing derivatives (I think JAX/Autograd have improved since Karpathy wrote that article), it's better to teach programmers to learn think of derivatives, gradients, hessians etc as high level abstractions. Worrying less about how to compute them and more about how to use them. In this way thinking about modeling doesn't need to be restricted to strictly NNs, but rather use NNs and example and then demonstrate to the student that they are free to build any model by defining how the model predicts, scoring the prediction and using the tools of calculus to answer other common questions you might have.

edit: a good analogy is logic programming and backtracking/unification. The entire point of logic programming is to abstract away backtracking. Sure experts in Prolog do need to understand backtracking, but it's more helpful to get beginners understanding how Prolog behaves than understand the details of backtracking.

[0] https://karpathy.medium.com/yes-you-should-understand-backpr...

Re:Neural Networks from Scratch by medo-bear on Monday October 11, 2021 @04:45PM (#28832848)
but with backprop you do not worry about computing derivatives by hand. backprop and AD in general means you do not have to do that. maybe one of us is misunderstanding the other

i am saying that if you want to work with ML algorithms on a more deeper level you must learn backprop

if you want to implement some models on the other hand, you can just follow a recipe approach

Re:Neural Networks from Scratch by matsemann on Monday October 11, 2021 @01:08PM (#28830517)
> there's only a 50% chance they can write down the chain rule

Why should I, though? I remember the concept from calculus. I know pytorch keeps track of the various stuff I do to a vector and calculates a gradient based on it. What more do I need to know when all I want to do is to play with applications, not implement backprop myself?

Re:Neural Networks from Scratch by Imnimo on Monday October 11, 2021 @03:21PM (#28831951)
Certainly there's a lot you can do without understanding backprop - you can train pre-made architectures, you can put pre-made layers together to build your own architecture, you can tweak hyperparameters and improve your model's accuracy, and so on. But I also think you will eventually run into a problem that would be much easier to debug if you understand backprop. If your model isn't learning, and your tensorboard graphs show your gradient magnitude is through the roof, it'll be much easier to track that down if you have a strong conceptual model of how gradients are calculated and how they flow backwards through the network.
Re:Neural Networks from Scratch by ZitchDog on Monday October 11, 2021 @07:28PM (#28834256)
I could be wrong but I think it’s possible to understand backprop without being able to apply the chain rule from memory.
Re:Neural Networks from Scratch by medo-bear on Monday October 11, 2021 @07:47PM (#28834383)
backpropagation IS the chain rule ... with book keeping
Re:Neural Networks from Scratch by medo-bear on Monday October 11, 2021 @02:08PM (#28831116)
if you don't understand chain rule then you dont understand backprop, which means you do not really understand how deep learning works. at most you can follow recipes cook book style. it is kind of how one can make a website without a deep understanding of networking
Re:Neural Networks from Scratch by kurikuri on Monday October 11, 2021 @10:40PM (#28835498)
This kind of argument can always go further by removing abstraction… you could argue that you don’t understand the chain rule without understanding the quotient and product rules which are used to prove the chain rule, and then once further with the epsilon-delta proofs required to get limits going for the derivative in the first place, and then continue until we reach some axioms.

I think you can accept that the chain rule is a thing, without understanding it, and then go further to understand its application to backprop.

Re:Neural Networks from Scratch by baron_harkonnen on Monday October 11, 2021 @03:44PM (#28832189)
> at most you can follow recipes cook book style.

Here I disagree with you pretty strongly. Once someone is comfortable with differentiable programming it's much more obvious how to build and optimize any type of model.

People should be more concerned about when to use derivatives, gradients, hessians, Laplace approximation etc rather than worry about the implementation details of these tools.

Abstraction can also aid depth of understanding. I know plenty of people who can implement backprop, but then don't understand how to estimate parameter uncertainty from the Hessian. The latter is much more important for general model building.

Re:Neural Networks from Scratch by medo-bear on Monday October 11, 2021 @04:38PM (#28832781)
i am not sure what you are disagreeing with. chain rule is basic calculus that precedes understanding hessians. my argument is, if you can not understand what the chain rule is, you will not understand more complicated mathematics in ML. do you think i am wrong ?

EDIT: also uncertainty estimation is the stuff of probabalistic approach to ML. i would say that people who do probabalistic ML are quite mathematically capable (at least to my experience)

Re:Neural Networks from Scratch by baron_harkonnen on Monday October 11, 2021 @06:31PM (#28833828)
> chain rule is basic calculus that precedes understanding hessians.

It doesn't have to be that way. The hessian is an abstract idea and the chain rule and more specifically backpropagation are methods of computing the results for an abstract idea. When I want the hessian I want a matrix of second order partial derivatives, I'm not interested in how those are computed.

For a more concrete example, would you say that using the quantile function for the normal distribution requires you to be able to implement it from scratch?

There are many, very smart, very knowledgeable people that correctly use the normal quantile function (inverse CDF) every day for essential quantitative computation that have absolutely no idea how to implement the inverse error function (an essential part of the normal quantile). Would you say that you don't really know statistics if you can't do this? That a beginner must understand the implementation details of the inverse error function before making any claims about normal quantiles? I myself would absolutely need to pull up a copy of Numerical Recipes to do this. It would be, in my opinion, ludicrous to say that anyone wanting to write statistical code should understand and be able to implement the normal quantile function. Maybe in 1970 that was true, but we have software to abstract that out for us.

The same is becoming true of backprop. I can simply call jax.grad on my implementation of loss of the forward pass of the NN I'm interested in and get the gradient of that function, the same way I can call scipy.stats.norm.ppf to get that quantile for a normal. All that is important is that you understand what the quantile function of the normal distribution means for you to use it correctly, and again I suspect there are many practicing statisticians that don't know how to implement this.

And to give you a bit of context, my view on this has developed from working with many people who can pass a calculus exam and perform the necessarily steps to compute a derivative, but yet have almost no intuition about what a derivative means and how to use it and reason about it. Calculus historically focused on computation over intuition because that was what was needed to do practical work with calculus. Today the computation can take second place to the intuition because we have powerful tools that can take care of all the computation for you.

Re:Neural Networks from Scratch by medo-bear on Monday October 11, 2021 @07:57PM (#28834461)
> Today the computation can take second place to the intuition because we have powerful tools that can take care of all the computation for you.

and that tool is backprop. if you do not understand what the chain rule is and what it is doing, that tool will be magic to you and you are blindly trusting its correctness. seeing that alot of risk is involved in using AI models in real life, blindly trusting your model is not a good approach

i agree that simply regurgitating rules of calculus is pointless to understanding. but thats definitely not what i mean when i talk about the need to understand the chain rule

ML is a mathematically intensive subject. there is no going around this fact

Re:Neural Networks from Scratch by mpfundstein on Tuesday October 12, 2021 @08:34AM (#28838893)
do you know all the assemlber instructions your pc/mac carried out for you in order to post this text on hn? i guess not
Re:Neural Networks from Scratch by medo-bear on Tuesday October 12, 2021 @02:45PM (#28843463)
but that's my point. knowing how to compile a program does not make me a compiler engineer. in that sense feel free to use ML tools, but don't be fooled into thinking you will get a job as an ML engineer if you do not know what the chain rule is, or why we need to take a derivative in order to optimise a loss function. in fact, don't even be fooled into thinking you will get into a ML uni degree if you don't know what the chain rule is. i actually don't understand what is the problem. spend 10 minutes reading up on it and i am sure you will get it. i think an unwarranted phobia of mathematics is what is at play here
Re:Neural Networks from Scratch by tchalla on Monday October 11, 2021 @05:12PM (#28833156)
> my argument is, if you can not understand what the chain rule is, you will not understand more complicated mathematics in ML.

Are you sure about this?

Re:Neural Networks from Scratch by medo-bear on Monday October 11, 2021 @05:26PM (#28833301)
yes. in europe admission into an ML-type masters degree lists all three standard levels of mathematical analysis as a bare minimum for application
Re:Neural Networks from Scratch by tchalla on Monday October 11, 2021 @06:07PM (#28833652)
If by understand, you mean understand and not regurgitate it when asked as a trivia question - I agree with you. However, there are different interpretations of the chain rule.
Re:Neural Networks from Scratch by thewarrior on Monday October 11, 2021 @07:04PM (#28834107)
Are there any books that teach differentiable programming ?
Re:Neural Networks from Scratch by medo-bear on Monday October 11, 2021 @07:44PM (#28834361)
not books but there are quite a few interesting and accessible papers. here is one

Pearlmutter, B.A. and Siskind, J.M., `Reverse-Mode AD in a Functional Framework: Lambda the Ultimate Backpropagator,'

http://www.bcl.hamilton.ie/~qobi/stalingrad/

Re:Neural Networks from Scratch by jhgb on Monday October 11, 2021 @01:29PM (#28830740)
> there's only a 50% chance they can write down the chain rule

I blame the common mathematical notation for that.

Re:Neural Networks from Scratch by friebetill on Monday October 11, 2021 @01:56PM (#28831006)
I found this 13 min explanation very helpful in understanding backpropagation (https://youtu.be/c36lUUr864M?t=2520).

First he explains the necessary concepts:

1) Chain Rule

2) Computational Graph

Then he explains backpropagation in these three steps (first in general and then with examples):

1) Forward pass: Compute loss

2) Compute local gradients

3) Backward pass: Compute dLoss/dWeights using the Chain Rule

Re:Neural Networks from Scratch by ThinkingAgain on Tuesday October 12, 2021 @12:37AM (#28836105)
After reading the tutorial I was not sure why it was called backpropagation. Thanks for the Colah's blog link. I think the two links together explains the things beautifully. Backpropagation seems just like an optimization for the gradient descent calculation as per Colah's blog.
Re:Neural Networks from Scratch by shaan7 on Monday October 11, 2021 @11:31AM (#28829477)
Any recommendations for a 101 book for neural nets for someone who is "just a programmer"? OP's tutorial is quite nice, but I love to read books and find it easier to learn from them.
Re:Neural Networks from Scratch by jacobcmarshall on Monday October 11, 2021 @11:50AM (#28829678)
Deep Learning with Python by Chollet is an excellent beginner resource if you are a hands-on learner.

It starts off with some tutorials using the Keras library, and then gets into the math later on.

By the end of the book, you create multiple different types of neural networks for identifying images, text, and more! I highly recommend it.

Re:Neural Networks from Scratch by aeg42x on Monday October 11, 2021 @02:45PM (#28831503)
I highly recommend http://neuralnetworksanddeeplearning.com/ it’s an online book that has some great code examples built in.
Re:Neural Networks from Scratch by bernulli on Monday October 11, 2021 @10:46PM (#28835533)
I also found his ‘visual proof’ for neural networks as general function approximators super intuitive.
Re:Neural Networks from Scratch by wesleywt on Monday October 11, 2021 @12:12PM (#28829904)
Fastai has a course: practical deep learning for programmers.
Re:Neural Networks from Scratch by carom on Monday October 11, 2021 @12:30PM (#28830097)
There are also coursera specializations from Andrew Ng at https://deeplearning.ai.
Re:Neural Networks from Scratch by matsemann on Monday October 11, 2021 @01:11PM (#28830548)
Ng's course is bottom up: Start with the basic math, expand upon it, until you arrive at ML and neural nets.

Fastai is top down: learn to use practical ML with abstractions, and then dig deeper and explain as needed.

I preferred fastai's approach, even though I enjoyed both. Ng's could be a bit too low level and fundamental for what I wanted to learn.

Re:Neural Networks from Scratch by carom on Monday October 11, 2021 @01:34PM (#28830782)
This is a valuable take. Fastai was very frustrating for me because I wanted to understand the internals. I ended up not finishing it, so take my opinion with a grain of salt.
Re:Neural Networks from Scratch by windsignaling on Monday October 11, 2021 @03:15PM (#28831872)
I much prefer Andrew Ng's courses as well.

I tried Fast AI, but it seems to be trying too hard to take out the math, which oddly for me (as a STEM grad) makes it much more difficult to understand.

Had to stop when I saw him using Excel spreadsheets to explain convolution.

Re:Neural Networks from Scratch by knicholes on Monday October 11, 2021 @07:08PM (#28834133)
The Excel spreadsheets is where it all clicked for me. It's not done with some magical library but with simple math being performed on some weights.
Re:Neural Networks from Scratch by carom on Monday October 11, 2021 @12:31PM (#28830104)
There is a book called neural networks from scratch at https://nnfs.io.
Re:Neural Networks from Scratch by shaan7 on Wednesday October 13, 2021 @02:03AM (#28848704)
Thanks for the recommendations folks! :)