1
00:00:00,000 --> 00:00:03,000
So finally guys, you can see the training has got completed.

2
00:00:03,000 --> 00:00:05,000
It took somewhere around eight minutes.

3
00:00:05,000 --> 00:00:07,000
Uh, and 8.8 second.

4
00:00:07,000 --> 00:00:08,000
Okay.

5
00:00:08,000 --> 00:00:13,000
And, uh, these are the number of epochs I was able to get a maximum accuracy.

6
00:00:14,000 --> 00:00:16,000
The training accuracy was somewhere around 94%.

7
00:00:16,000 --> 00:00:20,000
And the validation accuracy was point A, that is 81%.

8
00:00:20,000 --> 00:00:25,000
If I probably go ahead and do another ten more epochs, I feel that still the accuracy will keep on

9
00:00:25,000 --> 00:00:25,000
increasing.

10
00:00:25,000 --> 00:00:30,000
Okay, but I just wanted to show you till ten epochs so that, uh, you know, it won't take more time

11
00:00:30,000 --> 00:00:31,000
for the training.

12
00:00:31,000 --> 00:00:33,000
But initially what I thought, you know.

13
00:00:33,000 --> 00:00:35,000
So over here, please focus on this.

14
00:00:35,000 --> 00:00:35,000
Right.

15
00:00:35,000 --> 00:00:36,000
So loss and accuracy.

16
00:00:36,000 --> 00:00:39,000
Initially loss was shown as a very high value.

17
00:00:39,000 --> 00:00:40,000
I got worried okay.

18
00:00:40,000 --> 00:00:42,000
And then accuracy increased.

19
00:00:42,000 --> 00:00:45,000
Then you can see loss also increased.

20
00:00:45,000 --> 00:00:49,000
I think this is a kind of a glitch that has actually happened because after this you will be able to

21
00:00:49,000 --> 00:00:52,000
see the loss was in decimals in itself.

22
00:00:52,000 --> 00:00:54,000
And this was also getting decreased.

23
00:00:54,000 --> 00:00:54,000
Okay.

24
00:00:54,000 --> 00:00:59,000
But if you see with respect to validation loss here there was no glitches as such.

25
00:00:59,000 --> 00:01:04,000
So from 0.59 we came back to 0.50 which is good enough okay.

26
00:01:04,000 --> 00:01:08,000
And we are able to achieve the validation accuracy of 81%, which is good enough.

27
00:01:08,000 --> 00:01:15,000
Uh, now what I am actually going to do is that I'm just going to go ahead and save this entire file.

28
00:01:15,000 --> 00:01:22,000
Now, in order to save this, uh, I will just go ahead and say, hey, um, model dot, uh, or whatever

29
00:01:22,000 --> 00:01:28,000
models we specifically have, we can just go ahead and save into save it into the H5 file.

30
00:01:28,000 --> 00:01:28,000
Right.

31
00:01:28,000 --> 00:01:33,000
So here I will just go ahead and save my model file.

32
00:01:33,000 --> 00:01:33,000
Okay.

33
00:01:33,000 --> 00:01:35,000
I'll give you an assignment.

34
00:01:35,000 --> 00:01:39,000
You can also keep all these logs in your log folder and use TensorBoard to probably display how we did

35
00:01:39,000 --> 00:01:40,000
it in the end.

36
00:01:40,000 --> 00:01:44,000
Okay so here I'm just going to write model dot save.

37
00:01:44,000 --> 00:01:50,000
Let me just go ahead and write simple underscore RNN underscore IMDb.

38
00:01:51,000 --> 00:01:55,000
IMDb dot uh dot h5 file okay.

39
00:01:56,000 --> 00:01:56,000
So once I execute it.

40
00:01:56,000 --> 00:02:01,000
So this particular file may have got saved over here okay.

41
00:02:01,000 --> 00:02:03,000
Now, quickly, uh, let's do one thing.

42
00:02:03,000 --> 00:02:07,000
Let's also create, uh, one prediction dot ipynb file.

43
00:02:08,000 --> 00:02:12,000
Uh, the reason is very simple because I also need to create a Streamlit app right later on.

44
00:02:12,000 --> 00:02:16,000
So how to properly load this entire model will be discussing about that.

45
00:02:16,000 --> 00:02:18,000
Now this will be very simple.

46
00:02:18,000 --> 00:02:23,000
First of all, uh, I will go ahead and import all this particular libraries.

47
00:02:23,000 --> 00:02:27,000
So let's go ahead and import this data sets pre-processing all these things.

48
00:02:28,000 --> 00:02:33,000
Now from this particular IMDb data sets let's get all the word index okay.

