Hello.
Welcome back.
In this lesson where are you going to build our multilayered neural network.
I'm going to open our mortal layer on the score and in script
Okay so this is simply a copy of our Trulia.
And then we are going to call the new functions we created in the previous lesson over here.
So we don't have to change much.
What we may need to change is uh we need to call our new parameter initialization function and object.
Oh okay.
I'm simply going to create a new function.
Course this is our model to layer and then model.
So I'm going to create a new function known as multilayer and then model and in that function I'm going
to call a 1 new initialize parameters multi-layer function and the other new functions we created.
Um.
So let's see let's see.
I'm going to in order to simplify what we have over here.
Some of these things will need them.
But I see them when I put this new function here I'm going to create a new function here actually.
Yeah.
Being a bit indecisive.
I'm just going to comment out the things that have to do with two layers.
Once we are done we just clean this from this script.
So comment this out right.
So there's the layer dimension.
We created this for the layer dimensions.
Okay.
This also we can clean this.
Okay.
So now we just have to read the data.
We run our pre processing including our normalization.
And yeah.
And then down here we check our wrong predictions and other things.
So I'm gonna come here and I'm gonna create a new function.
This function was called to layer in and model.
I'll call this 1 def
multi layer and then model right.
And this function is going to take our training set the Y labels.
The layer dimensions
lending rate
although we can initialize the learning rate to to um what did we have before.
Um yes.
I'm gonna take the linen rate that we'll use for the two layer as well as the number of into uh number
of iterations.
The default values.
I'm gonna paste them here like this.
Okay so this is going to be our new function.
Okay.
So let's start off by seeding our random number generator and Peter at random um we actually doing this
twice because when we call our parameter initialization function it cedes this so we can skip over this
one to create a create a list to hold costs like we did initially and then I'm going to call our function
a new function just the feed two of our library
okay.
Where's the function.
This is a initialize parameters multilayer I'll copy this and then I'm gonna call this function here.
And um let's declare the dimensions here.
I'm gonna have a list here layout dimensions
I hate using the same name for the argument and the variable of Python is so flexible so low dimensions
here.
Let's say we have we want to finally on your network.
We know the the size of our input image.
Um as we computed earlier it's sixty four multiplied by 64 multiplied by three.
That is the inputs there and this gives us what this gives us twelve thousand two hundred and eighty
eight.
So this is going to be the number of notes for the input layer twelve thousand two hundred and twenty
eight.
Let's see.
Right.
So we're going to have twelve thousand from zero to twelve thousand two hundred and eighty seven.
So if we add zero we have twelve thousand two hundred and eighty eight.
That's going to be the input layer but this is not our neural network.
This is the previous one.
This one here is the they are one in currently the one we are creating is gonna have any number of layers
we want.
So this is just to show you just the the number of nodes for the input.
We'll get the first aid in layer less if we wanted to have 20 nodes the one after that let's say we
wanted to have eight nodes to one after that let's say we wanted to have sex nodes and the last one.
1 so we have 1 2 3 4 5.
So you could say this this is if we want to count the other ones which we should experiment with.
So anyway our function Initialize parameters multilayer it's extra layer dimensions as its argument
the teams pass this over here and it returns it's returns at Pictionary court parameters which the weight
and bias values.
So I'm gonna store the return in this dictionary we call parameters once that is done I can start the
loop for gradient descent come over here.
So for I in range
starting from zero to the argument that you so pass known as number of iterations
and then we going to call our forward propagation
we performed for prop somewhere.
Um yeah let's go to our library we have a function for the
Where's the library.
This is a multilayer and then
we have a function somewhere module forward prop it takes two arguments The X which is the training
input and the parameters and when I copy this and it returns the E L and the cache to Ellis like the
Y hot activation of the final layer and the cache is just the things that we store Um so I'll copy this
function and I'm going to pass X over here
onto parameters over here and um I'm going to store the return in a variable call E L and another one
called caches
right.
Okay so once that's done we're going to compute the cost or simply call our computer cos the function
in this function takes y hat and y e l which is activation of the final layer is that what y hat and
we already have Y which is the labels of the training set going to store the results in a variable called
cost.
This single cost.
We have a list or on our record costs we shall append each single cost to these to this to create a
list of costs.
Right.
Okay.
So once that is done we can call our newly minted function the backward propagation function as computers.
So does the function model.
But it takes the e l y in the cache is going to copy this and I'm gonna come back here pasted over here
and I'm going to pass a L and then Y and then caches.
And this is going to return gradients.
I'm going to store it in a variable of a similar name gradient.
Right.
So after this we would have performed back propagation.
Once this is done we need to update our parameters.
So we simply call or update the parameters function.
Let's take a look at it
update parameters okay.
So it takes parameters gradients and the lending rate.
And then it just runs through the loop.
Okay I'm gonna copy this
put it over here.
The first document is parameters.
The second document gradient
the third argument is the lending rate that the user passes to the function.
There's a typo here and um this show return to New parameters.
So I should store it in the variable of a similar name parameters like this right.
And then we going to print the cost for every 100 iterations.
We can simply copy what we wrote to do the.
And then append it.
Okay.
So this is from our previous function at a function for the two.
I'm going to copy this and then bring it back here and then
take away the comment.
Okay.
Right.
Okay.
So once this is done we can print out the um the cost and return the parameters.
This the same as what we wrote for the 2 layer.
So I'm gonna copy this as well.
And I'm going to come over here on comment.
Right.
And this we have to make sure it's not in the for loop.
It's not.
Okay.
So this is how a model.
Now we can call it a model and see what we have
so how.
We test out this model in the next lesson.
Yeah.
Um but before we do that.
Okay.
I wanted to clean this up a bit but we can clean it up once we've tested it.
Okay I'll see you in the next list.