nltk pos_tag usage

Ashish Singh picture Ashish Singh · Dec 30, 2012 · Viewed 9.3k times · Source

I am trying to use speech tagging in NLTK and have used this command:

>>> text = nltk.word_tokenize("And now for something completely different")

>>> nltk.pos_tag(text)

Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
nltk.pos_tag(text)
File "C:\Python27\lib\site-packages\nltk\tag\__init__.py", line 99, in pos_tag
tagger = load(_POS_TAGGER)
File "C:\Python27\lib\site-packages\nltk\data.py", line 605, in load
resource_val = pickle.load(_open(resource_url))
File "C:\Python27\lib\site-packages\nltk\data.py", line 686, in _open
return find(path).open()
File "C:\Python27\lib\site-packages\nltk\data.py", line 467, in find
raise LookupError(resource_not_found)
LookupError: 
**********************************************************************
Resource 'taggers/maxent_treebank_pos_tagger/english.pickle' not
found.  Please use the NLTK Downloader to obtain the resource:

However, I get an error message which shows:

engish.pickle not found.

I have download the whole corpora and the english.pickle file is there in the maxtent_treebank_pos_tagger

What can I do to get this to work?

Answer

Ram Narasimhan picture Ram Narasimhan · Dec 31, 2012

Your Python installation is not able to reach maxent or treemap.

First, check if the tagger is indeed there: Start Python from the command line.

>>> import nltk

Then you can check using

>>> dir (nltk)

Look through the list to see if maxent and treebank are both there.

Easier would be to type

>>> "maxent" in dir(nltk)
>>> True
>>> "treebank" in dir(nltk)
>>> True

Use nltk.download() --> Models tab and check to see if the treemap tagger shows as installed. You should also try downloading the tagger again.

NLTK Downloader, Models Tab