So finally guys, you can see the training has got completed.
It took somewhere around eight minutes.
Uh, and 8.8 second.
Okay.
And, uh, these are the number of epochs I was able to get a maximum accuracy.
The training accuracy was somewhere around 94%.
And the validation accuracy was point A, that is 81%.
If I probably go ahead and do another ten more epochs, I feel that still the accuracy will keep on
increasing.
Okay, but I just wanted to show you till ten epochs so that, uh, you know, it won't take more time
for the training.
But initially what I thought, you know.
So over here, please focus on this.
Right.
So loss and accuracy.
Initially loss was shown as a very high value.
I got worried okay.
And then accuracy increased.
Then you can see loss also increased.
I think this is a kind of a glitch that has actually happened because after this you will be able to
see the loss was in decimals in itself.
And this was also getting decreased.
Okay.
But if you see with respect to validation loss here there was no glitches as such.
So from 0.59 we came back to 0.50 which is good enough okay.
And we are able to achieve the validation accuracy of 81%, which is good enough.
Uh, now what I am actually going to do is that I'm just going to go ahead and save this entire file.
Now, in order to save this, uh, I will just go ahead and say, hey, um, model dot, uh, or whatever
models we specifically have, we can just go ahead and save into save it into the H5 file.
Right.
So here I will just go ahead and save my model file.
Okay.
I'll give you an assignment.
You can also keep all these logs in your log folder and use TensorBoard to probably display how we did
it in the end.
Okay so here I'm just going to write model dot save.
Let me just go ahead and write simple underscore RNN underscore IMDb.
IMDb dot uh dot h5 file okay.
So once I execute it.
So this particular file may have got saved over here okay.
Now, quickly, uh, let's do one thing.
Let's also create, uh, one prediction dot ipynb file.
Uh, the reason is very simple because I also need to create a Streamlit app right later on.
So how to properly load this entire model will be discussing about that.
Now this will be very simple.
First of all, uh, I will go ahead and import all this particular libraries.
So let's go ahead and import this data sets pre-processing all these things.
Now from this particular IMDb data sets let's get all the word index okay.
Load the word index.
And we also have this reverse word index okay.
This also I have already explained you.
Then uh, we will go ahead and load our H5 file.
Okay.
Model dot h l file file.
If you go ahead and see the model dot summary okay.
Model dot summary, you'll be able to see it.
One more thing that I forgot to show you.
Right.
Uh, that is, uh, how do you, uh, how do you probably see model dot summary?
If you.
Right, you'll be able to see the model summary if I also want to probably get the weights.
And I hope I've never shown you this.
So here you can actually see all the configuration.
If you want to probably go ahead and see get all the weights.
So here are all the weights that is used with respect to the parameter.
So this is also very handy.
Sometime we don't even save the file that five file.
What we do is that we save the architecture, we save the weights and then we try to combine it.
Okay.
So that way also we can do.
But right now let's move.
Focus on this H5 file.
Later on when I get an opportunity I will also show you that okay.
Then uh, we require two helper function.
One is for decoding the review okay.
And one is for pre-process input.
Now in pre-process input what we do we basically do the padding right sequence dot pad sequences.
And here the max length is 500 I hope in simple RNN what is the max length that we took.
Right.
I guess it was somewhere around 500.
Yeah I am sure 500 only.
Okay, so here, uh, this two will be my utility function.
Okay.
One is for decoding the review and one is for pre-process text.
Uh, whenever the user input gives, uh, gives an user input, we have to probably take that particular
word.
We have to encode that entire review, we have to pad that review.
And finally we get that padded review.
Then only we'll be able to pass it right, uh, to our uh, model.
Now this is very important.
We will go ahead and create our prediction function okay.
Prediction function.
Now in this prediction function we you know that we have loaded the model, right.
So I will just go ahead and write definition predict underscore sentiment.
And here I'm just going to see the review.
And inside this review what I will go ahead and do is that first of all, whenever I get the review
I have to probably pass, uh, through this pre-process underscore text.
Right.
And I will give the review over here right Right.
Once I give the I call this function what is going to happen.
All the padding is basically going to get applied.
First of all, I'm going to get the encoded format for that particular review.
And then we are going to pad all the sequence uh pre padding.
Uh, so I'm going to probably get that zeros and ones uh that I want.
Then I will go ahead and save this particular variable called as preprocessed underscore input over
here.
Okay Then once we get this I'm going to use model dot predict.
And I'm going to pass my preprocessed input over here.
Right.
Once I pass this over here I will be able to make my prediction.
So once I'm able to make the prediction I will quickly go ahead and write one very important condition.
So I'll say, hey, uh, I'll create a variable sentiment.
I'll say, hey, positive.
If prediction of zero zero is greater than 0.5, else negative.
Okay.
And then we are going to return both sentiment and prediction whatever values we are actually able to
get.
So this will basically be my function which is called as predict uh sentiment okay.
Now let's go ahead and see with respect to some examples.
So this is my next step here I'm taking uh review.
The movie was fantastic, the acting was great, and the plot was thrilling.
Okay, so this is my review.
Okay, now see this?
Uh, as soon as I go ahead and pass my predict sentiment and I pass my example review over here, I'll
be getting two values.
One is my sentiment comma prediction right now.
Or I can just go ahead and write my score.
Okay.
Sentiment and score.
Now I will go ahead and make sure that print with the F string.
And here you will be able to see this okay so I've got my example review sentiment prediction score.
If I go ahead and execute it here you can see the movie was fantastic.
The acting was great.
Sentiment is positive.
The prediction score is 0.811.
So this prediction of zero zero when we are using in short, we are getting the score right and this
is greater than 0.5.
So that is the reason we are getting positive.
So in this video, uh, we have saved the, uh, RNN file.
We have loaded it over here.
We got a very good accuracy with respect to the simple RNN.
Right.
And we also able to make the prediction.
Now the same thing will try to create a Streamlit app.
And then we'll create our entire web app.
And finally we'll also go ahead and deploy the our Streamlit web app in the Streamlit cloud that I will
be showing you in the next video.
Thank you.