A Gentle Introduction To Neural Networks With Python
A Gentle Introduction To Neural Networks With Python
to Neural Networks
(with Python)
Tariq Rashid @postenterprise
EuroPython Bilbao July 2016
Background
Ideas
DIY
Handwriting
Thoughts
and a
live demo!
Background
+
+
+
+
+
+
2403343781289312
2843033712837981
2362142787897881
3256541312323213
9864479802118978
8976677987987897
8981257890087988
= ?
AI is Huge!
Googles and Go
Ideas
Kilometres to Miles
Kilometres to Miles
not great
Kilometres to Miles
better
Kilometres to Miles
worse !
Kilometres to Miles
best yet !
Key Points
1.
2.
xactly? Try
e
s
rk
o
w
g
in
how someth
w
o
n
k
.
t
n
o
D
parameters
le
b
ta
s
ju
d
a
model with
.
parameters
e
th
e
n
fi
re
or to
Use the err
Garden Bugs
Classifying Bugs
Classifying Bugs
Classifying Bugs
Classifying Bugs
Key Points
ings.
1.
Classifying
thing
th
predicting
e
k
li
a
d
in
k
s is
Example
Width
Length
Bug
3.0
1.0
ladybird
1.0
3.0
caterpillar
Hang On!
Oh no!
each update ignores
previous examples
A = L (E / x)
learning rate
Key Points
1.
you
d - ensures
o
o
g
is
g
in
your learn
pact of
im
s
e
c
u
d
Moderating
re
nd
your data, a
ll
a
m
o
fr
rn
lea
.
training data
y
is
o
n
r
o
outliers
Boolean Logic
Input A
Input B
AND
OR
Boolean Logic
Boolean Logic
XOR Puzzle!
Input A
Input B
XOR
XOR Solution!
Key Points
gle
ith just a sin
w
d
e
lv
o
s
e
nt b
roblems ca
p
e
m
o
S
1.
r classifier.
simple linea
g together to
in
rk
o
w
s
e
nod
e multiple
s
u
n
a
c
u
o
s.
2. Y
se problem
e
th
f
o
y
n
a
solve m
Brains in Nature
Brains in Nature
11,000 neurons
resilient
302 neurons
37 billion neurons
(humans 20 billion)
https://en.wikipedia.org/wiki/List_of_animals_by_number_of_neurons
https://faculty.washington.edu/chudler/facts.html
Brains in Nature
Brains in Nature
logistic function
y = 1 / (1 + e-x)
Brains in Nature
Artificial Neuron
Pause.
...
link weight?
Key Points
things, and
d
te
a
c
ti
is
h
do sop
ct
brains can
l
ra
and imperfe
tu
e
a
g
a
N
m
a
d
1.
to
ly resilient
are incredib
omputing.
c
l
a
n
io
it
d
a
like tr
signals .. un
d
artly inspire
p
s
in
ra
b
l
a
logic
to copy bio
g
in
ry
T
.
2
etworks.
n
l
a
r
u
e
n
l
artificia
its
arameter p
le
b
ta
s
ju
e ad
ights are th
e
w
k
in
L
s.
3.
ing happen
rn
a
le
e
th
where
Matrix Multiplication
Matrix Multiplication
weights
incoming signals
WI = X
dot product
Key Points
e
tions can b
la
u
lc
a
c
rd
a
no
iplication,
any feedforw
lt
m
u
e
m
h
T
ix
tr
a
.
1
as m
concisely
d
e
s
s
re
p
x
e
network.
e
th
e
p
a
h
s
t
matter wha
n do matrix
a
c
s
e
g
a
u
g
lan
.
rogramming
p
e
m
nd quickly
o
a
S
y
tl
n
2.
ie
ic
n really eff
multiplicatio
Network Error
Network Error
Internal Error
Internal Error
Matrices Again!
Key Points
we
guide how
to
r
o
r
r
e
e
th
ber we use
m
e
m
e
k weights.
R
n
li
.
r
1
te
e
m
dels para
refine a mo
e
is easy - th
s
e
d
o
n
t
u
tp
or at the ou
nd actual
a
d
e
ir
s
2. The err
e
d
etween the
difference b
outputs.
obvious. A
t
n
is
s
e
d
o
n
l
or at interna
portion to
rr
o
r
e
p
e
h
in
T
it
t
li
.
p
3
to s
pproach is
a
c
ti
is
r
u
e
h
hts.
the link weig
be
e error can
th
g
n
ti
a
g
a
back prop
too!
4. and
ultiplication
m
ix
tr
a
m
as a
expressed
Aaarrrggghhh !!
Gradient Descent
Key Points
e
of finding th
y
a
w
l
a
c
ti
c
a pra
t descent is
n
ie
d
a
r
G
1.
nctions.
fu
lt
u
c
fi
if
d
f
minimum o
by
rshooting
e
v
o
f
o
e
c
n
ha
shallower.
avoid the c
ts
n
e
a
g
c
t
u
n
o
ie
Y
d
ra
2.
eg
r steps if th
e
ll
a
m
s
g
in
tak
tion
ifficult func
d
a
is
rk
o
etw
nt
f a neural n
o
r
o
rr
dient desce
e
ra
e
g
h
e
b
y
a
3. T
m
eights so
of the link w
will help ...
Error Gradient
E = (desired - actual)2
dE/dwij = - ej . oj . (1 - oj) . oi
previous node
DIY
Neural Network
Class
Initialise
Train
Query
do the learning
matrix maths
numpy
scipy
matplotlib
notebook
Function - Initialise
numpy.random.normal()
Function - Query
numpy.dot()
Function - Train
update weights
Handwriting
MNIST Datasets
MNIST dataset:
60,000 training data examples
10,000 test data examples
MNIST Datasets
label
784 pixels
values
28 by 28 pixel image
Experiments
More Experiments
98%
is amazing!
Thoughts
Thanks!
live demo!
makeyourownneuralnetwork.blogspot.co.uk
github.com/makeyourownneuralnetwork
www.amazon.co.uk/dp/B01EER4Z4G
twitter.com/myoneuralnet
slides goo.gl/JKsb62
Raspberry Pi Zero