49
00:02:33,000 --> 00:02:34,000
Load the word index.

50
00:02:34,000 --> 00:02:37,000
And we also have this reverse word index okay.

51
00:02:37,000 --> 00:02:39,000
This also I have already explained you.

52
00:02:40,000 --> 00:02:44,000
Then uh, we will go ahead and load our H5 file.

53
00:02:45,000 --> 00:02:45,000
Okay.

54
00:02:46,000 --> 00:02:47,000
Model dot h l file file.

55
00:02:47,000 --> 00:02:51,000
If you go ahead and see the model dot summary okay.

56
00:02:51,000 --> 00:02:53,000
Model dot summary, you'll be able to see it.

57
00:02:53,000 --> 00:02:55,000
One more thing that I forgot to show you.

58
00:02:55,000 --> 00:02:56,000
Right.

59
00:02:56,000 --> 00:03:03,000
Uh, that is, uh, how do you, uh, how do you probably see model dot summary?

60
00:03:03,000 --> 00:03:04,000
If you.

61
00:03:04,000 --> 00:03:08,000
Right, you'll be able to see the model summary if I also want to probably get the weights.

62
00:03:08,000 --> 00:03:10,000
And I hope I've never shown you this.

63
00:03:10,000 --> 00:03:12,000
So here you can actually see all the configuration.

64
00:03:13,000 --> 00:03:15,000
If you want to probably go ahead and see get all the weights.

65
00:03:15,000 --> 00:03:18,000
So here are all the weights that is used with respect to the parameter.

66
00:03:18,000 --> 00:03:20,000
So this is also very handy.

67
00:03:20,000 --> 00:03:22,000
Sometime we don't even save the file that five file.

68
00:03:22,000 --> 00:03:26,000
What we do is that we save the architecture, we save the weights and then we try to combine it.

69
00:03:26,000 --> 00:03:27,000
Okay.

70
00:03:27,000 --> 00:03:28,000
So that way also we can do.

71
00:03:28,000 --> 00:03:30,000
But right now let's move.

72
00:03:30,000 --> 00:03:31,000
Focus on this H5 file.

73
00:03:31,000 --> 00:03:35,000
Later on when I get an opportunity I will also show you that okay.

74
00:03:36,000 --> 00:03:39,000
Then uh, we require two helper function.

75
00:03:39,000 --> 00:03:42,000
One is for decoding the review okay.

76
00:03:42,000 --> 00:03:44,000
And one is for pre-process input.

77
00:03:44,000 --> 00:03:50,000
Now in pre-process input what we do we basically do the padding right sequence dot pad sequences.

78
00:03:50,000 --> 00:03:57,000
And here the max length is 500 I hope in simple RNN what is the max length that we took.

79
00:03:57,000 --> 00:03:58,000
Right.

80
00:03:58,000 --> 00:04:00,000
I guess it was somewhere around 500.

81
00:04:00,000 --> 00:04:02,000
Yeah I am sure 500 only.

82
00:04:02,000 --> 00:04:06,000
Okay, so here, uh, this two will be my utility function.

83
00:04:06,000 --> 00:04:07,000
Okay.

84
00:04:07,000 --> 00:04:10,000
One is for decoding the review and one is for pre-process text.

85
00:04:10,000 --> 00:04:15,000
Uh, whenever the user input gives, uh, gives an user input, we have to probably take that particular

86
00:04:15,000 --> 00:04:15,000
word.

87
00:04:15,000 --> 00:04:18,000
We have to encode that entire review, we have to pad that review.

88
00:04:18,000 --> 00:04:20,000
And finally we get that padded review.

89
00:04:20,000 --> 00:04:25,000
Then only we'll be able to pass it right, uh, to our uh, model.

90
00:04:25,000 --> 00:04:27,000
Now this is very important.

91
00:04:27,000 --> 00:04:31,000
We will go ahead and create our prediction function okay.

92
00:04:31,000 --> 00:04:33,000
Prediction function.

93
00:04:33,000 --> 00:04:37,000
Now in this prediction function we you know that we have loaded the model, right.

94
00:04:37,000 --> 00:04:43,000
So I will just go ahead and write definition predict underscore sentiment.

95
00:04:44,000 --> 00:04:48,000
And here I'm just going to see the review.

96
00:04:48,000 --> 00:04:53,000
And inside this review what I will go ahead and do is that first of all, whenever I get the review

97
00:04:53,000 --> 00:04:59,000
I have to probably pass, uh, through this pre-process underscore text.

98
00:04:59,000 --> 00:05:00,000
Right.

99
00:05:00,000 --> 00:05:02,000
And I will give the review over here right Right.

