Skip to content
This repository has been archived by the owner on Oct 31, 2023. It is now read-only.

Error in "model.load_state_dict" : IncompatibleKeys #130

Open
happypanda5 opened this issue Jun 30, 2019 · 6 comments
Open

Error in "model.load_state_dict" : IncompatibleKeys #130

happypanda5 opened this issue Jun 30, 2019 · 6 comments

Comments

@happypanda5
Copy link

I am trying to run the demo file available with InferSent on Google Colab but while doing so, in particular, the line model.load_state_dict(torch.load(MODEL_PATH)), I get the following error

IncompatibleKeys(missing_keys=[], unexpected_keys=[])

I run the same demo file without change. Can you help me regarding this error?

@happypanda5
Copy link
Author

@aconneau please help

@aconneau
Copy link
Contributor

aconneau commented Jul 8, 2019

Could you try to "git pull" once again and see if you still obtain this error?

@happypanda5
Copy link
Author

happypanda5 commented Jul 10, 2019

@aconneau

Same error.

"""InferSent attempt 4 (redo Facebook).ipynb

I get an error with this

IncompatibleKeys(missing_keys=[], unexpected_keys=[])
"""

import os

!git clone https:/facebookresearch/InferSent --quiet

#-# Download word vectors

os.mkdir('GloVe')
!curl -Lo GloVe/glove.840B.300d.zip http://nlp.stanford.edu/data/glove.840B.300d.zip
!unzip GloVe/glove.840B.300d.zip -d GloVe/

os.mkdir('fastText')
!curl -Lo fastText/crawl-300d-2M.vec.zip https://dl.fbaipublicfiles.com/fasttext/vectors-english/crawl-300d-2M.vec.zip
!unzip fastText/crawl-300d-2M.vec.zip -d fastText/

#-# Download InferSent models

os.mkdir('encoder')
!curl -Lo encoder/infersent1.pkl https://dl.fbaipublicfiles.com/infersent/infersent1.pkl
!curl -Lo encoder/infersent2.pkl https://dl.fbaipublicfiles.com/infersent/infersent2.pkl

#-# Download NLTK tokeniser

import nltk
nltk.download('punkt')

#-# Load Pre-trained models
import torch

from InferSent.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))

os.chdir('/content/InferSent')

@aconneau
Copy link
Contributor

I am not able to reproduce your error. What you sent in the above message is the code of the ipython notebook but not the full error message.

@happypanda5
Copy link
Author

@aconneau

Please find here a Colab notebook which will recreate the error.

Hopefully you can help

@RishabhMaheshwary
Copy link

I am getting the following error:

RuntimeError: Error(s) in loading state_dict for NLINet:
Missing 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.1.weight", "classifier.1.bias", "classifier.4.weight", "classifier.4.bias", "classifier.7.weight", "classifier.7.bias".
Unexpected 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".

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants