Search code examples
pythonnltktypeerrorstanford-nlp

How to import Stanford POS Tagger


I'm attempting to make use of the Stanford POS Tagger in Python.

home = 'U:/ManWin/My Documents/Research Project'
from nltk.tag.stanford import StanfordPOSTagger as POS_Tag
_path_to_model = home + '/stanford-postagger/models/english-bidirectional-distsim.tagger' 
_path_to_jar = home + '/stanford-postagger/stanford-postagger.jar'
st = POS_Tag(path_to_model=_path_to_model, path_to_jar=_path_to_jar)

Have copied the last line from the answer here: Python NLTK pos_tag not returning the correct part-of-speech tag

Getting the following error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "U:\Python35\site-packages\nltk\tag\stanford.py", line 136, in __init__
    super(StanfordPOSTagger, self).__init__(*args, **kwargs)
TypeError: __init__() got an unexpected keyword argument 'path_to_model'

What do I need to change?


Solution

  • It seems the name of the parameter path_to_model has changed to model_filename. So, replace the last line with:

    st = POS_Tag(model_filename=_path_to_model, path_to_jar=_path_to_jar)

    Or since the parameters are in order, just write:

    st = POS_Tag(_path_to_model, _path_to_jar)