v Tag Parts Of Speech - Machine Learning

Tag Parts Of Speech

Authors: Chris Albon


# Load libraries
from nltk import pos_tag
from nltk import word_tokenize

Create Text Data

# Create text
text_data = "Chris loved outdoor running"

Tag Parts Of Speech

# Use pre-trained part of speech tagger
text_tagged = pos_tag(word_tokenize(text_data))

# Show parts of speech
[('Chris', 'NNP'), ('loved', 'VBD'), ('outdoor', 'RP'), ('running', 'VBG')]

Common Penn Treebank Parts Of Speech Tags

The output is a list of tuples with the word and the tag of the part of speech. NLTK uses the Penn Treebank parts for speech tags.

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