‫Now let's create a structure of forward first artificial neural network model.
‫Before starting let's just say random seed 242 using these clues statements random seed is used to replicate
‫the same dessert every time.
‫You can use any of them but instead of 42 if you use that number in future when you are running the
‫same code you will get the same output as we have discussed in the theory.
‫There are multiple occasions where a what neural network generates random number such as assigning the
‫initial weights using random seed will help you to reproduce the same result using the same initial
‫weights every time they're tested on this.
‫So for the word problem we have observations in the form of 28 and 220 pixels observations are in the
‫form of to be array and as an output we want 10 categories.
‫These categories are exclusive.
‫That means a single limit can either be a t shirt ordered top or a boat etc..
‫This is what we are planning to do.
‫We are first converting over to be observations and book flight.
‫1 these observations.
‫So insert over to be a day of 2010 228 pixel we want 784 pixel in our input layer.
‫Then we are going to create two hidden layers the activation function which we are going to use for
‫hidden layers will be real.
‫As discussed in the theory lecture we always prefer red loop for classification models and in the output.
‫Since this 10 categories are exclusive and and this is a classification model we will be using soft
‫Max activation.
‫We have already discussed this activation types in our theory reelected.
‫That's why we are not going to discuss it here.
‫Now let's start creating this neural network using sequential a piece of data.
‫First we will need to create an model object.
‫So our object variable name is model and we are just building it using this function get US DOT models
‫dot sequential in this sequential object.
‫We can add different layers.
‫We will start with our input layer will move on to the hidden layer 1 then to heard on Layer 2 and then
‫to the output layer.
‫So first for the input layer we can write like this model dot ag and then guide us dot layers and then
‫since we want to convert this to be a real friend data into 28 pixels to say 184 pixel in a single array
‫we are using then
‫and then we need to provide the input shape of over X variables.
‫Since about X variable is a beauty array of 28 and Goodwin dead pixel we are using input shape equal
‫to then we are providing a list of two variables that is defined here called 128
‫then over the second layer is the hidden layer.
‫So in the next step we are adding another layer that is model dot and then get us dot layer.
‫And since this is a dance layer will write dense.
‫And here we need to mention the number of neurons we want in this layer.
‫So and then layer one we need 300 neurons.
‫That is why we are writing 300.
‫And then we want real to activation function.
‫That's why we are writing activation equally to very low in the next step.
‫We want another hidden layer.
‫So we are following the same process that is we are writing more than not Ed and in record we are writing
‫gave us dot layer dot bands and in this layer we 100 neurons.
‫That's why we are writing hundred and then activation equal to the loop since this is also done layer.
‫We want activation function to be done in the next output layer.
‫We want 10 different categories.
‫That's why we have to add 10 neurons and to this layer and since the classes are exclusive.
‫That's why we have to use soft Max activation.
‫So we'll write model and Dot ag and then K does dot layers dot bends and then the number of neurons
‫which expand and activation equate to solve.
‫Max I hope you remember Waterloo and soft Max are real low is zero for all the negative numbers and
‫equate to the input for all the positive inputs very soft Max equates the sum of all the class probability
‫to one
‫in case if you want any additional hidden layer you can always add additional layer between any of these
‫layers in the later part of the course.
‫We will see how to choose the number of neurons in each layer.
‫Let's run this.
‫After creating this model structure you can look at it using the somebody method.
‫So if you write your object name that is model and if you write dot somebody
‫the model somebody method displays all the more than layers including each layers names its outputs
‫shape and the number of parameters so these are the layer names.
‫Second is the output shape.
‫This the number of output.
‫And this is the bed size of the input.
‫Since we are passing all our data and that's why this is none none means no limit on input data.
‫And next is the number of green parameters.
‫Since our input have 784 variables and we are passing each of these variables and to 300 different neurons
‫we have individual words for each of these linkages.
‫So total number of weights is 784 in two 300 plus there are other 300 biased variables that they're
‫not associated with each of these neurons.
‫So 7 they take forward and 2 300 plus 300 will give you this number.
‫Our neural network is trying to optimize this many parameters for this layer.
‫Similarly this are the trainable parameters for this layer.
‫Again this will be 300 and 200.
‫There are three hundred and two hundred linkages between these two layers and each of that linkage will
‫have associated weights and each of the neurons in this layer that is hundred neurons have hundred different
‫biases values.
‫So three hundred and two hundred less hundred So thirty thousand one hundred three enabled parameters
‫are associated with this layer.
‫Similarly 1010 trainable parameters are associated with this layer.
‫So at the bottom you get the summary of total number of training parameters and this neural network.
‫So our neural network will try to optimize this many parameters to get the best result.
‫Now if you want to look at our now if you want to look at our neural network you can do that using BI
‫dot.
‫So you have to import by DOT and if by a dot is not installed in your system you can install it using
‫Pip space installed in space by a dot or Conda is space install the space by DOT in your command prompt.
‫So if you just write get us not utilities dot plot under Scott Morton and then give your object name
‫and if you run this you will get the structure of fewer neural network.
‫So here we have input layer.
‫Then we have lightning that would be a day and a one day a day.
‫So that's why we have a flat layer and then we have two dense good then layer and we have an output
‫layer which is giving us the plus probabilities so after creating the structure of your neural network.
‫You can also visualize this a structure using this command
‫as I said earlier our model is trying to optimize rates and biases that are represented by this number
‫to get output.
‫And if you remember in theory lecture we have this because the rates are assigned randomly for initialization
‫to get the information off those weights and biases.
‫There is a get underscore word method that you can use to get information of those weights and biases
‫so I can write my object name that is model and then the Layer number for the second layer.
‫I can write layers and then 1 since the location of object to is 1 and then I can use get free it's
‫my turn.
‫I'm sorting this information into two new variables weights and biases.
‫So if I just output the weights you can see this are the randomly generated weights that are 784 and
‫do 300 such weights in this layer.
‫So if you just view the shape you can see that there are 784 rows and 300 columns and the word weights
‫these All weights are randomly assigned for an installation.
‫Similarly you can also look at the biases values biases are initialized as Zito.
‫And if you just check the shape of biases.
‫This should be 300.
‫You can see that there are 300 biases in the next video.
‫We will combine and train our model.
‫Thank you.