1
00:00:00,000 --> 00:00:05,000
So guys, now we are going to continue the discussion with respect to our end to end project.

2
00:00:05,000 --> 00:00:07,000
Already we have trained our simple RNN.

3
00:00:07,000 --> 00:00:08,000
We have saved the H5 file.

4
00:00:08,000 --> 00:00:10,000
We are also able to do the prediction.

5
00:00:10,000 --> 00:00:14,000
Now let's go ahead and create our Streamlit app.

6
00:00:14,000 --> 00:00:17,000
So here I'm going to basically go ahead and write main.py.

7
00:00:18,000 --> 00:00:22,000
And inside this main.py I am going to write my code.

8
00:00:22,000 --> 00:00:26,000
Now with respect to prediction dot ipynb it's almost similar like this.

9
00:00:26,000 --> 00:00:29,000
Like uh, there will be a D code review, there will be a pre-processed text.

10
00:00:29,000 --> 00:00:32,000
So we need to probably go ahead and combine each and everything.

11
00:00:32,000 --> 00:00:32,000
Okay.

12
00:00:33,000 --> 00:00:35,000
Uh, I need to also load my model itself.

13
00:00:35,000 --> 00:00:35,000
Right.

14
00:00:35,000 --> 00:00:36,000
So let's go ahead and do it.

15
00:00:36,000 --> 00:00:41,000
So first of all I will go ahead and import my model libraries.

16
00:00:41,000 --> 00:00:42,000
So let me do one thing.

17
00:00:42,000 --> 00:00:46,000
Let me quickly import all the libraries that I have.

18
00:00:46,000 --> 00:00:51,000
So here we are going to import all these libraries like IMDb sequence load model.

19
00:00:51,000 --> 00:00:58,000
Then uh I'm going to load the word index specifically for the IMDb because I need to convert that based

20
00:00:58,000 --> 00:01:00,000
on, uh, our decode reviews.

21
00:01:00,000 --> 00:01:04,000
Uh, basically all the reviews needs to be converted into vectors.

22
00:01:04,000 --> 00:01:09,000
So that is the reason we require index, uh, and that we will be specifically getting from this particular

23
00:01:09,000 --> 00:01:14,000
word index right along with this two helper functions, uh, that I have actually shown you.

24
00:01:14,000 --> 00:01:17,000
We can also create this in another file and call this particular file.

25
00:01:17,000 --> 00:01:22,000
But let me just go ahead and put it over here so that it will be easy for you to refer.

26
00:01:22,000 --> 00:01:24,000
So here I have my decoded reviews.

27
00:01:24,000 --> 00:01:26,000
Here I have my pre-processed text.

28
00:01:26,000 --> 00:01:28,000
Now, finally, uh, this is important.

29
00:01:28,000 --> 00:01:30,000
We will go ahead and create our.

30
00:01:30,000 --> 00:01:36,000
Step three will be creating our prediction function right now.

31
00:01:36,000 --> 00:01:40,000
And inside this prediction function I have already shown you what we basically do.

32
00:01:40,000 --> 00:01:46,000
So if you go over here down this is the prediction function write predict sentiment.

33
00:01:46,000 --> 00:01:48,000
So I'm just going to copy this same thing okay.

34
00:01:48,000 --> 00:01:50,000
Model dot predict positive.

35
00:01:50,000 --> 00:01:52,000
If this is then we are going to return this.

36
00:01:52,000 --> 00:01:54,000
So the same thing will also be pasted over here.

37
00:01:54,000 --> 00:01:55,000
Right.

38
00:01:55,000 --> 00:01:59,000
So this basically becomes my predict sentiment right now.

39
00:01:59,000 --> 00:02:08,000
Uh let's do quickly one uh very important thing uh, in this is that when we are, you know, when we

40
00:02:08,000 --> 00:02:10,000
are probably using our Streamlit, you know.

