I am trying to do POS tagging using the spaCy module in Python.
Here is my code for the same
from spacy.en import English, LOCAL_DATA_DIR
import spacy.en
import os
data_dir = os.environ.get('SPACY_DATA', LOCAL_DATA_DIR)
nlp = English(parser=False, tagger=True, entity=False)
def print_fine_pos(token):
return (token.tag_)
def pos_tags(sentence):
sentence = unicode(sentence, "utf-8")
tokens = nlp(sentence)
tags = []
for tok in tokens:
tags.append((tok,print_fine_pos(tok)))
return tags
a = "we had crispy dosa"
print pos_tags(a)
Output:
[(We , u'PRP'), (had , u'VBD'), (crispy , u'NN'), (dosa, u'NN')]
Here it returns crispy as a noun instead of an adjective. However, if I use a test sentence like
a="we had crispy fries"
It recognizes that crispy is an adjective. Here is the output:
[(we , u'PRP'), (had , u'VBD'), (crispy , u'JJ'), (fries, u'NNS')]
I think the primary reason why crispy wasn't tagged as an adjective in the first case was because dosa was tagged as 'NN' whereas fries was tagged as 'NNS' in the second case.
Is there any way I can get crispy to be tagged as an adjective in the second case too?