I'm trying to implement chat-bot using seq2seq with attention for that I write a function for attention layer inspired by TensorFlow nmt example when I'm trying to fit this model I'm facing argument error I searched in google but couldn't find any solutions for my problem anyone help me where I did wrong
`
i'm stucking with below error can anyone help me with this error
`
model.fit([encoder_input_data, decoder_input_data], decoder_output_data, batch_size=86, epochs=10, validation_split=0.2)
Train on 4644 samples, validate on 1162 samples
Epoch 1/10
86/4644 [..............................] - ETA: 8:18
in ()
----> 1 get_ipython().run_cell_magic('time', '', 'model.fit([encoder_input_data, decoder_input_data], decoder_output_data, batch_size=86, epochs=10, validation_split=0.2) ')
14 frames
in time(self, line, cell, local_ns)
in ()
/usr/local/lib/python3.6/dist-packages/six.py in raise_from(value, from_value)
InvalidArgumentError: Only one input size may be -1, not both 0 and 1
[[node model/tf_op_layer_Reshape/Reshape (defined at /usr/local/lib/python3.6/dist-packages/tensorflow_core/python/framework/ops.py:1751) ]] [Op:__inference_distributed_function_16029]
Function call stack:
distributed_function
`
I'm trying to implement chat-bot using seq2seq with attention for that I write a function for attention layer inspired by TensorFlow nmt example when I'm trying to fit this model I'm facing argument error I searched in google but couldn't find any solutions for my problem anyone help me where I did wrong `
Bahdanu attention
def Attention_layer(state_h,state_c,encoder_outputs,decoder_embedding):
d0 = tf.keras.layers.Dense(1024,name='dense_layer_1') d1 = tf.keras.layers.Dense(1024,name='dense_layer_2') d2 = tf.keras.layers.Dense(1024,name='dense_layer_3') score = d0(tf.keras.activations.tanh(encoder_outputs) + d1(state_h) + d2(state_c)) attention_weights = tf.keras.activations.softmax(score, axis=1) context_vector = attention_weights * encoder_outputs context_vector = tf.keras.backend.sum(context_vector, axis=1) context_vector = tf.keras.backend.expand_dims(context_vector, 1) context_vector = tf.keras.backend.reshape(context_vector,[-1,-1,1024]) input_to_decoder = tf.keras.layers.concatenate([context_vector,decoder_embedding], axis=-1) return input_to_decoder
Below is Encoder-Decoder model
encoder_inputs = tf.keras.layers.Input(shape=(None,),name='encoder_input_layer') encoder_embedding = tf.keras.layers.Embedding(vocab_size, 1024, mask_zero=True,name='encoder_embedding_layer')(encoder_inputs) encoder_outputs , state_h , state_c = tf.keras.layers.LSTM(1024, return_state=True)(encoder_embedding) encoder_states = [state_h, state_c]decoder_inputs = tf.keras.layers.Input(shape=(None,),name='decoder_input_layer') decoder_embedding = tf.keras.layers.Embedding(vocab_size, 1024, mask_zero=True,name='decoder_embedding_layer')(decoder_inputs) decoder_lstm = tf.keras.layers.LSTM(1024, return_state=True, return_sequences=True) attention_layer = Attention_layer(state_h, state_c, encoder_outputs, decoder_embedding) decoderoutputs, , _ = decoder_lstm(attention_layer, initial_state=encoder_states) decoder_dense = tf.keras.layers.TimeDistributed(tf.keras.layers.Dense(vocab_size, activation='softmax'))
output = decoder_dense(decoder_outputs) model = tf.keras.models.Model([encoder_inputs, decoder_inputs], output) model.compile(optimizer='adam', loss='categorical_crossentropy') model.summary() `
i'm stucking with below error can anyone help me with this error ` model.fit([encoder_input_data, decoder_input_data], decoder_output_data, batch_size=86, epochs=10, validation_split=0.2)
Train on 4644 samples, validate on 1162 samples Epoch 1/10 86/4644 [..............................] - ETA: 8:18
InvalidArgumentError Traceback (most recent call last)