Hello guys.
So we are going to continue the discussion with respect to NLP.
And in this video we are going to discuss about something called as parts of speech tagging.
Now I hope you have understood in Lemmatization this parts of speech tagging, it plays a very important
role because if we are giving it as a verb or a noun, right?
Based on that, you know, we are able to get the root form of the specific word, right.
And we have seen lot of examples with respect to this.
In this video, we will try to understand that how many different types of parts of speech tagging is
there.
And with respect to that, we'll also see a practical example.
Let's say that if I am actually getting a sentence like this, Taj Mahal is a beautiful monument.
How with the help of NLTK, we are able to understand that and you'll be seeing that the output of this,
let's say I'm just taking this particular example.
The output for this will be that Tajammul will be considered as a noun.
Beautiful may be considered as a adjective.
Monument can be considered as a verb, right?
I'm just giving as an example, but we'll definitely see this particular example.
And we'll also see some extensive example altogether.
Now, with respect to parts of speech, how many different types of things are there.
Right.
So here you have something called as CC coordinating conjunction CD Cardinal dejate de determinar x.
Uh, existential.
There f w foreign word I n preposition jj adjective jj r adjective.
So that basically means suppose if I'm giving a sentence automatically, it will be able to categorize
in all this specific different different parts of speech automatically with the help of NLTK.
And similarly there are a lot of things over here.
You can see a personal, now not personal pronoun like, uh, for the letters like hi, he she will
be put up as PRP, right?
It'll be getting a tag called as PRP if you see over here some more example like AAB adverb right?
Words like very silently will be put up over here rb r.
It is also above but it will be like a comparative one right.
So example like better.
So you have r bs adverb like this.
You have lot.
Right.
So what I'm actually going to do is that I'm going to take a very good example.
And one assignment you just have to do is that take this particular simple example and try to find out
and try to write down the comment in the comment section.
Okay.
Now over here, you'll be able to see that I have this particular speech of doctor, uh, A.P.J. Abdul
Kalam.
And obviously the same example I have shown you in the stop words example itself.
Right.
So I'm going to take this very simple okay.
And then let's consider that, uh, in this parts of speech tagging I really wanted to perform uh,
stemming let's say, but, uh, I don't want to perform any stemming because I want to see for each
and every word.
Right.
What kind of POS speech tagging will be there.
So no need to import all these things.
Okay.
So I'm just going to, uh, remove all these things instead.
I'll just be focusing on importing NLTK.
So I'll write import NLTK.
And then here you can see that I'm just writing NLTK dot sent to underscore tokenize.
So that basically means I'm actually converting the paragraph into sentences.
So let me just execute this.
And once I get it here you'll be able to see all the sentences.
So in this example I'm trying to show you that how for each and every word we'll be able to find out
the POS tag.
Okay.
So the next thing is that now what I'm actually going to do is that apply the stopwords.
Okay, and no need to apply the Stopwords also because we don't want to remove anything.
So I'm just going to uncomment all these things and I'm going to say that we will find out the POS tag
okay.
Find out the POS tag.
Right.
So this is perfect.
Uh, till here we are going.
Good.
Right now, what I'm actually doing over here, uh, it is very much clear, very much easy to understand
that, uh, over here, we are able to, uh, do that, like I'm doing.
I'm just simply putting a for loop over here with respect to all the sentences and this sentences here,
what I'm doing is that I'm just trying to convert this into words.
I'll be getting a list of words.
And now no need to do the stemming.
So I'll just remove the stemming.
Okay.
And uh, over here I'll just add this w word itself.
I'll be getting the word.
And I'm just saying that if the word is not in set stop words dot words of English.
So, uh, let's see that.
Okay?
I told you that I'll not apply stop words, but let's let us just remove the stop words, because some
of the stop words will not be playing an important role.
So in order to do that, uh, I'll just, uh, import all the libraries with respect to stop word.
And obviously over here, I had already written that.
But let me do Ctrl Z.
So here it is.
Stop words with respect to this and I will also remove this.
Okay, so two things and I will just import the stop words.
So I'm writing that from Anticorpos import stop words.
And now let's apply for this same thing.
Whatever we have done in the previous time.
Uh the same part we are actually repeating it.
So here you can see that for word for word in words if word not in this particular stop word with respect
to English, I'm going to take all the words and then I'm just going to comment down this code, because
I'm not going to join them back into the sentences, because I need to understand what POS tag each
word will be getting.
So I will basically write print.
Okay, so here I'm just going to write a simple print statement.
And in this particular print statement uh, before printing this also what I can do, I can write basically
this in the next line here I'll be using something called as NLTK dot post tag.
Okay, so here you'll be able to see post tag.
I can also apply it for words and I can also apply it for sentences.
Right now I'm just going to apply this for the words itself.
So this is my entire thing.
And uh here I'll just create a uh pos underscore tag variable.
So this will basically indicate that everything is getting stored over here.
And with respect to that I'm just going to print this.
Now.
Let me revise it again.
What all things we did.
I'm iterating through each and every sentence, and then I'm converting this particular sentence into
words.
And for each words I'm applying stop words.
Initially I thought that I'll not apply, but let's apply the stop words because see, at the end of
the day they are so small.
Small words like isn't the he she.
I don't want this particular words right.
So I'll, I'll remove the stop words and I will take all the list of words over here.
I do not apply stemming because I really need to find out whatever words are present over here.
It needs to be, uh, like this.
Analytic will be able to find out all the different, different types of, uh, parts of speech tagging
with respect to that.
And then I just apply this particular simple code that is NLTK dot post underscore tag of words.
And then finally I'm printing it.
So here you can see I'll just execute it I'm getting some error.
I'm not going to, uh, make sure that nothing I'm not going to like if there is an error, I'm not
going to edit the video.
So here it says NLTK dot download average perceptron trigger tagger.
So I definitely require this particular tagger to apply post tag.
So what I will do is that I'll just go and uh copy and paste this.
You also have to do this because you will also face this particular error.
Now here you can see that it has been downloaded.
Now if I probably go ahead and run it now here you'll be seeing for the first sentence I is basically
a PRP.
PRP basically means what?
So if you probably go over here and see personal pronoun and I have given the examples like I he she
right.
Similarly you'll be able to see that other words like three three CD vision Gnns uh, India NLP.
Let's go ahead and see what is PNP.
Because India has been categorized with PNP.
So PNP is nothing but proper noun singular.
It's like a name place.
It can be monuments.
It can be different, different things like NP.
S is proper, proper noun plural.
Americans, Indians like that.
Right?
So all those things are there.
And how easily it is being able to simply, you know, just show the post tags, right, with the help
of NLTK.
This is an amazing thing.
And here, with respect to all the sentences, you will be able to see this okay?
And that is how powerful NLTK is.
Uh, let me just show you whatever assignment that I had actually given you.
Right.
So this was the sentence over here.
I'm just going to copy this, and I'm just going to take this entirely, okay.
And let's see whether we'll be able to do it.
So I'm just going to use NLTK dot pos accents.
Now let's see with respect to sense.
Also if you are able to do this or not.
So I'm just going to put this Taj Mahal is a beautiful monument and I'm going to execute this.
Now here you can see T okay.
Now in this particular case what has happened each and every word has been considered over here.
Right.
This should not basically happen.
So what I'm actually going to do is that I'm going to basically use post tag.
Let's see what is the output with respect to this.
So here also the same thing is coming.
So the simple way in this particular scenario is that again I'll put a for loop for I in.
Okay, I'll say sentence or I in this entire quotes I will just put this.
I'll go through each and every word over here okay.
And I can write dot split with respect to this.
Because if I'm just using this dot split this is my string okay.
And if I probably use dot split, you'll be able to see that what I'm getting.
Taj Mahal is a beautiful monument.
Right.
So for I in this now and here you can see that I'm iterating through each and every things right.
Each and every word.
So I'm just going to print NLTK dot pos tag.
And I am actually going to use this.
So you can here you can uh just go ahead and write this specific I or instead of writing this, I,
I'll just write words.
Okay.
For word in this and I'll take a dot post tag.
I'm just going to use this specific word now here.
Uh, still, uh, there is an issue because I am iterating through each and every thing.
So if I probably get this entire thing, uh, with respect to the list, you'll be able to see.
Okay, uh, let's see, let's see, let's see.
There's something again.
I'm not going to delete it.
I'm just going to see what is the word over here.
So I'm getting this okay.
And if I take this NLTK dot pos tag with respect to this specific word.
Uh, okay.
This is the problem.
Let's see.
What did I do over here?
Uh, I need to provide a list of words.
Okay.
And then I'll be applying this.
Okay.
This is the problem.
Okay?
Now, uh, all you have to do is that I don't have to give word by word.
If it is giving word by word here, you will be able to see for every single character it is giving
this right.
I really need to provide the list of words.
So if I probably just copy this part and put it over here and remove all these things.
Now what I have actually done after this error, see, I'm not editing this particular video with respect
to this error because you really need to see all these errors.
In short, when I give like this, I'll be getting a list of words.
So if I execute this here now you can see that Taj.
It is showing an NP Mahal and NP is is VBS a TT beautiful JJ monument n now see what did I do over here?
POS tag.
Basically, uh, whatever parameter we give, we should be giving in the form of list of words.
And if you are able to do that, we will be getting the same answer.
Right.
So guys, I hope you are able to understand parts of speech tagging.
I definitely got some errors, but I really wanted to show you all the errors that we are getting and
based on that, how you can solve this, right?
That is the main purpose.
So the error part, I'm not going to edit it, I'm going to keep it like that.
So please make sure that you practice.
And yes, this was it.
I will see you all in the next video.
Thank you.