cuilimeng / dEFEND-web

24 stars 7 forks source link

Inputs to operation sentence_lstm/while_1/Select_1 of type Select must have the same size and shape #6

Open shreeshaa opened 4 years ago

shreeshaa commented 4 years ago

Hi! I was using your project dEFEND code (https://www.dropbox.com/sh/rzczwopo618jyv2/AAA1mI2yvbt6TAfqpcxfjL8va?dl=0) as reference for a project we are working on. But, unfortunately, running the go_defend.py file with the dataset we collected from FakeNewsNet will have some errors. Specifically, the error is caused when model.fit is called and it is in the sentence lstm part. Please find exact error below:

Traceback (most recent call last): File "go_defend.py", line 85, in saved_model_filename=SAVED_MODEL_FILENAME) File "/home/shreeshaa/d/dEFEND-5/fake news detection/dEFEND/defend.py", line 389, in train callbacks=callbacks) File "/home/shreeshaa/anaconda3/envs/d/lib/python3.7/site-packages/keras/engine/training.py", line 1039, in fit validation_steps=validation_steps) File "/home/shreeshaa/anaconda3/envs/d/lib/python3.7/site-packages/keras/engine/training_arrays.py", line 199, in fit_loop outs = f(ins_batch) File "/home/shreeshaa/anaconda3/envs/d/lib/python3.7/site-packages/keras/backend/tensorflow_backend.py", line 2715, in call return self._call(inputs) File "/home/shreeshaa/anaconda3/envs/d/lib/python3.7/site-packages/keras/backend/tensorflow_backend.py", line 2675, in _call fetched = self._callable_fn(*array_vals) File "/home/shreeshaa/anaconda3/envs/d/lib/python3.7/site-packages/tensorflow/python/client/session.py", line 1439, in call run_metadata_ptr) File "/home/shreeshaa/anaconda3/envs/d/lib/python3.7/site-packages/tensorflow/python/framework/errors_impl.py", line 528, in exit c_api.TF_GetCode(self.status.status)) tensorflow.python.framework.errors_impl.InvalidArgumentError: Inputs to operation sentence_lstm/while_1/Select_1 of type Select must have the same size and shape. Input 0: [20,12000] != input 1: [20,100] [[{{node sentence_lstm/while_1/Select_1}}]]

Any advice would be extremely helpful. Thanks!

DeepAccount commented 3 years ago

I am also stuck with same problem. After changing dependencies according to https://github.com/cuilimeng/dEFEND-web/blob/master/requirements.txt. I get a different error You are trying to load a weight file containing 5 layers into a model with 4 layers

Error is coming in load module step self.model = load_model(./static/saved_models/politifact_Defend_model.h5)

CODE-FOR commented 3 years ago

Have you fixed it? I occur the same problem.

namphn commented 3 years ago

I am also stuck with same problem. After changing dependencies according to https://github.com/cuilimeng/dEFEND-web/blob/master/requirements.txt. I get a different error You are trying to load a weight file containing 5 layers into a model with 4 layers

Error is coming in load module step self.model = load_model(./static/saved_models/politifact_Defend_model.h5)

Have you fixed it? I occur the same problem

CODE-FOR commented 3 years ago

I am also stuck with same problem. After changing dependencies according to https://github.com/cuilimeng/dEFEND-web/blob/master/requirements.txt. I get a different error You are trying to load a weight file containing 5 layers into a model with 4 layers Error is coming in load module step self.model = load_model(./static/saved_models/politifact_Defend_model.h5)

Have you fixed it? I occur the same problem

I kind of fixed it by changing code in _build_model

        sentence_input = Input(shape=(self.MAX_SENTENCE_LENGTH,), dtype='int32')
        embedded_sequences = embedding_layer(sentence_input)
        # change
        embedded_sequences = Lambda(lambda x: x, output_shape=lambda s: s)(embedded_sequences)
        l_lstm = Bidirectional(GRU(100, return_sequences=True), name='word_lstm')(Reshape((120, 100))(embedded_sequences))
        # change
        l_att = AttLayer(name='word_attention')(l_lstm)
        sentEncoder = Model(sentence_input, l_att)
        comment_input = Input(shape=(self.MAX_COMS_LENGTH,), dtype='int32')
        com_embedded_sequences = com_embedding_layer(comment_input)
        # change
        com_embedded_sequences = Lambda(lambda x: x, output_shape=lambda s: s)(com_embedded_sequences)
        c_lstm = Bidirectional(GRU(100, return_sequences=True), name='comment_lstm')(Reshape((100, 120))(com_embedded_sequences))
        # change
        c_att = AttLayer(name='comment_word_attention')(c_lstm)
        comEncoder = Model(comment_input, c_att, name='comment_word_level_encoder')

Maybe just reshape is enough, but after reshaping. I occur some strange bug. And by adding a lambda layer can fix it. The model seems to run successfully.

You can try this.

namphn commented 3 years ago
c_lstm = Bidirectional(GRU(100, return_sequences=True), name='comment_lstm')(Reshape((100, 120))(com_embedded_sequences))

Oh my god!!! You saved my life =))))) thanks so munch!!!!!!

peteoleary commented 3 years ago

The above code fixed the problem for me but now I am seeing:

`Exception has occurred: RuntimeError Unable to create link (name already exists) File "/Users/pete_o/Documents/Dev/InfoAuthN/news-dj-service/our3.py", line 400, in train callbacks=callbacks) File "/Users/pete_o/Documents/Dev/InfoAuthN/news-dj-service/go_defend.py", line 96, in embeddings_path='saved_models', saved_model_dir='saved_models', saved_model_filename=SAVED_MODEL_FILENAME )

The exception is thrown from:

self.model.fit([encoded_train_c, encoded_train_x], y=train_y, validation_data=([encoded_val_c, encoded_val_x], val_y), batch_size=batch_size, epochs=epochs, verbose=1, callbacks=callbacks) `

peteoleary commented 3 years ago

Opened new issue https://github.com/cuilimeng/dEFEND-web/issues/14

Let me know if there is another Github repo or forum where I could post this.

gmyfreedom commented 2 years ago
c_lstm = Bidirectional(GRU(100, return_sequences=True), name='comment_lstm')(Reshape((100, 120))(com_embedded_sequences))

Oh my god!!! You saved my life =))))) thanks so munch!!!!!!

c_lstm = Bidirectional(GRU(100, return_sequences=True), name='comment_lstm')(Reshape((100, 120))(com_embedded_sequences))

Oh my god!!! You saved my life =))))) thanks so munch!!!!!!

Hi,have you run the project successfully? I have some problem in getting twitter API. I want to know if this project can run successfully.

gmyfreedom commented 2 years ago

Hi,have you run the project successfully? I have some problem in getting twitter API. I want to know if this project can run successfully.