Live data from Hacker News

How to build your own neural network from scratch in Python

towardsdatascience.com

11–20 of 46 posts

Re: How to build your own neural network from scratch in Python

#11
post #2

Too often you see articles like this and they start with $ import a_whole_bunch_of_stuff Good to see that this is not the case here :) The fast.ai course has a similar exercise in the beginning, but you'll still import the weights from somewhere else. Their fast.ai v1 library has a very short implementation too (loading the MINIST example dataset and then using Resnet18): from fastai import * from fastai.data import…

How is your example not "$ import a_whole_bunch_of_stuff"?

Re: How to build your own neural network from scratch in Python

#12
post #7

Nah, let's make that 10 lines: https://gist.github.com/vesche/72dafed33d614710f03f1b75cff1c... I got a beer for anyone who can golf it under 5 lines

Naive solution (1 line):

https://gist.github.com/applecrazy/deda2fac6e83c07b93e001731...

Edit: I literally took newlines, converted to \n in a string, and then exec()ed the whole thing. Here's a repl of it working: https://repl.it/@applecrazy/Code-Golfing-a-Neural-Net

Re: How to build your own neural network from scratch in Python

#13
post #2

Too often you see articles like this and they start with $ import a_whole_bunch_of_stuff Good to see that this is not the case here :) The fast.ai course has a similar exercise in the beginning, but you'll still import the weights from somewhere else. Their fast.ai v1 library has a very short implementation too (loading the MINIST example dataset and then using Resnet18): from fastai import * from fastai.data import…

[deleted]

Re: How to build your own neural network from scratch in Python

#14
post #7

Nah, let's make that 10 lines: https://gist.github.com/vesche/72dafed33d614710f03f1b75cff1c... I got a beer for anyone who can golf it under 5 lines

Sure! Optimizing for number of lines (instead of number of characters):

* Remove 'import numpy as n' and use __import__('numpy') in place of it everywhere

* Remove s and d functions; inline them where they're called

* Get rid of 'class N', as it's unnecessary. If adding globals is cheating, then you can do '__import__('math').x = x' instead of 'self.x = x' (yes this will work and persist).

* Technically, you don't have to print the result at the end

Where do I go for my beer?

Re: How to build your own neural network from scratch in Python

#16
post #2

Too often you see articles like this and they start with $ import a_whole_bunch_of_stuff Good to see that this is not the case here :) The fast.ai course has a similar exercise in the beginning, but you'll still import the weights from somewhere else. Their fast.ai v1 library has a very short implementation too (loading the MINIST example dataset and then using Resnet18): from fastai import * from fastai.data import…

It's not mentioned in the article but he is importing numpy.

It has around 100k LOC.

Re: How to build your own neural network from scratch in Python

#17
post #2

Too often you see articles like this and they start with $ import a_whole_bunch_of_stuff Good to see that this is not the case here :) The fast.ai course has a similar exercise in the beginning, but you'll still import the weights from somewhere else. Their fast.ai v1 library has a very short implementation too (loading the MINIST example dataset and then using Resnet18): from fastai import * from fastai.data import…

How is your example not "$ import a_whole_bunch_of_stuff"?

should've been more explicit - deleted that part accidentally in an early edit, but yeah, that's what I would've expected, an 'import from' at the beginning

Re: How to build your own neural network from scratch in Python

#18
post #2

Too often you see articles like this and they start with $ import a_whole_bunch_of_stuff Good to see that this is not the case here :) The fast.ai course has a similar exercise in the beginning, but you'll still import the weights from somewhere else. Their fast.ai v1 library has a very short implementation too (loading the MINIST example dataset and then using Resnet18): from fastai import * from fastai.data import…

It's not mentioned in the article but he is importing numpy. It has around 100k LOC.

numpy is considered a low-level backbone of data science on Python; re-writing it would be equivalent to re-writing the "print" function.

OP is probably referring to somebody importing a high-level class that does something complex (auto-differentiation etc.)

Re: How to build your own neural network from scratch in Python

#19
post #7

Nah, let's make that 10 lines: https://gist.github.com/vesche/72dafed33d614710f03f1b75cff1c... I got a beer for anyone who can golf it under 5 lines

Naive solution (1 line): https://gist.github.com/applecrazy/deda2fac6e83c07b93e001731... Edit: I literally took newlines, converted to \n in a string, and then exec()ed the whole thing. Here's a repl of it working: https://repl.it/@applecrazy/Code-Golfing-a-Neural-Net

Oh dear, I got played.

PM address if you want the beer, you sly dog. Obligatory, I'm a normal dude: http://vesche.github.io/

Edit: Wait, you can't PM on here... PM on reddit /u/vesche

Re: How to build your own neural network from scratch in Python

#20
post #7

Nah, let's make that 10 lines: https://gist.github.com/vesche/72dafed33d614710f03f1b75cff1c... I got a beer for anyone who can golf it under 5 lines

Sure! Optimizing for number of lines (instead of number of characters): * Remove 'import numpy as n' and use __import__('numpy') in place of it everywhere * Remove s and d functions; inline them where they're called * Get rid of 'class N', as it's unnecessary. If adding globals is cheating, then you can do '__import__('math').x = x' instead of 'self.x = x' (yes this will work and persist). * Technically, you don't ha…

https://i.imgur.com/DpSQVCh.png
Post reply on HN