facebookresearch / InferSent

InferSent sentence embeddings
Other
2.28k stars 471 forks source link

Not able to load trained model, UnpicklingError: invalid load key, '<' #110

Closed gopinath-r closed 5 years ago

gopinath-r commented 5 years ago

Hi,

I am facing issue while loading the trained model.

from models import InferSent V = 2 MODEL_PATH = 'encoder/infersent%s.pkl' % V params_model = {'bsize': 64, 'word_emb_dim': 300, 'enc_lstm_dim': 2048, 'pool_type': 'max', 'dpout_model': 0.0, 'version': V} infersent = InferSent(params_model) infersent.load_state_dict(torch.load(MODEL_PATH))

I am getting the following error

UnpicklingError Traceback (most recent call last)

in 8 'pool_type': 'max', 'dpout_model': 0.0, 'version': V} 9 infersent = InferSent(params_model) ---> 10 infersent.load_state_dict(torch.load("/home/gopinathr/Documents/projects/Conversation_engine/Sentence_Clustering/InferSent-master/encoder/infersent1.pkl")) ~/Documents/projects/Conversation_engine/virtualenv/lib/python3.5/site-packages/torch/serialization.py in load(f, map_location, pickle_module) 259 location = location_tag(obj) 260 serialized_storages[obj_key] = obj --> 261 is_view = obj._cdata != obj._cdata 262 if is_view: 263 view_metadata = (str(obj._cdata), offset, obj.size()) ~/Documents/projects/Conversation_engine/virtualenv/lib/python3.5/site-packages/torch/serialization.py in _load(f, map_location, pickle_module) 397 current_source = inspect.getsource(container_type) 398 except Exception: # saving the source is optional, so we can ignore any errors --> 399 warnings.warn("Couldn't retrieve source code for container of " 400 "type " + container_type.__name__ + ". It won't be checked " 401 "for correctness upon loading.") **UnpicklingError: invalid load key, '<'.** My environment Details are, python 3.5 torch == 1.0.0 I am not able to load the pickle file even using pickle module. So is the model corrupted or is there a specific version of torch has to be used
sandeepeecs commented 5 years ago

Thanks gopi,

This issue is because the infersent models were not available in the given link. So whatever the models that are been downloaded they doesn't contain any data.

These links on the README page are expired.

curl -Lo encoder/infersent1.pkl https://s3.amazonaws.com/senteval/infersent/infersent1.pkl curl -Lo encoder/infersent2.pkl https://s3.amazonaws.com/senteval/infersent/infersent2.pkl

Facing the same issue :

from models import InferSent model_version = 2 MODEL_PATH = "/mnt/ebs2/apis/pretrained/infersent/infersent%s.pkl" % model_version params_model = {'bsize': 64, 'word_emb_dim': 300, 'enc_lstm_dim': 2048, ... 'pool_type': 'max', 'dpout_model': 0.0, 'version': model_version}

model = InferSent(params_model) model.load_state_dict(torch.load(MODEL_PATH))

import torch model.load_state_dict(torch.load(MODEL_PATH)) Traceback (most recent call last): File "", line 1, in File "/mnt/ebs2/apis/mlengine/p2env/lib/python2.7/site-packages/torch/serialization.py", line 368, in load return _load(f, map_location, pickle_module) File "/mnt/ebs2/apis/mlengine/p2env/lib/python2.7/site-packages/torch/serialization.py", line 532, in _load magic_number = pickle_module.load(f) cPickle.UnpicklingError: invalid load key, '<'.

jkamalu commented 5 years ago

I am also facing the same issue (which I refiled because this is not resolved).

berfubuyukoz commented 5 years ago

This repo requires a banner "shelved" on top of Readme to save people's time I think. Or else the pickle file can be provided again. :)))