100
00:05:02,000 --> 00:05:06,000
Once I give the I call this function what is going to happen.

101
00:05:06,000 --> 00:05:08,000
All the padding is basically going to get applied.

102
00:05:08,000 --> 00:05:12,000
First of all, I'm going to get the encoded format for that particular review.

103
00:05:12,000 --> 00:05:16,000
And then we are going to pad all the sequence uh pre padding.

104
00:05:16,000 --> 00:05:20,000
Uh, so I'm going to probably get that zeros and ones uh that I want.

105
00:05:20,000 --> 00:05:26,000
Then I will go ahead and save this particular variable called as preprocessed underscore input over

106
00:05:26,000 --> 00:05:26,000
here.

107
00:05:26,000 --> 00:05:32,000
Okay Then once we get this I'm going to use model dot predict.

108
00:05:33,000 --> 00:05:36,000
And I'm going to pass my preprocessed input over here.

109
00:05:37,000 --> 00:05:37,000
Right.

110
00:05:37,000 --> 00:05:42,000
Once I pass this over here I will be able to make my prediction.

111
00:05:43,000 --> 00:05:50,000
So once I'm able to make the prediction I will quickly go ahead and write one very important condition.

112
00:05:50,000 --> 00:05:53,000
So I'll say, hey, uh, I'll create a variable sentiment.

113
00:05:53,000 --> 00:05:54,000
I'll say, hey, positive.

114
00:05:54,000 --> 00:05:57,000
If prediction of zero zero is greater than 0.5, else negative.

115
00:05:57,000 --> 00:05:57,000
Okay.

116
00:05:57,000 --> 00:06:02,000
And then we are going to return both sentiment and prediction whatever values we are actually able to

117
00:06:02,000 --> 00:06:02,000
get.

118
00:06:02,000 --> 00:06:07,000
So this will basically be my function which is called as predict uh sentiment okay.

119
00:06:07,000 --> 00:06:11,000
Now let's go ahead and see with respect to some examples.

120
00:06:12,000 --> 00:06:16,000
So this is my next step here I'm taking uh review.

121
00:06:16,000 --> 00:06:20,000
The movie was fantastic, the acting was great, and the plot was thrilling.

122
00:06:20,000 --> 00:06:22,000
Okay, so this is my review.

123
00:06:22,000 --> 00:06:23,000
Okay, now see this?

124
00:06:23,000 --> 00:06:29,000
Uh, as soon as I go ahead and pass my predict sentiment and I pass my example review over here, I'll

125
00:06:29,000 --> 00:06:30,000
be getting two values.

126
00:06:30,000 --> 00:06:35,000
One is my sentiment comma prediction right now.

127
00:06:35,000 --> 00:06:38,000
Or I can just go ahead and write my score.

128
00:06:38,000 --> 00:06:39,000
Okay.

129
00:06:39,000 --> 00:06:40,000
Sentiment and score.

130
00:06:41,000 --> 00:06:45,000
Now I will go ahead and make sure that print with the F string.

131
00:06:45,000 --> 00:06:52,000
And here you will be able to see this okay so I've got my example review sentiment prediction score.

132
00:06:52,000 --> 00:06:55,000
If I go ahead and execute it here you can see the movie was fantastic.

133
00:06:55,000 --> 00:06:55,000
The acting was great.

134
00:06:55,000 --> 00:06:57,000
Sentiment is positive.

135
00:06:57,000 --> 00:06:59,000
The prediction score is 0.811.

136
00:06:59,000 --> 00:07:05,000
So this prediction of zero zero when we are using in short, we are getting the score right and this

137
00:07:05,000 --> 00:07:05,000
is greater than 0.5.

138
00:07:05,000 --> 00:07:07,000
So that is the reason we are getting positive.

139
00:07:08,000 --> 00:07:12,000
So in this video, uh, we have saved the, uh, RNN file.

140
00:07:12,000 --> 00:07:14,000
We have loaded it over here.

141
00:07:14,000 --> 00:07:17,000
We got a very good accuracy with respect to the simple RNN.

142
00:07:17,000 --> 00:07:17,000
Right.

143
00:07:17,000 --> 00:07:20,000
And we also able to make the prediction.

144
00:07:20,000 --> 00:07:22,000
Now the same thing will try to create a Streamlit app.

145
00:07:22,000 --> 00:07:25,000
And then we'll create our entire web app.

146
00:07:25,000 --> 00:07:30,000
And finally we'll also go ahead and deploy the our Streamlit web app in the Streamlit cloud that I will

147
00:07:30,000 --> 00:07:32,000
be showing you in the next video.

148
00:07:32,000 --> 00:07:33,000
Thank you.

