‫In the last couple of videos we learn how to create neural network with get us sequential EPA the sequential
‫EPA was quite easy to use but it have some limitation with sequential EPA.
‫You can only create neural network with simply sequential architecture.
‫You cannot create complex typologies like this where you have multiple inputs or multiple outputs.
‫For that you have to use functional yet and functionally appear We create each of these layers in the
‫form of functions or you can see a building block of your neural network and you can use this functions
‫to create a complex structure by joining them according to your structure need before going into details.
‫Let's first build the model that we created in our last lecture.
‫Just very well and you're more than.
‫And then you will also need to clear the session off your gave us this will free up the resources for
‫our next model training.
‫So just start get US DoD backing not only of session
‫run this to now we are ready to create and train our next model for functional API we will be using
‫this example this kind of neural network is known as vide and deep neural network deep because of what
‫input is going through to layers of dense hidden layer and wide because of what input is directly going
‫for output as well.
‫So along with the output of this hidden layers it also connect all parts of our input directly to the
‫output layer
‫this linkage which I have my best right is not possible when we are using sequential API
‫the advantage of this architecture is that it makes possible for a neural network to learn both the
‫deep patterns by this deep linkage and the simple rules by this wide linkage in our regular MLP more
‫than all the data flows through this full stacks of dense layers and thus some simple patterns in their
‫data may end up being distorted by the sequence of this transformation.
‫So now let's create this leads one by one we will be using the same dataset as we use for our last lecture.
‫First we need to create the input layer we are calling it input and we are creating it with get us lot
‫layers not input and then we have to provide the shape we can either write just it in decades because
‫we have eight independent variables or we can write it in this way extreme dot shape and then the first
‫and so on attribute.
‫So this is our input layer we will create this kind of layers and then we will connect these layers
‫accordingly.
‫So next we create a dense layer with 30 neurons using the railway activation and you can also notice
‫that we are calling this input player like a function.
‫So this input layer is an input for this hidden layer 1 and we are calling it like a function and that's
‫why we call it functional EPA.
‫We create this kind of layers and we use these layers as functions for our next players so we have connected
‫our input layer our crude on there to now we create our second hidden layer.
‫Again we are using crosstalk layers or bends and we are creating it with today neurones and activation
‫is a loop.
‫And now for this certain layer to our input should be that layer 1.
‫So we are passing our hat on Layer 1 as a function.
‫Now the next step is this.
‫Here we warn the output of this done there too.
‫And also we want all lower inputs variable here.
‫You can see this linkage.
‫We want these two to go into this contact layer contact layer is just merging the output of the Sudan
‫layer and all the inputs
‫so we can write this layer as concrete.
‫And then we'll use get us dot layer dots concrete and we are passing the list of output off on layer
‫2 and importantly if we wanted output offered on Layer 1 that's what we can write.
‫Then Layer 1 here and it will add a linkage like this also.
‫So you can see you can customize all these linkages very easily using a functional API now.
‫Next step is to create our output layer our output should get input from the concert layer and this
‫should be a single neuron.
‫So we are creating output equal to give us not layers not bends and then a single neuron without any
‫activation function and input as the output of contact layer.
‫We are passing concrete layer as a function here.
‫Now we have created all the layers.
‫The next step is to combine all this layers and create a modern so we are creating a model object and
‫then we are calling get us dot models dot model.
‫And here we are mentioning what we want as our input and what we want as our output.
‫So what input is this first input layer and our output.
‫Is this last output layer.
‫Sequentially.
‫Yeah we first create the model and then we create each layer layer by layer but then functional API
‫we create this layers and then we join this layers to create this whole network just run this again
‫just to look at the structure of the model that you have created you can call not somebody so what object
‫name is Martin and we are calling somebody might you on this you will get all their details for First
‫we have input layer with it input variables then we have a dense layer with 30 neurons then we ever
‫got a second dense layer again with 30 neurons then we have a concrete layer where we are contacting
‫the input of the second dense layer and our input layer so you can see we have 30 less a so hardier
‫neurons here and then we have output that we have on the one neuron now the next step is to combine
‫and just as in our previous lecture we will be using mean this squared error as loss function as 2D
‫with learning rate of zero point zero zero one as our optimizer and Emmy all mean absolute edit as our
‫traditional metrics to get this on this now fitting the model is same we will just say more the Lord
‫put away another training dataset Lord in a middle epoch we lose and then the valuation let us say since
‫last time we ran that regression more than 40 bucks on switching four equals so let this in more than
‫again you will see the lost functions whether nation lost and the value of my cook says thirty you when
‫you
‫can see the lost value we are getting on our training set is zero point 3 6 this is their messy value
‫and the validation loss is 0 1 3 6 3 8 let's calculate the value on our best data
‫you can see the lost value here is 0 1 3 0 6 4 near.
‫In our last case
‫I guess we were getting law says it all.
‫Warren Buffet fight so this model is not performing that good.
‫But in some situations this kind of deep and wide network performs better than at normal MLB Martin's
‫in this case of a normal MLP model is performing better than this wide and deep net for again you have
‫all the parameters of whenever you do.
‫So if you just read model underscore a student art history you will get all the lost values and the
‫M.A. value that we got during their training.
‫And you can also load this on the graph just like we did on the so the important thing here is that
‫a word valuation loss or valuation and me value is decreasing.
‫So there is a scope of further improvement in the accuracy of our morning.
‫So let's just run this model for 40 months epoch as well.
‫Let's call the best values as well.
‫You can see now the loss has decreased to zero point to six.
‫Earlier we were getting around zero point three.
‫Now we have zero point to six as a lost value we can also applaud this graph again to see whether the
‫model of converts this fame on the
‫you can see.
‫This is almost a straight line so we can see that model has converged.
‫And the best value for our model and the MSE value whatever model is 0 1 2 6 1 on the test say this
‫is somewhat similar to the accuracy we bought earlier with our model MLP model but decent I would say
‫that our normal MLP Wanda was performing better than this deep and wide net for that sold for this lecture
‫in the next lecture.
‫We will see how to say well what model and how to save check points at the end of each epochs.
‫Thank you.