So guys, here you can see the training has been stopped in 50 epochs because I only did till 50 epochs.
And here I'm able to get an accuracy till 40%.
It started from 0.03 right 3% to 40%.
So if you probably do for another 50 epochs, I think the accuracy will keep on increasing.
Okay.
Now what we'll do is that we'll try to create a function okay, which will be able to predict the next
word.
Now see this.
So this is nothing but a prediction.
The next word here we need to give the model tokenizer text and max sequence.
Okay.
So first of all we will use the tokenizer.
We'll convert that into sequence.
How we did it.
We'll say hey if length of this particular token list is greater than or equal to max sequence length,
right at that point of time, we will just make sure to ensure the sequence length matches the sequence
length minus one.
Right.
So this is the operation that we are specifically doing.
We'll take the token list.
We will give the indexing from this particular value.
Right.
Uh, like max sequence length minus one.
And most of the time you'll be able to see that when we get this particular value from this value till
the end, we are going to take that entire token list, right.
Then we are going to apply the pad sequence, uh, where we will specifically use pre padding.
Then we will go ahead and use model dot predict on this particular token list.
And we will get the predicted word index wherein we'll say hey whichever has the highest probability
with respect to all the outputs, take one.
Uh, I mean, uh, take that specific value and show me that particular index, and then I will convert
that particular index into a word.
So I'll write for word comma index in tokenizer dot word underscore index dot item.
If index is equal to predicted word, return that specific word.
Now you'll be able to understand it once I probably go ahead and execute it.
Let's say this is my input text Okay.
Now input text is that I will say hey to be or not to be.
Okay.
Suppose let's say this is my input text.
I will go ahead and write.
This is my print.
Uh f I will just go ahead and write my input.
Text is colon nothing.
But here I'm going to basically go ahead and give my input text.
So this will basically be my input text over here.
Okay.
And then I will go ahead and write max sequence length.
Max sequence length is equal to model dot input of input of shape of one plus one okay.
So uh plus one uh, you'll be able to see that this will basically be my max sequence length, because
I have to make sure that, uh, whatever max sequence length we have initially taken, that needs to
be same thing, right?
Then we will go ahead and predict our next underscore word.
And here I will just call my predict next word function.
Here I will give my model then my tokenizer okay tokenizer.
Along with this I will also go ahead and give my input text okay.
And then finally let's go ahead and give my max sequence length.
Right.
These are the parameters that I need to give right.
And that is the reason I'm giving this okay.
And finally let's go ahead and print.
And here I will just go ahead and write my next word prediction.
Which will be equal to.
My next underscore word that let's go ahead and execute it.
So to be not to be next word predicted is considered right.
It is good to be or not to be considered right.
So this looks like a very good word.
Okay.
Finally, uh, after doing this I will go ahead and save my entire models so quickly.
Go.
Let's go ahead and save the model that I've actually created.
Okay.
So I'll write model dot save.
And here I'm going to basically use next underscore word.
Word underscore LSTM okay dot h5 file.
So this will basically be my h5 file.
Other than that I will also go ahead and save the tokenizer right.
So tokenizer also needs to be saving because we need to use the same tokenizer what we have created.
So here I will go ahead and write with open tokenizer dot pickle file.
I'll open this particular pickle file and it'll be in my write byte mode.
I will say as handle okay.
This will basically be my context.
Let me just go ahead and write pickle dot dump.
And here let me just import pickle because I will be requiring pickle Pickle okay.
Pickle dot dump.
And here we will dump this entire tokenizer comma handle comma I will use a protocol also over here
this protocol will be equal to and we will use pickle dot highest protocol okay.
Okay.
One assignment.
Just try to find out why this specific thing we specifically use.
Okay.
So this will be an assignment for you.
Come on.
So has no attribute dump.
Uh, dumpy it is written dumpy.
I should have written dump.
Okay.
So once it is executed now in the same folder, you'll be able to see my next word.
LSTM dot h5 and tokenizer dot pickle.
Okay, so here is all my things.
And uh, I can go ahead and use more text if you want.
Okay.
Um, to be bad is better than.
Okay, I'll just try to go ahead and predict it.
It says to be bad is better than.
And.
Okay, so since the model accuracy is a little bit less all the time, you're not going to get the right
output okay.
So you can go ahead and try it out.
But I'll just go ahead and use some more examples from here.
Okay.
Let's say, uh, I'm using this.
Okay.
I don't know, like what exactly these words are, but I'll just try to use this whether it'll be fine
or not.
Let's see.
Okay.
I will use this particular sentence.
And then we are going to do the prediction fantasy.
See it's coming fantasy right.
The prediction is absolutely right.
Right.
Mama horror okay.
Is tis but our fantasy, right?
This is good.
Um.
Uh, let's see some more things.
Uh, I'll say.
Well, born last night of all.
When you and same starry, starry.
I don't know whether this English or something else.
Okay.
Okay, same.
Let's execute it.
Cosine.
It comes as cosine okay.
The exact input here.
We had to get started but it got cosine.
That's okay.
So I hope are you able to understand this now in our next video I'm going to create a Streamlit app.
And we will use all these things.
All this functions.
First of all we will be loading loading our H5 file and all.
And we'll try to convert that into an entire end to end project using Streamlit.
So yes, this was it for my side.
I will see you all in the next video.
Thank you.
Take care.