A Neural Network in 11 Lines of Python
iamtrask.github.io
iamtrask.github.io
import numpy as npLumpy Numpy FTW
import numpy as np
X = np.array([ [0,0,1],[0,1,1],[1,0,1],[1,1,1]])
y = np.array([[0,0,1,1]]).T
from keras.models import Sequential
from keras.layers.core import Dense
model = Sequential([Dense(3, 1, init='uniform', activation='sigmoid')])
model.compile(loss='mean_absolute_error', optimizer='sgd')
model.fit(X, y, nb_epoch=10000)
model.predict(X)
[1] http://keras.ioAlso, lines 22 and 23 in the three layer network are not intuitive for a beginner. Before, syn0 was (3,1) and now its (3,4), and the new syn1 is (4,1). Your previous explanation for this initialization was much better.
But again, awesome work, just being nitpicky. Really appreciate it!
https://triangleinequality.wordpress.com/2014/08/12/theano-a...
nonlin:{:[y;x*1-x;1%1+_exp -x]}
x:(0 0 1;0 1 1;1 0 1;1 1 1)
y:+,0 0 1 1
syn0:-0.5+3 1 _draw 0
step:{L1:nonlin[x _mul syn0;0]
L1err:y-L1
L1delta:L1err*nonlin[L1;1]
syn0+:(+x)_mul L1delta;L1}
do[10000;L1:step[x;y]]
L1
(,0.009668795
,0.007862982
,0.9935916
,0.9921171)
k3 does this in 140ms, Kona in 2030ms on the same machine.[1] https://en.wikipedia.org/wiki/Rectifier_(neural_networks)#Le...
I much rather read a book.
Fewer lines of code doesn't always equate to simple, comprehensible code.
http://docs.scipy.org/doc/numpy/reference/ufuncs.html
http://docs.scipy.org/doc/numpy/reference/routines.random.ht...
http://docs.scipy.org/doc/numpy/reference/generated/numpy.nd...
;)