"ImportError: cannot import name StanfordNERTagger" in NLTK

I worked it out.

  1. set the STANFORD_MODELS as you did # I learnt from you, thx!
  2. import nltk.tag.stanford as st
  3. tagger = st.StanfordNERTagger(PATH_TO_GZ, PATH_TO_JAR) # here PATH_TO_GZ and PATH_TO_JAR are the FULL path to where I store the file "all.3class.distsim.crf.ser.gz" and the file "stanford-ner.jar"
  4. now the tagger is usable. # try tagger.tag(‘Rami Eid is studying at Stony Brook University in NY’.split())

It has nothing to do with CLASSPATH.

Hope it helps!


try this approach:

from nltk.tag.stanford import StanfordNERTagger
st = StanfordNERTagger('/usr/share/stanford-ner/classifiers/english.all.3class.distsim.crf.ser.gz', '/usr/share/stanford-ner/stanford-ner.jar')
st.tag('Rami Eid is studying at Stony Brook University in NY'.split())

worked for me!


Here's another approach:

    from nltk.tag.stanford import NERTagger
    import os
    java_path = "/Java/jdk1.8.0_45/bin/java.exe"
    os.environ['JAVAHOME'] = java_path
    st = NERTagger('../ner-model.ser.gz','../stanford-ner.jar')

The NERTagger takes two arguments: the path to the model file and the path to the jar file.

Tags:

Python

Nlp

Nltk