Determine the Part of Speech of Words in Sentence Using Python NLTK

In this tutorial, we will introduce the way to determine the part of speech of words in a sentence. We will use python nltk to implement.

1. Import libraries

from nltk import pos_tag
from nltk import word_tokenize

2. Create a sentence

text_data = "Tom loved outdoor running"

3. Determine the part of speech of words in sentence

text_tagged = pos_tag(word_tokenize(text_data))

# Show parts of speech
print(text_tagged)

You will get the result:

[('Tom', 'NNP'), ('loved', 'VBD'), ('outdoor', 'RP'), ('running', 'VBG')]

Here is a simple list of part of speech in nltk.

Tag Part Of Speech
NNP Proper noun, singular
NN Noun, singular or mass
RB Adverb
VBD Verb, past tense
VBG Verb, gerund or present participle
JJ Adjective
PRP Personal pronoun

If you plan to know a full list of part of speech, you can read:

A Full List of Part-of-Speech of Word in NLTK – NLTK Tutorial