Hi and welcome back to this course.
So now we have everything, the data and the model that are ready to be used and so we are just ready
to go to the training phase.
So in order to do that, we will first, of course, need to create our model or more precisely, to
create the objects from the class that we created.
And to do that, we need to create all the hyper monitors of our model and all the parameters that are
used to create the models.
So let's do that right now by having Capsis, which is equal to the length of tokenized that vocab.
So that's exactly the number of words that are used during the tokenized phase.
Then we will define our end Beijing time dimension with some tests afterwards.
I found out that's two hundred is a pretty good number, but of course this is not optimized.
You can play with it if you want to find even better results.
When you really get to the evaluation phase, then we have the number of filters.
Same thing for me.
One hundred worked pretty well then F in units.
Here I decided to go with two fifty six, then we have the number of classes which here is equal to
two, then we will define our dropout rates.
In this case, open to worked pretty well.
And finally, the number of epochs that we will use for training and I'll stick to five epochs.
That was enough.
So that's it for the hyper barometer's and all the information we need for the training.
And now let's create our eye with the CNN equals to CNN and let's create everything so Upside's equals
four Capsis then embedding Dymaxion will be equal to and Jim.
The number of filters equals to the filters.
The FT four network units will be equal to 15 units, then we have a number of classes which will be
equal to the classes once again, and I won't surprise you with drop out rates, which will be equal
to, you guessed it, dropout rates.
That's it.
And of course, with this small.
They should do it perfect, so now we have our deep conviction on your network that has been created
and we need, as we use the standards to cross that middle class to combine it.
So we need to give it and optimizer and lost function and accuracy function.
So we'll do that right now.
And as we did while creating our model, we need to make a difference between if we have two classes
or if we have more classes, this will be different.
We will have to face different cases.
So if no classes is to, then the way we do that is to CNN that compile.
And he.
We will have only one number between zero and one that should make a difference between two classes,
and the last function that we use in this case is the binary, because you have two classes cross entropy.
So that will works perfectly.
Optimizer, we will stick to we stand out one that works perfectly well with conventional networks,
which is Adam and finally Matrix.
We will basically just use accuracy.
So this will do the job by itself.
And otherwise, if well, again, let's just use Alsup, if we have more than two classes for our classification
task this time we will with compile use the loss spots.
Category called Cross Entropy, which is once again the standard lost function when we have more than
two classes and we will use exactly the same optimizer, which will be Adam and Matrix.
Same thing this time we call sparse, categorical accuracy, so everything's pretty much handled by
itself.
All we have to do is to use the standard things we call it and perfectly.
Now, our model has been compiled right before, calling the feed function and so training our model.
There's one thing that I want to do and that is create checkpoints.
So the idea behind that is that when we train our model after it is trained, we want to keep it.
We want to be able to get back to the weights that have been trained and to use it later.
And for that we use checkpoints.
So that's just something that's just a tool that is used in order to save our model, the state of the
weight of the optimizer of everything.
And we want to store those check points in our Google Drive folders.
So if we go here in philes, drive my drive projects and we go to but you can see that have many checkpoints
for for all the different applications that we will go through.
So once you have created a photo like that, what you can do is that you can create a checkpoint path,
which is just the path to your checkpoint.
So I will use this.
Small tweaks by copy, but is posted here and now that we have the path to store our check points,
we can create a checkpoint object.
So checkpoint will be a goal to see if the train at checkpoint.
And all we have to do is to say that we will start a decision, which is our actual decision, and that's
it now we will create an object that will be able to manage our checkpoints.
And so that's a checkpoint manager.
So CAPTA manager will be equal to the train that checkpoints manager this time.
And we give it the checkpoint that we wants to manage the path for the checkpoint.
So checkpoint path and the maximum number of checkpoints that we want to keep in this folder.
I personally use one, but if you want to have a history of all your checkpoints doing training, for
instance, you can set these to five and you will have five the five most recent checkpoints in your
folder.
So this will give us the creation of the checkpoints and the checkpoint manager.
And finally, I will just add a Kapiti manager condition.
So if captain manager does.
Latest checkpoint's.
So this is just a way to have access to the latest checkpoints so that those checkpoints, which sense
the latest checkpoints in our foder and if there is no checkpoint, then it will be turned on.
So that's why we can use this condition.
This will be equal to two if this is not empty.
So if we have the latest checkpoint, so if we basically have a checkpoint in order, otherwise, if
we don't, this will be equal to none.
And so this will be false and we won't do what we are about to do right now, which is to restore the
checkpoints.
So Kapiti DOT, Restore and restore the checkpoints manager that latest checkpoints.
Perfect, of course, you can skip this if you already have a checkpoint.
But you want to start from scratch.
Well, just don't run those three lines because this will restore your latest checkpoints.
And if you want to start from scratch, that's not what you want.
So let's just print so that we know whether it has been done or not.
That the latest checkpoint.
Has been restored.
Perfect.
Let's run this and we should see in my case, as I have already trained the network, that's the latest
checkpoint point is restored.
So now CNN contents my train network, but that should not be the case for you.
And so now one last thing I want to do before calling the FT metal into drainage is to create what we
call a custom colebatch.
So that's something that we can give to the fit function so that it executes any lines of code between
each epoch or between its patch or whatever.
You have the wide variety of choices of what you want to execute during your training.
And the way to do that is to create a class that we call my custom.
Colebatch and it inherits from that Kiraz, that's callbacks.
And we just create a callback objects from that and all we have to do for that is to define one of the
several functions that we can use so we can use, for example, on Buche start start on budget and on
ebook starts on Époque.
And so that we just say at every moment of the training whether we want to execute some specific and
home-made lines of code.
So in my case, I want to do is to store the model, so to call the check points at the end of each
ebook.
So in order to do that, I just need to define the UN epoch and method.
And of course this is a method for the class.
So it will itself then it will need the époque we are currently in and let's say that logs equals known.
So we want to know what happens in any file.
And what I want to do at the end of each book is simply to call Kapiti manager that safe.
And that's actually how you really simply save the status of your model into the points.
And we just want to print that check point is saved at.
Brackets and those curly brackets are actually just the the checkpoint path, so check points that it's
my custom callback has been created and now we are finally ready to call the FETs method for our model
and to train it.
So let's have a look at that.
I won't run it by myself right now, and I don't want to delete the sale so you can see what it looks
like because it takes quite a long time to train.
But basically that's really standard.
We just called CNN, so our model that fits, we give it the train that sets the number of epochs we
want to use.
And finally, we just have to use these callbacks equal and enter brackets because you can send several
callbacks.
We just give it an instance of the class that you created.
So here we go.
It's in my custom callback objects with the band.
This is right here.
And this is what we use as callbacks for our fit method.
So that will take a while.
This is what you get after five epochs.
We can see that the accuracy went from well at the beginning.
Of course, it's point five because we started as a 50 50 chance to get the actual good label.
But after some training, we, of course, get a higher and higher accuracy and this 88 percent accuracy.
This is not what we will get in the test, he said.
You will see that later because we have some overfitting.
But using this tokenized from birth is still an improvement from the previous decision and implemented
with a homemade organizer.
But we'll talk about that in the evaluation, but which is actually the topic of the next lecture.
So perhaps you will enjoy the training phase of your D CNN and just use for the evolution part.