What is NLTK POS tagger asking me to download?

Pearl picture Pearl · Dec 21, 2011 · Viewed 44.9k times · Source

I just started using a part-of-speech tagger, and I am facing many problems.

I started POS tagging with the following:

import nltk
text=nltk.word_tokenize("We are going out.Just you and me.")

When I want to print 'text', the following happens:

print nltk.pos_tag(text)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "F:\Python26\lib\site-packages\nltk\tag\__init__.py", line 63, in pos_tag
tagger = nltk.data.load(_POS_TAGGER)
File "F:\Python26\lib\site-packages\nltk\data.py", line 594, in load
resource_val = pickle.load(_open(resource_url))
File "F:\Python26\lib\site-packages\nltk\data.py", line 673, in _open
 return find(path).open()
 File "F:\Python26\lib\site-packages\nltk\data.py", line 455, 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:

>>> nltk.download().

 Searched in:
    - 'C:\\Documents and Settings\\Administrator/nltk_data'
    - 'C:\\nltk_data'
    - 'D:\\nltk_data'
    - 'E:\\nltk_data'
    - 'F:\\Python26\\nltk_data'
    - 'F:\\Python26\\lib\\nltk_data'
    - 'C:\\Documents and Settings\\Administrator\\Application Data\\nltk_data'

I used nltk.download() but it did not work.

Answer

Pearl picture Pearl · Dec 22, 2011

When you type nltk.download() in Python, an NLTK Downloader interface gets displayed automatically.
Click on Models and choose maxent_treebank_pos_. It gets installed automatically.

import nltk 
text=nltk.word_tokenize("We are going out.Just you and me.")
print nltk.pos_tag(text)
[('We', 'PRP'), ('are', 'VBP'), ('going', 'VBG'), ('out.Just', 'JJ'),
 ('you', 'PRP'), ('and', 'CC'), ('me', 'PRP'), ('.', '.')]