




























































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





























































































Here are the course summary as its given on the course link:
If you want to break into cutting-edge AI, this course will help you do so. Deep learning engineers are highly sought after, and mastering deep learning will give you numerous new career opportunities. Deep learning is also a new "superpower" that will let you build AI systems that just weren't possible a few years ago.
In this course, you will learn the foundations of deep learning. When you finish this class, you will:
Understand the major technology trends driving Deep Learning Be able to build, train and apply fully connected deep neural networks Know how to implement efficient (vectorized) neural networks Understand the key parameters in a neural network's architecture
This course also teaches you how Deep Learning actually works, rather than presenting only a cursory or surface-level description. So after completing it, you will be able to apply deep learning to a your own applications. If you are looking for a job in AI, after this course you will also be able to answer basic interview questions.
Be able to explain the major trends driving the rise of deep learning, and understand where and how it is applied today.
Single neuron == linear regression without applying activation(perceptron)
Basically a single neuron will calculate weighted sum of input(W.T*X) and then we can set a threshold to predict output in a perceptron. If weighted sum of input cross the threshold, perceptron fires and if not then perceptron doesn't predict.
Perceptron can take real values input or boolean values.
Actually, when w⋅x+b=0 the perceptron outputs 0.
Disadvantage of perceptron is that it only output binary values and if we try to give small change in weight and bais then perceptron can flip the output. We need some system which can modify the output slightly according to small change in weight and bias. Here comes sigmoid function in picture.
If we change perceptron with a sigmoid function, then we can make slight change in output.
e.g. output in perceptron = 0, you slightly changed weight and bias, output becomes = 1 but actual output is 0.7. In case of sigmoid, output1 = 0, slight change in weight and bias, output = 0.7.
If we apply sigmoid activation function then Single neuron will act as Logistic Regression.
we can understand difference between perceptron and sigmoid function by looking at sigmoid function graph.
Simple NN graph:
Image taken from tutorialspoint.com
RELU stands for rectified linear unit is the most popular activation function right now that makes deep NNs train faster now.
Hidden layers predicts connection between inputs automatically, thats what deep learning is good at.
Deep NN consists of more hidden layers (Deeper layers)
Image taken from opennn.net
Each Input will be connected to the hidden layer and the NN will decide the connections.
Supervised learning means we have the (X,Y) and we need to get the function that maps X to Y.
Different types of neural networks for supervised learning which includes: CNN or convolutional neural networks (Useful in computer vision) RNN or Recurrent neural networks (Useful in Speech recognition or NLP) Standard NN (Useful for Structured data) Hybrid/custom NN or a Collection of NNs types Structured data is like the databases and tables. Unstructured data is like images, video, audio, and text. Structured data gives more money because companies relies on prediction on its big data.
Deep learning is taking off for 3 reasons:
i. Data: Using this image we can conclude:
For small data NN can perform as Linear regression or SVM (Support vector machine) For big data a small NN is better that SVM For big data a big NN is better that a medium NN is better that small NN. Hopefully we have a lot of data because the world is using the computer a little bit more Mobiles IOT (Internet of things) ii. Computation: GPUs. Powerful CPUs. Distributed computing. ASICs iii. Algorithm: a. Creative algorithms has appeared that changed the way NN works. For example using RELU function is so much better than using SIGMOID function in training a NN because it helps with the vanishing gradient problem.
The actual equations we will implement:
w = w - alpha * d(J(w,b) / dw) (how much the function slopes in the w direction) b = b - alpha * d(J(w,b) / db) (how much the function slopes in the d direction)
We will talk about some of required calculus. You don't need to be a calculus geek to master deep learning but you'll need some skills from it. Derivative of a linear line is its slope. ex. f(a) = 3a d(f(a))/d(a) = 3 if a = 2 then f(a) = 6 if we move a a little bit a = 2.001 then f(a) = 6.003 means that we multiplied the derivative (Slope) to the moved area and added it to the last result.
f(a) = a^2 ==> d(f(a))/d(a) = 2a a = 2 ==> f(a) = 4 a = 2.0001 ==> f(a) = 4.0004 approx. f(a) = a^3 ==> d(f(a))/d(a) = 3a^ f(a) = log(a) ==> d(f(a))/d(a) = 1/a To conclude, Derivative is the slope and slope is different in different points in the function thats why the derivative is a function.
Its a graph that organizes the computation from left to right.
Calculus chain rule says: If x -> y -> z (x effect y and y effects z) Then d(z)/d(x) = d(z)/d(y) * d(y)/d(x) The video illustrates a big example.
We compute the derivatives on a graph from right to left and it will be a lot more easier. dvar means the derivatives of a final output variable with respect to various intermediate quantities.
In the video he discussed the derivatives of gradient decent example for one sample with two features x1 and x.
Lets say we have these variables:
X1 Feature X2 Feature W1 Weight of the first feature. W2 Weight of the second feature. B Logistic Regression parameter. M Number of training examples Y(i) Expected output of i
So we have:
Then from right to left we will calculate derivations compared to the result:
d(a) = d(l)/d(a) = -(y/a) + ((1-y)/(1-a)) d(z) = d(l)/d(z) = a - y d(W1) = X1 * d(z) d(W2) = X2 * d(z) d(B) = d(z)
From the above we can conclude the logistic regression pseudo code:
J = 0; dw1 = 0; dw2 =0; db = 0; # Devs. w1 = 0; w2 = 0; b=0; # Weights for i = 1 to m
z(i) = W1x1(i) + W2x2(i) + b a(i) = Sigmoid(z(i)) J += (Y(i)log(a(i)) + (1-Y(i))log(1-a(i)))
dz(i) = a(i) - Y(i) dw1 += dz(i) * x1(i) dw2 += dz(i) * x2(i) db += dz(i) J /= m dw1/= m dw2/= m db/= m
w1 = w1 - alpa * dw w2 = w2 - alpa * dw b = b - alpa * db
The above code should run for some iterations to minimize error.
So there will be two inner loops to implement the logistic regression.
Vectorization is so important on deep learning to reduce loops. In the last code we can make the whole loop in one step using vectorization!
Deep learning shines when the dataset are big. However for loops will make you wait a lot for a result. Thats why we need vectorization to get rid of some of our for loops.
kaggle.com is a good place for datasets and competitions. Pieter Abbeel is one of the best in deep reinforcement learning.
Learn to build a neural network with one hidden layer, using forward propagation and backpropagation.
In logistic regression we had:
X1 X2 ==> z = XW + B ==> a = Sigmoid(z) ==> l(a,Y) X3 /
In neural networks with one layer we will have:
X1 X2 => z1 = XW1 + B1 => a1 = Sigmoid(z1) => z2 = a1W2 + B2 => a2 = Sigmoid(z2) => l(a2,Y) X3 /
X is the input vector (X1, X2, X3) , and Y is the output variable (1x1)
NN is stack of logistic regression objects.
We will define the neural networks that has one hidden layer. NN contains of input layers, hidden layers, output layers. Hidden layer means we cant see that layers in the training set. a0 = x (the input layer) a1 will represent the activation of the hidden neurons. a2 will represent the output layer. We are talking about 2 layers NN. The input layer isn't counted.
Equations of Hidden layers:
Here are some informations about the last image: noOfHiddenNeurons = 4 Nx = 3 Shapes of the variables: W1 is the matrix of the first hidden layer, it has a shape of (noOfHiddenNeurons,nx) b1 is the matrix of the first hidden layer, it has a shape of (noOfHiddenNeurons,1) z1 is the result of the equation z1 = W1X + b , it has a shape of (noOfHiddenNeurons,1) a1 is the result of the equation a1 = sigmoid(z1) , it has a shape of (noOfHiddenNeurons,1) W2 is the matrix of the second hidden layer, it has a shape of (1,noOfHiddenNeurons) b2 is the matrix of the second hidden layer, it has a shape of (1,1) z2 is the result of the equation z2 = W2a1 + b , it has a shape of (1,1) a2 is the result of the equation a2 = sigmoid(z2) , it has a shape of (1,1)
Pseudo code for forward propagation for the 2 layers NN:
for i = 1 to m z[1, i] = W1x[i] + b1 # shape of z[1, i] is (noOfHiddenNeurons,1) a[1, i] = sigmoid(z[1, i]) # shape of a[1, i] is (noOfHiddenNeurons,1) z[2, i] = W2a[1, i] + b2 # shape of z[2, i] is (1,1) a[2, i] = sigmoid(z[2, i]) # shape of a[2, i] is (1,1)
Lets say we have X on shape (Nx,m). So the new pseudo code:
Z1 = W1X + b1 # shape of Z1 (noOfHiddenNeurons,m) A1 = sigmoid(Z1) # shape of A1 (noOfHiddenNeurons,m) Z2 = W2A1 + b2 # shape of Z2 is (1,m) A2 = sigmoid(Z2) # shape of A2 is (1,m)
If you notice always m is the number of columns.
In the last example we can call X = A0. So the previous step can be rewritten as:
Z1 = W1A0 + b1 # shape of Z1 (noOfHiddenNeurons,m) A1 = sigmoid(Z1) # shape of A1 (noOfHiddenNeurons,m) Z2 = W2A1 + b2 # shape of Z2 is (1,m) A2 = sigmoid(Z2) # shape of A2 is (1,m)
So far we are using sigmoid, but in some cases other functions can be a lot better. Sigmoid can lead us to gradient decent problem where the updates are so low. Sigmoid activation function range is [0,1] A = 1 / (1 + np.exp(-z)) # Where z is the input matrix Tanh activation function range is [-1,1] (Shifted version of sigmoid function)
In NumPy we can implement Tanh using one of these methods: A = (np.exp(z) - np.exp(-z)) / (np.exp(z) + np.exp(-z)) # Where z is the input matrix
Or A = np.tanh(z) # Where z is the input matrix
It turns out that the tanh activation usually works better than sigmoid activation function for hidden units because the mean of its output is closer to zero, and so it centers the data better for the next layer. Sigmoid or Tanh function disadvantage is that if the input is too small or too high, the slope will be near zero which will cause us the gradient decent problem. One of the popular activation functions that solved the slow gradient decent is the RELU function. RELU = max(0,z) # so if z is negative the slope is 0 and if z is positive the slope remains linear. So here is some basic rule for choosing activation functions, if your classification is between 0 and 1, use the output activation as sigmoid and the others as RELU. Leaky RELU activation function different of RELU is that if the input is negative the slope will be so small. It works as RELU but most people uses RELU. Leaky_RELU = max(0.01z,z) #the 0.01 can be a parameter for your algorithm. In NN you will decide a lot of choices like: No of hidden layers. No of neurons in each hidden layer. Learning rate. (The most important parameter) Activation functions. And others.. It turns out there are no guide lines for that. You should try all activation functions for example.
If we removed the activation function from our algorithm that can be called linear activation function. Linear activation function will output linear activations Whatever hidden layers you add, the activation will be always linear like logistic regression (So its useless in a lot of complex problems) You might use linear activation function in one place - in the output layer if the output is real numbers (regression problem). But even in this case if the output value is non-negative you could use RELU instead.
Derivation of Sigmoid activation function:
g(z) = 1 / (1 + np.exp(-z)) g'(z) = (1 / (1 + np.exp(-z))) * (1 - (1 / (1 + np.exp(-z)))) g'(z) = g(z) * (1 - g(z))
Derivation of Tanh activation function:
How we derived the 6 equations of the backpropagation:
In logistic regression it wasn't important to initialize the weights randomly, while in NN we have to initialize them randomly.
If we initialize all the weights with zeros in NN it won't work (initializing bias with zero is OK):
all hidden units will be completely identical (symmetric) - compute exactly the same function on each gradient descent iteration all the hidden units will always update the same
To solve this we initialize the W's with a small random numbers:
W1 = np.random.randn((2,2)) * 0.01 # 0.01 to make it small enough b1 = np.zeros((2,1)) # its ok to have b as zero, it won't get us to the symmetry breaking problem
We need small values because in sigmoid (or tanh), for example, if the weight is too large you are more likely to end up even at the very start of training with very large values of Z. Which causes your tanh or your sigmoid activation function to be saturated, thus slowing down learning. If you don't have any sigmoid or tanh activation functions throughout your neural network, this is less of an issue.
Constant 0.01 is alright for 1 hidden layer networks, but if the NN is deep this number can be changed but it will always be a small number.
Understand the key computations underlying deep learning, use them to build and train deep neural networks, and apply it to computer vision.
Shallow NN is a NN with one or two layers. Deep NN is a NN with three or more layers. We will use the notation L to denote the number of layers in a NN. n[l] is the number of neurons in a specific layer l. n[0] denotes the number of neurons input layer. n[L] denotes the number of neurons in output layer. g[l] is the activation function. a[l] = gl w[l] weights is used for z[l] x = a[0] , a[l] = y' These were the notation we will use for deep neural network. So we have: A vector n of shape (1, NoOfLayers+1) A vector g of shape (1, NoOfLayers) A list of different shapes w based on the number of neurons on the previous and the current layer. A list of different shapes b based on the number of neurons on the current layer.
Forward propagation general rule for one input:
z[l] = W[l]a[l-1] + b[l] a[l] = gl
Forward propagation general rule for m inputs:
Z[l] = W[l]A[l-1] + B[l] A[l] = gl
We can't compute the whole layers forward propagation without a for loop so its OK to have a for loop here.
The dimensions of the matrices are so important you need to figure it out.
The best way to debug your matrices dimensions is by a pencil and paper. Dimension of W is (n[l],n[l-1]). Can be thought by right to left. Dimension of b is (n[l],1) dw has the same shape as W , while db is the same shape as b Dimension of Z[l], A[l] , dZ[l] , and dA[l] is (n[l],m)
Why deep NN works well, we will discuss this question in this section. Deep NN makes relations with data from simpler to complex. In each layer it tries to make a relation with the previous layer. E.g.: a. Face recognition application: Image ==> Edges ==> Face parts ==> Faces ==> desired face b. Audio recognition application: Audio ==> Low level sound features like (sss,bb) ==> Phonemes ==> Words ==> Sentences Neural Researchers think that deep neural networks "think" like brains (simple ==> complex) Circuit theory and deep learning:
When starting on an application don't start directly by dozens of hidden layers. Try the simplest solutions (e.g. Logistic Regression), then try the shallow neural network and so on.
Forward and back propagation for a layer l:
Deep NN blocks:
Basic Recipe for Machine Learning
Regularization
||W|| = Sum(|w[i,j]|) # sum of absolute values of all w
||W||^2 = Sum(|w[i,j]|^2) # sum of all w squared
Other regularization methods
Normalizing inputs
Vanishing / Exploding gradients
Y' = W[L]W[L-1].....W[2]W[1]X
if W[l] = [1.5 0] [0 1.5] (l != L because of different dimensions in the output layer) Y' = W[L] [1.5 0]^(L-1) X = 1.5^L # which will be very large [0 1.5]
if W[l] = [0.5 0] [0 0.5] Y' = W[L] [0.5 0]^(L-1) X = 0.5^L # which will be very small [0 0.5]
Weight Initialization for Deep Networks
np.random.rand(shape) * np.sqrt(1/n[l-1])
np.random.rand(shape) * np.sqrt(2/(n[l-1] + n[l]))
np.random.rand(shape) * np.sqrt(2/n[l-1])
Numerical approximation of gradients
X{1} = 0 ... 1000 X{2} = 1001 ... 2000 ... X{bs} = ...
for t = 1:No_of_batches # this is called an epoch AL, caches = forward_prop(X{t}, Y{t}) cost = compute_cost(AL, Y{t}) grads = backward_prop(AL, caches) update_parameters(grads)
Exponentially weighted averages
t(1) = 40 t(2) = 49 t(3) = 45 ... t(180) = 60 ...
V0 = 0 V1 = 0.9 * V0 + 0.1 * t(1) = 4 # 0.9 and 0.1 are hyperparameters V2 = 0.9 * V1 + 0.1 * t(2) = 8. V3 = 0.9 * V2 + 0.1 * t(3) = 12. ...
V(t) = beta * v(t-1) + (1-beta) * theta(t)