Text: BadZipfile

Created on 8 Jan 2018  路  6Comments  路  Source: pytorch/text

python 2.7
torchtext 0.2.1

trying to build the vocab:

my_text.build_vocab(train, vectors=GloVe(name='840B', dim=300))

results in error:

  File "/home/noa/miniconda2/lib/python2.7/site-packages/torchtext/vocab.py", line 330, in __init__
    super(GloVe, self).__init__(name, url=url, **kwargs)
  File "/home/noa/miniconda2/lib/python2.7/site-packages/torchtext/vocab.py", line 223, in __init__
    self.cache(name, cache, url=url)
  File "/home/noa/miniconda2/lib/python2.7/site-packages/torchtext/vocab.py", line 251, in cache
    with zipfile.ZipFile(dest, "r") as zf:
  File "/home/noa/miniconda2/lib/python2.7/zipfile.py", line 770, in __init__
    self._RealGetContents()
  File "/home/noa/miniconda2/lib/python2.7/zipfile.py", line 813, in _RealGetContents
    raise BadZipfile, "File is not a zip file"
zipfile.BadZipfile: File is not a zip file

Most helpful comment

Looks related to https://github.com/pytorch/text/issues/158.
The easiest fix is to delete the GloVe zipfile and try again, it may be cached in /home/noa/miniconda2/lib/python2.7/site-packages/torchtext/.data/

All 6 comments

Looks related to https://github.com/pytorch/text/issues/158.
The easiest fix is to delete the GloVe zipfile and try again, it may be cached in /home/noa/miniconda2/lib/python2.7/site-packages/torchtext/.data/

@nelson-liu thank you very much!
I can't even find a hidden .data dir....
I tried uninstalling and reinstalling torchtext. Any idea what else I can try?

Thanks :)

oops, not a hidden .data dir, but .vector_cache. It might be in the torchtext install file, or in where you ran the script...

@jekbradbury what do you think about moving the default cache dir to ~/torchtext_data, like scikit-learn has ~/scikit_learn_data and nltk uses ~/nltk_data?

@nelson-liu Thank you very much! I still have an error (different one)
I have tried removing the files and re-installing

  File "/home/ubuntu/anaconda3/envs/pytorch_p27/lib/python2.7/site-packages/torchtext/vocab.py", line 331, in __init__
    super(GloVe, self).__init__(name, url=url, **kwargs)
  File "/home/ubuntu/anaconda3/envs/pytorch_p27/lib/python2.7/site-packages/torchtext/vocab.py", line 224, in __init__
    self.cache(name, cache, url=url)
  File "/home/ubuntu/anaconda3/envs/pytorch_p27/lib/python2.7/site-packages/torchtext/vocab.py", line 314, in cache
    torch.save((self.itos, self.stoi, self.vectors, self.dim), path_pt)
  File "/home/ubuntu/anaconda3/envs/pytorch_p27/lib/python2.7/site-packages/torch/serialization.py", line 134, in save
    return _with_file_like(f, "wb", lambda f: _save(obj, f, pickle_module, pickle_protocol))
  File "/home/ubuntu/anaconda3/envs/pytorch_p27/lib/python2.7/site-packages/torch/serialization.py", line 116, in _with_file_like
    return body(f)
  File "/home/ubuntu/anaconda3/envs/pytorch_p27/lib/python2.7/site-packages/torch/serialization.py", line 134, in <lambda>
    return _with_file_like(f, "wb", lambda f: _save(obj, f, pickle_module, pickle_protocol))
  File "/home/ubuntu/anaconda3/envs/pytorch_p27/lib/python2.7/site-packages/torch/serialization.py", line 203, in _save
    serialized_storages[key]._write_file(f)
RuntimeError: unexpected EOF. The file might be corrupted.

I found the glove.6B.zip file in about two seconds by entering

locate vector_cache

into my Terminal

Was this page helpful?
0 / 5 - 0 ratings