
Now we have seen how we can tags words using NLTK. For example, in our POS tag code, “PRP” stands for Pronoun and “JJ” stands for Adjective. We get a complete list of what the abbreviations mean.

import nltkĪfter running the above code, we get the output.
Pos tagger python code#
The following block of code helps us to decipher the tags provided by NLTK. If you look at the parts-of-speech tags you may get confused by what does “PRP” means or what does “JJ” means. Output:Īs you can see in the output, the words in our input sentence are tagged automatically to their respective parts of speech. Now, we use the POS tagger provided by NLTK to POS tag our words. Output:Īs I had mentioned previously, before POS tagging the words it is necessary that we tokenize our text first. The output of the above code is as follows. Txt = ("We are trying to learn how pos tagging works") On the fourth line, we are tokenizing our text into words and finally printing the tokenized words. This helps to reduce the size of our vector.

On the third line, we are converting our text to lowercase. Next, we define a sentence and assign it to the variable “txt”. As it turns out, we can use NLTK for the task of POS tagging too. The NLTK library is one of the most popular libraries for NLP and for a good reason. Rather than using our own tagset, we usually make use of well-known defined tagsets. This is essential information that the tagger must be given. The parts of speech explains how a word is used in a sentence.Ī tagset is called a set of predefined tags. This the main function or role of a POS tagger. So basically in POS tagging, we are taking the individual words and automatically tagging them with their correct part-of-speech. Thus tagging is a kind of classification. When you visit websites to read articles or blogs, you must have noticed that those articles or blogs are tagged with specific topics. To tag, something means you classify it as something. Now what does this “tagging” in “POS tagging” mean? Okay, so now we know what the parts-of-speech are. Note that this is very basic definition and I have not listed all the grammatical parts. Examples include when, unless, so that, etc. Conjunction – Joins together sentences, phrases, words, etc.Pronoun – Substitutes for a noun or noun phrase.Examples include now, peacefully, carefully, etc. Adverb – represents and describes a verb.Adjective – represents the qualities or states of nouns.Examples include clean, hoping, working, etc. Examples include bottle, Jaipur, tiger, etc. Noun – represents a thing and these things may include a person, place, animal, idea, etc.To give a quick refresher, I have listed a very basic definition of the important parts of speech with some examples. These may include nouns, verbs, adverbs, adjectives, pronouns, conjunction as so on. If you recall your high-school grammar, you may remember that any sentence is made up of several grammatical components. We first have to be familiar with the parts of speech. It may sound confusing at first and so to make things easy to understand we first have to revisit our high school grammar. POS tagging or part-of-speech tagging may be defined as the process of assigning a part of speech to the given word. It is important for other NLP tasks and problems as well. We saw that part-of-speech or POS tagging is necessary for Lemmatization.

Let us start by defining what Part-of-Speech tagging means.
