Reputation: 13
I want to use NLTK to recognize the difference between "red dress" and "dress shoes". The part of speech is the same for both, and none of the taggers I have tried have worked.
I'm aware that POS tagger can only pick up on one token at a time, which poses some problems. I'm very new to NLTK, and I'm sure I'm just missing something very basic here.
Upvotes: 1
Views: 208
Reputation: 7519
Try Spacy
pip install spacy
Here is a small example to parse and visualize "dress shoes"
:
import spacy
from spacy import displacy
nlp = spacy.load('en')
doc = nlp("dress shoes")
displacy.serve(doc, style='dep')
The relation between red
(adjective) to dress
(noun) is an adjectival modifier (amod
), while the relation between dress
(noun) and shoes
(noun) is a compound.
These can be accessed via token.dep_
(for dependencies) and token.pos_
(for part of speech). Documentation here
Upvotes: 2