AniSkywalker / SarcasmDetection

Sarcasm detection on tweets using neural network
https://www.aclweb.org/anthology/W/W16/W16-0425.pdf
GNU Lesser General Public License v3.0
129 stars 39 forks source link

Issue with loading model: "You are trying to load a weight file containing 7 layers into a model with 5 layers." #11

Open conorg000 opened 3 years ago

conorg000 commented 3 years ago

Hi there,

Thank you to the authors for making your research, code, and results public. I'm trying to run the model from sarcasm_detection_model_CNN_LSTM_DNN.py but keep coming across this error:

model loaded from file... Traceback (most recent call last): File "sarcasm_detection_model_CNN_LSTM_DNN.py", line 314, in t.load_trained_model(model_file='model.json', weight_file='model.json.hdf5') File "sarcasm_detection_model_CNN_LSTM_DNN.py", line 208, in load_trained_model self.load_model(self._model_file_path + model_file, self._model_file_path + weight_file) File "sarcasm_detection_model_CNN_LSTM_DNN.py", line 215, in load_model self.model.load_weights(model_weight_path) File "C:\Users\Me\Anaconda3\envs\sarcasmpy\lib\site-packages\keras\models.py", line 768, in load_weights topology.load_weights_from_hdf5_group(f, layers, reshape=reshape) File "C:\Users\Me\Anaconda3\envs\sarcasmpy\lib\site-packages\keras\engine\topology.py", line 3365, in load_weights_from_hdf5_group str(len(filtered_layers)) + ' layers.') ValueError: You are trying to load a weight file containing 7 layers into a model with 5 layers.

The model.json says that it uses Keras v 2.1.6, which I'm using. I'm also working with Python 3.7.

Has anyone come across this? Thanks for your help.

conorg000 commented 3 years ago

The model.json file seems to be missing conv1d_2 and lstm_2. Adding them has fixed the issue, though I'm not sure if that's the right way to go about it.

Is there an up-to-date model.json which matches the weights shared on Google Drive?

Thanks :)