Closed Deltaus closed 6 years ago
It seems that you're using a model that was saved this way:
torch.save(nli_net.state_dict(), os.path.join(params.outputdir, params.outputmodelname))
(https://github.com/facebookresearch/InferSent/blob/master/train_nli.py#L266) which save both the encoder and the classifier, while you should have used the one saved this way (last line of train_nli.py) :
torch.save(nli_net.encoder.state_dict(), os.path.join(params.outputdir, params.outputmodelname + '.encoder.pkl'))
(https://github.com/facebookresearch/InferSent/blob/master/train_nli.py#L302) which saves just the encoder.
Oh you're right. Thx.
When I tried to evaluate the model trained with the updated versions of InferSent and SentEval, I got: Traceback (most recent call last): File "infersent.py", line 63, in
model.load_state_dict(torch.load(MODEL_PATH))
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/torch/nn/modules/module.py", line 721, in load_state_dict
self.class.name, "\n\t".join(error_msgs)))
RuntimeError: Error(s) in loading state_dict for InferSent:
Missing key(s) in state_dict: "enc_lstm.weight_ih_l0", "enc_lstm.weight_hh_l0", "enc_lstm.bias_ih_l0", "enc_lstm.bias_hh_l0", "enc_lstm.weight_ih_l0_reverse", "enc_lstm.weight_hh_l0_reverse", "enc_lstm.bias_ih_l0_reverse", "enc_lstm.bias_hh_l0_reverse".
Unexpected key(s) in state_dict: "encoder.enc_lstm.weight_ih_l0", "encoder.enc_lstm.weight_hh_l0", "encoder.enc_lstm.bias_ih_l0", "encoder.enc_lstm.bias_hh_l0", "encoder.enc_lstm.weight_ih_l0_reverse", "encoder.enc_lstm.weight_hh_l0_reverse", "encoder.enc_lstm.bias_ih_l0_reverse", "encoder.enc_lstm.bias_hh_l0_reverse", "classifier.0.weight", "classifier.0.bias", "classifier.1.weight", "classifier.1.bias", "classifier.2.weight", "classifier.2.bias".
Could you help find out what's wrong with it? Thanks!