deep learning - BGU · 2018-12-25 · Deep Learning • Logistic Regression • Neural Network •...

21
Deep Learning Intro to neural networks using Theano and deep learning examples

Transcript of deep learning - BGU · 2018-12-25 · Deep Learning • Logistic Regression • Neural Network •...

Page 1: deep learning - BGU · 2018-12-25 · Deep Learning • Logistic Regression • Neural Network • Autoencoders Example • Recursive Neural Network Example

Deep LearningIntro to neural networks using Theano and deep learning examples

Page 2: deep learning - BGU · 2018-12-25 · Deep Learning • Logistic Regression • Neural Network • Autoencoders Example • Recursive Neural Network Example

Deep Learning

• Logistic Regression

• Neural Network

• Autoencoders Example

• Recursive Neural Network Example

Page 3: deep learning - BGU · 2018-12-25 · Deep Learning • Logistic Regression • Neural Network • Autoencoders Example • Recursive Neural Network Example

Logistic Regression• probabilistic, linear classifier

• parametrized by a weight matrix W and a bias vector b

!

!

!

• SoftMax a generalisation of the logistic function

X1

X2

X3

X4

X5

SoftMax(Wx+b)

Page 4: deep learning - BGU · 2018-12-25 · Deep Learning • Logistic Regression • Neural Network • Autoencoders Example • Recursive Neural Network Example

Logistic Regression - Theano Code• x = T.fmatrix(‘x’)

• y = T.lvector('y')

• b = theano.shared(numpy.zeros((10,)), name=‘b')

• W = theano.shared(numpy.zeros((784, 10)), name=‘W')

• p_y_given_x = T.nnet.softmax(T.dot(x, W) + b)

• get_p_y_given_x = theano.function(inputs=[x], outputs=p_y_given_x)

• print 'Probability that x is of class %i is %f' % (i, get_p_y_given_x(x_value)[i])

• y_pred = T.argmax(p_y_given_x, axis=1)

• classify = theano.function(inputs=[x], outputs=y_pred)

Page 5: deep learning - BGU · 2018-12-25 · Deep Learning • Logistic Regression • Neural Network • Autoencoders Example • Recursive Neural Network Example

Logistic Regression - Loss Function• use the negative log-likelihood as the loss

!

!

• loss = -T.mean(T.log(p_y_given_x)[T.arange(y.shape[0]), y])

• T.log(p_y_given_x) is a matrix of all classes probability for all the bathes !

• [T.arange(y.shape[0]), y] selects the correct class for each batch

Page 6: deep learning - BGU · 2018-12-25 · Deep Learning • Logistic Regression • Neural Network • Autoencoders Example • Recursive Neural Network Example

Logistic Regression - Learning W and B• Use gradient decent to maximize the probability of our dataset on W

and B

• cost = classifier.negative_log_likelihood(y)

• g_W = T.grad(cost, classifier.W)

• g_b = T.grad(cost, classifier.b)

• updates = [(classifier.W, classifier.W - learning_rate * g_W),

• (classifier.b, classifier.b - learning_rate * g_b)]

Page 7: deep learning - BGU · 2018-12-25 · Deep Learning • Logistic Regression • Neural Network • Autoencoders Example • Recursive Neural Network Example

Logistic Regression

• More info and all the coed could be found here: http://deeplearning.net/tutorial/logreg.html#logreg

Page 8: deep learning - BGU · 2018-12-25 · Deep Learning • Logistic Regression • Neural Network • Autoencoders Example • Recursive Neural Network Example

Neural Networks

Page 9: deep learning - BGU · 2018-12-25 · Deep Learning • Logistic Regression • Neural Network • Autoencoders Example • Recursive Neural Network Example

Neural Network!

• Output:

!

• Where s is:

!

• or

Page 10: deep learning - BGU · 2018-12-25 · Deep Learning • Logistic Regression • Neural Network • Autoencoders Example • Recursive Neural Network Example

Neural Network - L1 and L2 Regularization• L1 and L2 regularization involve adding an extra term to the loss function

• L1 = T.sum(abs(param))

• L2_sqr = T.sum(param ** 2)

• loss = NLL + lambda_1 * L1 + lambda_2 * L2_sqr

• The regularization keeps our network parameters low

• lambda_1 and lambda_2 are hyper paramaters with values ranging between 1 to 2

Page 11: deep learning - BGU · 2018-12-25 · Deep Learning • Logistic Regression • Neural Network • Autoencoders Example • Recursive Neural Network Example

Neural Network - Back Propagation

• Phase 1: Propagation:!

1.Forward propagation of a training pattern's input through the neural network in order to generate the propagation's output activations.

2.Backward propagation of the propagation's output activations through the neural network using the training pattern target in order to generate the deltas of all output and hidden neurons.

Page 12: deep learning - BGU · 2018-12-25 · Deep Learning • Logistic Regression • Neural Network • Autoencoders Example • Recursive Neural Network Example

Neural Network - Back Propagation

• Phase 2: Weight update: For each weight-synapse!

1.Multiply its output delta and input activation to get the gradient of the weight.

2.Subtract a ratio (percentage) of the gradient from the weight.

Page 13: deep learning - BGU · 2018-12-25 · Deep Learning • Logistic Regression • Neural Network • Autoencoders Example • Recursive Neural Network Example

Neural Network - Back Propagation

The Error Function The Actual Output Function

Page 14: deep learning - BGU · 2018-12-25 · Deep Learning • Logistic Regression • Neural Network • Autoencoders Example • Recursive Neural Network Example

Neural Network - Back Propagation

Page 15: deep learning - BGU · 2018-12-25 · Deep Learning • Logistic Regression • Neural Network • Autoencoders Example • Recursive Neural Network Example

Neural Network - Back Propagation

Updated Weight Learning Rate

Target Output

Input

Page 16: deep learning - BGU · 2018-12-25 · Deep Learning • Logistic Regression • Neural Network • Autoencoders Example • Recursive Neural Network Example

Autoencoders• An input layer. For example, in a

face recognition task, the neurons in the input layer could map to pixels in the photograph

• A number of considerably smaller hidden layers, which will form the encoding

• An output layer, where each neuron has the same meaning as in the input layer

X1

X2

X3

X4

X1

X2

X3

X4

Encoder Decoder

Page 17: deep learning - BGU · 2018-12-25 · Deep Learning • Logistic Regression • Neural Network • Autoencoders Example • Recursive Neural Network Example

Sentiment Analysis• Uses the sentence syntax to learn

phrases representation

• Learns from a tagged dataset of parsed phrases and sentiment

• Input is two phrases

• Output is the phrases and their sentiment

• Hidden layer learns the representation of the phrase

W1

W2

W1

W2

S

Page 18: deep learning - BGU · 2018-12-25 · Deep Learning • Logistic Regression • Neural Network • Autoencoders Example • Recursive Neural Network Example

Sentiment Analysis

Page 19: deep learning - BGU · 2018-12-25 · Deep Learning • Logistic Regression • Neural Network • Autoencoders Example • Recursive Neural Network Example

Sentiment Analysis

Page 20: deep learning - BGU · 2018-12-25 · Deep Learning • Logistic Regression • Neural Network • Autoencoders Example • Recursive Neural Network Example

Sentiment Analysis

• Online Demo: http://nlp.stanford.edu:8080/sentiment/rntnDemo.html

Page 21: deep learning - BGU · 2018-12-25 · Deep Learning • Logistic Regression • Neural Network • Autoencoders Example • Recursive Neural Network Example

Questions?