Crista23 Crista23 - 4 months ago 85
Python Question

Stanford NER Tagger in NLTK

I am trying to import the Stanford Named Entity Recognizer in Python. This is already built in the NLTK package. However, my code below is not working:

from nltk.tag.stanford import NERTagger
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name NERTagger


What could be the cause? In all articles I read it works by default. Thank you.

Answer

That class has been renamed to StanfordNERTagger in version 3.0.3 (commit 190673c7).

So for nltk >= 3.0.3 you need to use this import instead:

from nltk.tag import StanfordNERTagger

(You could also do from nltk.tag.stanford import StanfordNERTagger, but since they now also provide a convenience import in the nltk.tag module, that's probably what they want use to use, that import location should be less prone to future changes like this.)