2

The python code I used for POS Tagging:

>>> import nltk, csv, itertools
>>> sentence = "Unigram taggers are based on a simple statistical algorithm: for each token, assign the tag that is most likely for that particular token."
>>> tokens = nltk.word_tokenize(sentence)
>>> tags = nltk.pos_tag(tokens)
and the error shown is:
>>> tags = nltk.pos_tag(tokens)
Traceback (most recent call last):
  File "<pyshell#7>", line 1, in <module>
    tags = nltk.pos_tag(tokens)
  File "/usr/local/lib/python2.7/dist-packages/nltk/tag/__init__.py", line 99, in pos_tag
    tagger = load(_POS_TAGGER)
  File "/usr/local/lib/python2.7/dist-packages/nltk/data.py", line 605, in load
    resource_val = pickle.load(_open(resource_url))
  File "/usr/local/lib/python2.7/dist-packages/nltk/data.py", line 686, in _open
    return find(path).open()
  File "/usr/local/lib/python2.7/dist-packages/nltk/data.py", line 455, in find
    try: return find(modified_name)
  File "/usr/local/lib/python2.7/dist-packages/nltk/data.py", line 445, in find
    try: return ZipFilePathPointer(p, zipentry)
  File "/usr/local/lib/python2.7/dist-packages/nltk/data.py", line 311, in __init__
    zipfile = OpenOnDemandZipFile(os.path.abspath(zipfile))
  File "/usr/local/lib/python2.7/dist-packages/nltk/data.py", line 738, in __init__
    zipfile.ZipFile.__init__(self, filename)
  File "/usr/lib/python2.7/zipfile.py", line 714, in __init__
    self._GetContents()
  File "/usr/lib/python2.7/zipfile.py", line 748, in _GetContents
    self._RealGetContents()
  File "/usr/lib/python2.7/zipfile.py", line 763, in _RealGetContents
    raise BadZipfile, "File is not a zip file"
BadZipfile: File is not a zip file

Is there any python modules to be included??

What is the solution?

jamylak
  • 128,818
  • 30
  • 231
  • 230
Anand Menon
  • 141
  • 5
  • You might be missing the dataset that the tagger uses: try running `nltk.download()` and make sure you have the Penn Treebank dataset downloaded. – Marius May 30 '13 at 07:00
  • possible duplicate of [bad zip file error in POS tagging in NLTK in python](http://stackoverflow.com/questions/28122980/bad-zip-file-error-in-pos-tagging-in-nltk-in-python) – tripleee Jan 24 '15 at 20:00

1 Answers1

0

Rather than using pos_tag

apply this

nltk.download("maxent_treebank_pos_tagger")
nltk.download("maxent_ne_chunker")
nltk.download("punkt")

first two for pos_tag and last one is for sent_tokenizer