Search code examples
pythonnlpnltkstanford-nlppos-tagger

NLTK can't find the Stanford POS tagger model file


I am trying to use StanfordPOSTagger from the NLTK. I downloaded Stanford POS full tagger. I have set

CLASSPATH=/home/waheeb/Stanford_Tools/stanford-postagger-full-2015-12-09  /stanford-postagger.jar
STANFORD_MODELS=home/waheeb/Stanford_Tools/stanford-postagger-full-2015-12-09/models

When I type the following in python:

>>> from nltk.tag import StanfordPOSTagger
>>> st = StanfordPOSTagger('english-bidirectional-distsim.tagger')

I get the following error:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/waheeb/anaconda2/lib/python2.7/site-packages/nltk/tag /stanford.py", line 136, in __init__
super(StanfordPOSTagger, self).__init__(*args, **kwargs)
File "/home/waheeb/anaconda2/lib/python2.7/site-packages/nltk/tag/stanford.py", line 56, in __init__
env_vars=('STANFORD_MODELS',), verbose=verbose)
File "/home/waheeb/anaconda2/lib/python2.7/site-packages /nltk/internals.py", line 573, in find_file
file_names, url, verbose))
File "/home/waheeb/anaconda2/lib/python2.7/site-packages/nltk/internals.py", line 567, in find_file_iter
raise LookupError('\n\n%s\n%s\n%s' % (div, msg, div))

LookupError:

=========================================================================
NLTK was unable to find the english-bidirectional-distsim.tagger file!
Use software specific configuration paramaters or set the TANFORD_MODELS  environment variable.
==========================================================================

Why is that??


Solution

  • You forgot to use export in the command line before calling your python script. I.e.

    alvas@ubi:~$ export STANFORDTOOLSDIR=$HOME
    alvas@ubi:~$ export CLASSPATH=$STANFORDTOOLSDIR/stanford-postagger-full-2015-12-09/stanford-postagger.jar
    alvas@ubi:~$ export STANFORD_MODELS=$STANFORDTOOLSDIR/stanford-postagger-full-2015-12-09/models
    alvas@ubi:~$ python
    

    For more details see https://gist.github.com/alvations/e1df0ba227e542955a8a


    Similar problems includes: