Tensorflow Ensai SID 13 01 17
Tensorflow Ensai SID 13 01 17
Fabien Baradel
PhD Candidate
fabienbaradel.github.io
@fabienbaradel
[email protected]
DEEP LEARNING? 2
TENSORFLOW?
TENSORFLOW BACKGROUND 3
Video = sequence of
Microsoft Kinect v2: frames
Skeleton not enough
• 3D joint location
(looking at book, looking at
• 25 joints smartphone)
SELF-DRIVING CARS 7
Tesla
• https://www.youtube.com/watch?v=CxanE_W46ts
MATERIALS 8
INTRODUCTION
WHAT IS TENSORFLOW? 11
• A python library
• pip install tensorflow
• Google
• open-source
• library for numerical computation
using data flow graphs
• CPU and GPU
• Research & Industry
PRINCIPLE 12
« HELLO WOLRD » 13
• INTRODUCTION EXERCISES
• Tensorflow workflow:
• Draw your graph
• Feed data
• … and optimize
« BASIC MATHS OPERATIONS » 14
• Open « math_ops.py »
• Same thing with integer
• Mathematical operation done
only using Tensorflow library (no
numpy or else)
• Draw the schema of the code
Linear regression y = X +✏
ˆ = (X T X) 1
XT Y
• Initialize ˆ0 randomly
• Choose a learning rate ⌘
• for t in range(training_step):
• Compute the loss
N
X
J( ˆt ) = (Xi ˆt yi ) 2
i=1
• Update parameters
ˆt+1 = ˆt ⌘rJ( ˆt )
https://jalammar.github.io/visual-interactive-guide-basics-neural-networks/#train-your-dragon
MINI-BATCH SGD 18
i2Stn
Neural nets always trained
• Update parameters with mini-batch SGD!
ˆt+1 = ˆt ⌘rJ( ˆt )
EXERCISES 19
http://playground.tensorflow.org/
https://wookayin.github.io/TensorflowKR-2016-talk-debugging/
20
NEURAL NETWORKS
MNIST DATASET 21
• Handwritten digits
• 60.000 training data and 10.000 test data
• 28x28 grayscale images
• matrix of size 28x28 with value between 0 and 255
• data preprocessing = rescaling to [0,1]
MULTINOMIAL LOGISTIC REGRESSION ON MNIST:
CREATE THE GRAPH 22
logits predictions
label
c
W
vectorization learnable parameter softmax
10x1 28x28
10
784
Compute cross-entropy
c) =
J(W y ⇥ log(ŷ)
WHY LOG?
http://colah.github.io/posts/2015-09-Visual-Information/
MULTINOMIAL LOGISTIC REGRESSION ON MNIST:
CREATE THE GRAPH 23
images t=0
logits predictions labels
ct
W
vectorization learnable parameter softmax
10
10
784
X
Compute ct ) =
J(W yi ⇥ log(yˆi )
cross-entropy
i2St2
c updated [ c ct )
Wt by SGD W t+1 = W t ⌘rJ(W
MULTINOMIAL LOGISTIC REGRESSION ON MNIST:
FEED DATA 24
images t=1
logits predictions labels
ct
W
vectorization learnable parameter softmax
28x28
10 10
10
784
X
Compute ct ) =
J(W yi ⇥ log(yˆi )
cross-entropy
i2St2
c updated [ c ct )
Wt by SGD W t+1 = W t ⌘rJ(W
MULTINOMIAL LOGISTIC REGRESSION ON MNIST:
FEED DATA 25
images t=2
logits predictions labels
ct
W
vectorization learnable parameter softmax
28x28
10 10
10
784
X
Compute ct ) =
J(W yi ⇥ log(yˆi )
cross-entropy
i2St2
c updated [ c ct )
Wt by SGD W t+1 = W t ⌘rJ(W
NEURAL NETWORKS 26
0 1 0 1
✓ yb1
B yb2 C
0
B1C
B C Error B C
B yb3 C B0C
FUNCTION B C B C
@ ... A @...A
yc10
0
input
inference function output label
ŷ = f (✓, x)
J(✓) = error(ŷ, y) given ✓
✓ˆ = argmin J(✓)
And train it using mini-batch SGD!
NEURAL NETWORKS IN TENSORFLOW:
GENERAL GRAPH 27
placeholder placeholder
0 1
✓ 0
yc
c1
1 ?
B yc C Error B?C
FUNCTION B Cc 2 B C
@ ... A @...A
yccn ?
inference function output
input
label
labels
labels
labels
X f✓ ŷ y
https://medium.com/@karpathy/yes-you-should-understand-backprop-e2f06eab496b#.l8cz02hlu
BACKPROPAGATION 32
forward pass
X f✓ ŷ y
https://medium.com/@karpathy/yes-you-should-understand-backprop-e2f06eab496b#.l8cz02hlu
BACKPROPAGATION 33
error
X f✓ ŷ y
https://medium.com/@karpathy/yes-you-should-understand-backprop-e2f06eab496b#.l8cz02hlu
BACKPROPAGATION 34
X f✓ ŷ y
https://medium.com/@karpathy/yes-you-should-understand-backprop-e2f06eab496b#.l8cz02hlu
BACKPROPAGATION 35
forward pass
error
X f✓ ŷ y
https://medium.com/@karpathy/yes-you-should-understand-backprop-e2f06eab496b#.l8cz02hlu
EXERCISES 36
• Go here: https://github.com/fabienbaradel/Tensorflow-tutorials
• And do the softmax and multilayer perceptron exercises
37
CONVOLUTIONAL NETWORKS
CONVNET 38
• Computer vision
• NLP
• Artificiel Intelligence
http://dl.heeere.com/convolution3/
POOLING 41
• Dimension reduction
• No learnable parameters!
AlexNet (2012)
80.1 %
93.4 %
CONVNETS 43
EXERCISES 44
https://www.youtube.com/watch?v=AgkfIQ4IGaM
FINE-TUNING 50
FROZEN FINETUNED
0 1
v1
DIMENSION REDUCTION v( = @ ... A
v2048
EXERCISE 52
AUTOENCODER
NEURAL NETWORK LEARNING 54
X f Y
Supervised learning
‣ y are given !
X X
f Z g
Unsupervised learning
‣ y is no longer needed
AUTOENCODER 55
X X
f Z g
encoder latent decoder
X X
f Z g
encoder latent decoder
GENERATIVE MODELS
GENERATIVE MOMENT MATCHING NETWORKS58
X X’
f Z g
encoder latent decoder RMSE
X
GENERATIVE MOMENT MATCHING NETWORKS59
Z
GENERATED
predicted latent
N(0,1)
GENERATIVE MOMENT MATCHING NETWORKS60
Z latent
MMD
X
f Z
GENERATED
predicted latent
encoder
N(0,1)
GENERATIVE MOMENT MATCHING NETWORKS61
X
Z
GENERATED
g GENERATED
decoder
N(0,1)
GENERATIVE MOMENT MATCHING NETWORKS62
latent
X
f Z
encoder ~
~
X
latent Z
GENERATED
g GENERATED
decoder
N(0,1)
GENERATIVE ADVERSIAL NETWORKS 63
Intuition
Intuition
FAKE
OR
REAL?
FAKE
OR
REAL?
real money
GENERATIVE ADVERSIAL NETWORKS 65
Z G D Y
http://blog.aylien.com/introduction-generative-adversarial-networks-code-tensorflow/
GAN: EXAMPLES 66
GAN: EXAMPLES 67
GAN: EXAMPLES 68
Ongoing topic…
EXERCISE 69
SEQUENCE MODELING
WHAT ABOUT SEQUENCE? 71
Sequence to sequence:
Machine Translation
RECURRENT NEURAL NETWORK 73
http://colah.github.io/posts/2015-08-Understanding-LSTMs/
http://karpathy.github.io/2015/05/21/rnn-effectiveness/
RNN AND CLASSIFICATION 74
RNN
RNN AND CLASSIFICATION 75
H_0
H_0
X_1 H_1
H_0
H_N-1
H_N
X_n RNN
RNN AND CLASSIFICATION 78
H_0
H_N-1
H_N classif
X_n RNN Y
WORD2VEC 79
TF-IDF?
100
Italy = (5.12, 7.21, ..., 0.78) 2 R
TF-IDF?
100
Italy = (5.12, 7.21, ..., 0.78) 2 R
TF-IDF?
100
Italy = (5.12, 7.21, ..., 0.78) 2 R
=
RNN ON MNIST 83
=
RNN ON MNIST 84
=
RNN ON MNIST 85
=
RNN ON MNIST 86
RL = Reinforcement Learning
RL: FEW EXAMPLES 90
https://www.youtube.com/watch?v=V1eYniJ0Rnk
RL IN A FINITE STATE SPACE 91
st at st , st+1 2 S
st+1
at 2 A(st )
t = 0, 1, 2, ...
rt+1
FROZEN LAKE EXAMPLE 92
2 3
S F F F F = frozen surface, safe
6F H F H7 G = goal, where the frisbee is located
6 7
4F F F H5 S = starting point, safe
H F F G H = hole, fall to your doom
• Possible actions:
- Up
- Down
- Left
- Right
Ice is slippery: you won’t always move in the direction you intend
RL: DEFINITIONS 93
The agent learns to assign values to state-action pairs
Discounted return:
2 T 1
Rt = rt+1 + rt+2 + rt+3 + ... + rT
where 2 [0; 1] is the discount rate
Q value function
2 3
Q(0, Up, ✓t ) Q(0, Down, ✓t ) Q(0, Left, ✓t ) Q(0, Right, ✓t )
6 Q(1, Up, ✓t ) Q(1, Down, ✓t ) Q(1, Left, ✓t ) Q(1, Right, ✓t ) 7
Q ✓t =6
4
7
5
... ... ... ...
Q(15, Up, ✓t ) Q(15, Down, ✓t ) Q(15, Left, ✓t ) Q(15, Right, ✓t )
Loss function
X
2
J(✓t ) = (Q(st , at , ✓t ) rt+1 + ⇥ max Q(st+1 , at+1 , ✓t ))
at+1
W Qup
Qdown argmax
S Q A
Qright
state from 0 to 15 Qlef t action
DEEP Q-FUNCTION FOR REAL GAMES 97