Tagging a single word with the nltk pos tagger tags each letter instead of the word

jksnw picture jksnw · Apr 1, 2015 · Viewed 10.2k times · Source

I'm try to tag a single word with the nltk pos tagger:

word = "going"
pos = nltk.pos_tag(word)
print pos

But the output is this:

[('g', 'NN'), ('o', 'VBD'), ('i', 'PRP'), ('n', 'VBP'), ('g', 'JJ')]

It's tagging each letter rather than just the one word.

What can I do to make it tag the word?

Answer

kasravnd picture kasravnd · Apr 1, 2015

nltk.tag.pos_tag accepts a list of tokens, separate and tags its elements. Therefore you need to put your words in an iterable like list:

>>> nltk.tag.pos_tag(['going'])
[('going', 'VBG')]