41
00:02:10,000 --> 00:02:15,000
So Streamlit app needs to be providing some input boxes, some buttons and.

42
00:02:15,000 --> 00:02:15,000
All right.

43
00:02:15,000 --> 00:02:17,000
So we can go ahead and do that.

44
00:02:17,000 --> 00:02:18,000
All the things over here.

45
00:02:18,000 --> 00:02:19,000
Right.

46
00:02:19,000 --> 00:02:25,000
So uh quickly uh uh I'll keep this predict sentiment and let's see whether we will be requiring it or

47
00:02:25,000 --> 00:02:25,000
not.

48
00:02:25,000 --> 00:02:29,000
So I will go ahead and design my Streamlit app.

49
00:02:29,000 --> 00:02:29,000
Okay.

50
00:02:29,000 --> 00:02:32,000
So first of all I'll go ahead and write SD dot title.

51
00:02:32,000 --> 00:02:35,000
so quickly.

52
00:02:35,000 --> 00:02:39,000
First of all, I'll also import Streamlit as st.

53
00:02:39,000 --> 00:02:44,000
Okay, then I will just go ahead and give my title and some information over here.

54
00:02:44,000 --> 00:02:50,000
So I'll give a text which says IMDb Movie Review Sentiment Analysis.

55
00:02:50,000 --> 00:02:53,000
Enter a movie review to classify it as positive or negative.

56
00:02:53,000 --> 00:02:54,000
Right.

57
00:02:54,000 --> 00:02:55,000
So this is there.

58
00:02:55,000 --> 00:03:00,000
Then we will go ahead and create a user input by again using Streamlit.

59
00:03:00,000 --> 00:03:02,000
So for that we use s t dot text area.

60
00:03:02,000 --> 00:03:03,000
And this will be my movie review.

61
00:03:04,000 --> 00:03:09,000
Then what I'm actually going to do is that I'm going to probably go ahead and create one button okay.

62
00:03:09,000 --> 00:03:13,000
And if I click this button this should classification should basically happen.

63
00:03:13,000 --> 00:03:17,000
Now when I'm giving this user input, this user input.

64
00:03:17,000 --> 00:03:24,000
First of all, once we click this particular button it should be passed to our preprocess underscore

65
00:03:24,000 --> 00:03:25,000
text function.

66
00:03:25,000 --> 00:03:27,000
And here I will just give my user input.

67
00:03:27,000 --> 00:03:35,000
Through this we will be getting our preprocess underscore input value right.

68
00:03:35,000 --> 00:03:39,000
So this is how we will be getting this preprocess underscore input value.

69
00:03:39,000 --> 00:03:45,000
Then here the next step will be that I will go ahead and make my prediction.

70
00:03:45,000 --> 00:03:53,000
Now this prediction I'm going to basically use prediction is equal to model dot predict.

71
00:03:53,000 --> 00:03:58,000
And here I'm going to use my process underscore input okay.

72
00:03:58,000 --> 00:04:04,000
So this processed underscore input I'll just keep a spelling which looks like this okay.

73
00:04:05,000 --> 00:04:12,000
Then uh once we get this specific input then I'm just going to go ahead and calculate my sentiments

74
00:04:12,000 --> 00:04:13,000
and sentiments will be nothing.

75
00:04:13,000 --> 00:04:17,000
But here we are going to use this positive or negative right.

76
00:04:17,000 --> 00:04:21,000
If this is greater than 0.5 it's negative I'll say.

77
00:04:21,000 --> 00:04:27,000
Then we will display the result in my in my Streamlit itself.

78
00:04:27,000 --> 00:04:33,000
So we will go ahead and write SD dot right SD dot right, else SD dot right right.

79
00:04:33,000 --> 00:04:37,000
So here uh let me do one thing.

80
00:04:37,000 --> 00:04:37,000
Okay.

81
00:04:37,000 --> 00:04:39,000
So here, this else should be here.

