Skip to content

Comment on Neural network from scratch

Comments

Interesting read, but there's a few things I haven't understood. In the training [function](https://colab.research.google.com/drive/1YRp9k_ORH4wZMqXLNkc...):

1- In the instruction `hidden_layer.data[index] -= learning_rate * hidden_layer.grad.data[index]`where was the `hidden_layer.grad` value updated?

2- from what I've understood, we'll update the hidden_layer according to the inclination of the error function (because we want to minimize it). But where are `error.backward()` and `hidden_layer.grad` interconnected?

Great questions, I struggled with this part the most when I was learning it.

`.grad` is set by `autograd` when calling `backward()`

Probably the easiest way to understand this is to play a bit with `.grad` and `backward()` on their own, with the first code sample in the `autograd` section [1].

[1]: https://sirupsen.com/napkin/neural-net#automagically-computi...

Thank you!

FYI Markdown type links don't work on HN, that's why you see people type footnotes [0]

[0] like this

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.