facebookresearch / InferSent

InferSent sentence embeddings
Other
2.28k stars 471 forks source link

Error in "model.load_state_dict" : IncompatibleKeys #130

Open happypanda5 opened 5 years ago

happypanda5 commented 5 years ago

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 commented 5 years ago

@aconneau please help

aconneau commented 5 years ago

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

happypanda5 commented 5 years ago

@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://github.com/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 commented 5 years ago

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 commented 4 years ago

@aconneau

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

Hopefully you can help

RishabhMaheshwary commented 4 years ago

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".