82
00:04:39,000 --> 00:04:41,000
And here I will go ahead and.

83
00:04:41,000 --> 00:04:41,000
Right.

84
00:04:41,000 --> 00:04:44,000
So here I'll say if I go ahead and click the classify button.

85
00:04:44,000 --> 00:04:47,000
So I should basically do the prediction of this processed input.

86
00:04:47,000 --> 00:04:49,000
I should be getting the sentiment.

87
00:04:49,000 --> 00:04:51,000
I will probably display the sentiment in prediction.

88
00:04:51,000 --> 00:04:54,000
Else if I don't click it, it'll just give me a message saying that.

89
00:04:54,000 --> 00:04:56,000
Please enter a movie review.

90
00:04:56,000 --> 00:05:05,000
Okay, so, uh, this is done over here and, uh, you know, uh, uh, you can probably also display

91
00:05:05,000 --> 00:05:09,000
how the sample review should look like, write sample reviews.

92
00:05:09,000 --> 00:05:10,000
Also, we need to properly display.

93
00:05:10,000 --> 00:05:15,000
So that is the reason we are using this code review and pre-process text over here.

94
00:05:15,000 --> 00:05:17,000
So let me do one thing.

95
00:05:19,000 --> 00:05:20,000
Let me just go ahead and run this.

96
00:05:20,000 --> 00:05:23,000
And I think we have almost done each and everything right.

97
00:05:23,000 --> 00:05:25,000
If you want you can also display your sample review below.

98
00:05:25,000 --> 00:05:27,000
You can just write SD dot write.

99
00:05:27,000 --> 00:05:28,000
Hey, this should be a sample review.

100
00:05:28,000 --> 00:05:30,000
That is one way, but here.

101
00:05:30,000 --> 00:05:32,000
In short, let us revise what all things we did.

102
00:05:32,000 --> 00:05:33,000
We imported all the libraries.

103
00:05:33,000 --> 00:05:37,000
So here is my word index that I am actually able to get.

104
00:05:37,000 --> 00:05:42,000
I'm reloading my H5 file, so let me just rename this file like this.

105
00:05:43,000 --> 00:05:46,000
Then here is my helpful uh, helper function.

106
00:05:46,000 --> 00:05:48,000
Helper function of decode review.

107
00:05:48,000 --> 00:05:50,000
Here is my with respect to pre-process preprocess input.

108
00:05:50,000 --> 00:05:54,000
So this function is basically just giving you the vectors with padded sequence, right?

109
00:05:54,000 --> 00:05:56,000
Not vector indexes with padded sequence.

110
00:05:56,000 --> 00:05:58,000
Then this is your prediction function.

111
00:05:58,000 --> 00:06:00,000
I have not even used this prediction function.

112
00:06:00,000 --> 00:06:03,000
I can also use it over here, but I have written it.

113
00:06:03,000 --> 00:06:05,000
So let me just remove this over here.

114
00:06:05,000 --> 00:06:06,000
Okay, I don't require it.

115
00:06:06,000 --> 00:06:08,000
Then we are importing Streamlit.

116
00:06:08,000 --> 00:06:10,000
Then we have created our text area.

117
00:06:10,000 --> 00:06:11,000
We have created a button.

118
00:06:11,000 --> 00:06:16,000
If we click the button, it should probably predict it and give you the sentiments.

119
00:06:16,000 --> 00:06:21,000
So finally guys, now we are going to run this and see that whether everything is working fine or not.

120
00:06:21,000 --> 00:06:24,000
So I will just go ahead and open my terminal.

121
00:06:25,000 --> 00:06:27,000
Please make sure to go to the simple RNN folder.

122
00:06:27,000 --> 00:06:32,000
Then only you will be able to execute it because as you know, I have also created simple RNN and similarly

123
00:06:32,000 --> 00:06:37,000
when LSTM will be working, we'll create another folder and we will be working in the similar way.

