‫Now in this lecture we are going to be on model using Cato's before that we will do one small thing.
‫We will take out end of this small set of training examples as validation set of validation set is used
‫to tune the model hyper barometers.
‫So we'll just take our first 5000 examples as validation set and the remaining we will see them in another
‫variable called partial training say so here and setting the noses of postpaid him in a variable called
‫value indices.
‫Now I knew this variable could take all the information off plus 5000 and stored it into the validation
‫images
‫for the first 5000 brain images are now stored in value images.
‫The remaining part of the images is stored in part underscored brain images
‫we do the same thing with labels.
‫The First 5000 labels are stored in VAT labels and the rest of the labels are stored in part print labels
‫so we have created two parts.
‫Although these trading examples one is validation say and one is the partial dating reality partial
‫dating site to trendy model.
‫And the validation set will be used to do only hyper parameters and you will see the use of validation
‫set in becoming victims.
‫Now there are two ways in which we can define our model using get us.
‫One is using sequential EPA and the other is using functional EPA
‫sequencing.
‫EPA is used when we want to make a normal neural network with linear stack of layers.
‫The functional EPA is used for a complex network structure where you have multiple usages of several
‫small one it looks will see an example of functional EPA when we build a regression model for this classification
‫example we will use sequential EPA.
‫Now we'll be taking three steps in defining our model.
‫The first step is defining the network structure.
‫This includes setting up the number of layers number of neurons in each layer and the activation function
‫to be used in each layer.
‫This is captured and this part of decode.
‫The second part is configuring the learning process this includes selecting the lost function and optimizer
‫and some metrics to be monitored.
‫This is this part of the code.
‫The third is specifying the operations and blending the model.
‫This is done in this last part of this code.
‫So let's start discussing each line of code one by one.
‫Here we start by creating a new variable called model and this variable will contain the information
‫of the structure of our network.
‫This is the function we use for using sequence and EPA gave us model underscored sequences and then
‫to start defining the structure.
‫We use this type symbol.
‫This pipe operator comes with the magnetite package which is auto installed when we installed the cameras
‫package.
‫This is used for passing values as arguments to function.
‫We can do away with a decimal also but the use of this symbol makes the code more readable and compact.
‫So as a good practice we will use this operator too.
‫This is a pipe operator.
‫And if you remember even this operator that we used by assigning new plane images and green labels this
‫multiple assignment operator this has come into the alert package which was also part of the clearance
‫package.
‫We're using this also because it makes the code compact so first we flatten the input layer my flattening
‫I mean that we have 28 micro indeed image we can turn it into one dimension by putting all these pixels
‫in one line.
‫For example if you have this three by 3 two dimensional Eddy you can flatten it by putting these multiple
‫roles in front of each other.
‫So this will become a one dimensional edit
‫this step is important as we have to give a straight shape of input values in place offered to the input
‫you can converted in one dimensional using edit easier.
‫Function also when we have hit us why should we bother.
‫Just specify here layer flatten like this and specify the input shape.
‫That is what is the kind of input that this layer is having.
‫It will automatically convert this to endured by two indeed input in 2 7 a report pixel values for the
‫next layer.
‫Next we specify any details of our dense hidden layer.
‫That is we are telling that this layer is dense meaning each neuron is connected to all neurons of the
‫next layer.
‫And then this layer we want one twenty eight neurons and the activation function for all these neurons
‫will meet the loop.
‫That is rectified linear Unit 2 in this way.
‫We have defined one hidden layer.
‫It's a densely.
‫It has 120 neutrons and they look at and function.
‫Next we specify the output layer.
‫You can add more layers also but here I am using only one had a layer and one output in this last net.
‫We have 10 neutrons whiten because we have 10 classes to be predicted.
‫Each of these 10 neutrons will be predicting the probability of one class such as whether it is a shirt
‫or a boot.
‫And if you remember from your theory lecture this soft Max activation just make sure that the sum of
‫all the probabilities come out to 1.
‫So this last layer has 10 neurons with soft Max activation.
‫That's all for the structure.
‫In short it is a 780 for hyphen 128 different in neural network.
‫Once we have run the entire code I would suggest that you come back to this point and experiment a little
‫bit here try to see what is the effect of having more lives and what is the effect of increasing or
‫decreasing the number of neurons in different layers.
‫Next underscored.
‫You can see that a new variable called model is created and it has the structure stored in it.
‫Now let's look at the second step at this step.
‫We configured the learning process in this.
‫The first thing is specifying optimizer.
‫We have discussed the concept behind stochastic gradient descent.
‫This is deadly.
‫Is that only data other optimizer also with small differences other optimizes include Adam Artemus prof
‫and few others.
‫In fact in the coming team we may see few more added to this list.
‫But to answer the question which should be used then ideally the optimizer depends on the shape of the
‫edit function go.
‫But we do not know that shape.
‫So we do not know the ideal optimize it but practically in most of these scenarios all of these work
‫very well.
‫It's just that for some scenarios as did converges it and for some situations outermost prop converges
‫faster.
‫So my suggestion would be labeled readonly model once with duty.
‫If you think it is taking too long to convert and you are also not seeing much improvement in training
‫it is always worth a shot to Brio Artemus prop optimizer also.
‫Let's move on to this again parameter which is lost function.
‫We have this because this is the theory part for classification models views cross entropy and for regression
‫models we use the means squared added values but within cross entropy you will find three options.
‫Which of these three should you use depends on the type of problem you have.
‫These are the three names sparse categorical cross entropy binary cross entropy and categorical cross
‫entropy if your problem has two classes to be predicted like whether a is spam of North spam we use
‫the binary cross entropy.
‫If you have multiple classes such as this problem where we have ten fashion objects and each example
‫is exclusive meaning each image contains only one object to be predicted then we use sparse categorical
‫cross and Ruby.
‫So that is why I am right and logical loose pass categorical course and repeated if we have multiple
‫classes and one observation can belong to many classes for example if we are labeling whether an email
‫is from someone you know or not and we are also labeling whether the email is important or not.
‫Here one email can be bought.
‫It can be from someone you know and it can be important so it may belong to two classes at the same
‫time.
‫In this scenario we use categorical growth and Ruby.
‫I hope you understood this.
‫Here's the gist of what I just said.
‫You can look at this commented part here to understand the three cross and rupees.
‫The third parameter is metrics.
‫This is not mandatory but we specify this to monitor the performance of model on the training set.
‫Basically we would like to see the improvement in accuracy of a classification model or the mean squared.
‫Edit offer the regression model over each epoch.
‫As I told you we go over the entire training dataset several times each time we will calculate the accuracy
‫of our model.
‫At that instant and store it so that we can see if the learning process is having any improvement in
‫accuracy or not.
‫So with these three parameters say we can done this part of the code.
‫Now we have configured the learning process also.
‫This brings us to the third part where we actually train not more than training is done using different
‫function within function.
‫We have to specify the input variable first.
‫That is the posture training dataset that we will input then comes the actual output corresponding to
‫those inputs to the actual output is stored in partial train labeled.
‫So that is the second parameter.
‫Next we specify the epoch number.
‫This is the number of times our entire training data will be put into the model.
‫We set this to 30 for this example then we have that size.
‫This is the number of observations which will be used during each forward and backward propagation step
‫so we take a battery of hundred
‫lastly we tell that we have a separate validation data also which is a list of valid images and value
‫labels and we would like to see the accuracy score on this validation data.
‫As keep in mind that only this part brain images and bartering labels will be used to bring any model
‫this validation data is like this data.
‫In this scenario that is our model will not have seen the validation data when it calculates the accuracy
‫on this validation data.
‫Now let's run this line of code as well and this will be number one
‫well you can see that neural network model is getting green and the accuracy in lost value is being
‫recorded for each epoch in the next video we will see the performance of this train more model.