Part of speech (pos) tagging in nlp with example
In this tutorial, you will learn how to tag a part of speech in nlp. We are going to use NLTK standard library for this program.
First we need to import nltk library and word_tokenize and then we have divide the sentence into words. Next step is to call pos_tag() function using nltk.
import nltk
from nltk.tokenize import word_tokenize
text = word_tokenize("The quick brown fox jumps over the lazy dog")
print(nltk.pos_tag(text))
Output:
[(‘The’, ‘DT’), (‘quick’, ‘JJ’), (‘brown’, ‘NN’), (‘fox’, ‘NN’), (‘jumps’, ‘VBZ’), (‘over’, ‘IN’), (‘the’, ‘DT’), (‘lazy’, ‘JJ’), (‘dog’, ‘NN’)]