124
00:06:37,000 --> 00:06:38,000
Okay.

125
00:06:38,000 --> 00:06:43,000
So now here what I'm actually going to do is that I'm just going to go ahead and write Streamlit run

126
00:06:43,000 --> 00:06:44,000
main.py file.

127
00:06:44,000 --> 00:06:45,000
Okay.

128
00:06:45,000 --> 00:06:48,000
So here is my URL.

129
00:06:48,000 --> 00:06:51,000
Uh that has been loaded okay.

130
00:06:51,000 --> 00:06:52,000
Let's do one thing.

131
00:06:52,000 --> 00:06:59,000
Let's I have also already created in my prediction dot ipynb some text and all we have used, right?

132
00:06:59,000 --> 00:07:00,000
I'll copy that same text.

133
00:07:01,000 --> 00:07:02,000
The movies.

134
00:07:02,000 --> 00:07:05,000
This movie was fantastic and so thrilling.

135
00:07:05,000 --> 00:07:07,000
Okay, and then we will try to use this.

136
00:07:07,000 --> 00:07:08,000
Let's see.

137
00:07:08,000 --> 00:07:09,000
So quickly.

138
00:07:09,000 --> 00:07:11,000
Uh, here I'm going to copy and paste it.

139
00:07:11,000 --> 00:07:12,000
This movie was fantastic.

140
00:07:12,000 --> 00:07:16,000
The acting was great and the plot was thrilling.

141
00:07:16,000 --> 00:07:21,000
So once I classify it, you'll be able to see, wow, this looks good, right?

142
00:07:21,000 --> 00:07:26,000
My sentiment is positive prediction is 0.811.

143
00:07:26,000 --> 00:07:27,000
Let's go ahead and try something.

144
00:07:28,000 --> 00:07:33,000
The movie was scary.

145
00:07:36,000 --> 00:07:38,000
I did not like it.

146
00:07:40,000 --> 00:07:45,000
But the critics is good, right?

147
00:07:46,000 --> 00:07:47,000
I'll just go ahead and classify it.

148
00:07:47,000 --> 00:07:53,000
So sentiment, it shows positive because it does not care about my feeling what exactly it is.

149
00:07:53,000 --> 00:07:57,000
But the prediction score that I am able to get is 0.85, which is good enough, right?

150
00:07:58,000 --> 00:08:03,000
Now the next step is that you can go to the Streamlit cloud, okay and do the deployment.

151
00:08:03,000 --> 00:08:06,000
I've already shown you how to probably do the deployment.

152
00:08:06,000 --> 00:08:08,000
So this will be one assignment for you.

153
00:08:08,000 --> 00:08:10,000
Go ahead and upload all the files in your GitHub.

154
00:08:10,000 --> 00:08:14,000
And from here you can just go ahead and deploy in the Streamlit cloud.

155
00:08:14,000 --> 00:08:17,000
Again I'm going to keep this as an assignment guys.

156
00:08:17,000 --> 00:08:23,000
Uh but I'll not be uploading that specific video, so I hope you like this entire session wherein we

157
00:08:23,000 --> 00:08:30,000
discussed about so many things we discussed about, uh, how to probably create or work with RNN again,

158
00:08:30,000 --> 00:08:35,000
completely end to end projects, from embeddings to training, a simple RNN to creating this H5 file.

159
00:08:35,000 --> 00:08:37,000
You know, everything we basically did, right?

160
00:08:37,000 --> 00:08:40,000
So yes, uh, this was it for my side.

161
00:08:40,000 --> 00:08:41,000
I hope you liked this particular video.

162
00:08:41,000 --> 00:08:42,000
I'll see you in the next video.

163
00:08:42,000 --> 00:08:42,000
Thank you.

164
00:08:42,000 --> 00:08:43,000
Take care.

165
00:08:43,000 --> 00:08:43,000
Bye bye.

