Decoder Construction functional API keras

I have trained and encoder, decoder model using teacher forcing for timeseries forecasting. Now I am trying to prepare the model for prediction.

I prepared the decoder in the following way:

    # DECODER (modified)
# ------------------

# Define new input layers that will contain the intermediate state between decoding steps
decoder_state_input_h = tf.keras.Input(shape=[128])
decoder_state_input_c = tf.keras.Input(shape=[128])
decoder_state_input = [decoder_state_input_h, decoder_state_input_c]

decoder_input_single = tf.keras.Input(shape=[1,7])
lstm_out, h, c = seq2seq_model.get_layer('lstm_dec')(decoder_input_single, initial_state=decoder_state_input)

# Save decoder state (for next ste inference)
decoder_state = [h, c]
decoder_out = seq2seq_model.get_layer('decoder_out')(lstm_out)

decoder_inference_model = tf.keras.Model([decoder_input_single] + decoder_state_input,
                                         [decoder_out] + decoder_state)

Note that there are 7 features to predict therefore the decoder input has shape (1,7), because I am feeding back the predicted value at each step. Here is the summary

Model: "model_6"
 Layer (type)                   Output Shape         Param #     Connected to                     
 input_9 (InputLayer)           [(None, 1, 7)]       0           []                               
 input_7 (InputLayer)           [(None, 128)]        0           []                               
 input_8 (InputLayer)           [(None, 128)]        0           []                               
 lstm_dec (LSTM)                multiple             69632       ['input_9[0][0]',                
 decoder_out (Dense)            multiple             903         ['lstm_dec[1][0]']               
Total params: 70,535
Trainable params: 70,535
Non-trainable params: 0

I then take decoder inputs such that:

dec_inputs = [initial_input]+states_values

If I write the a loop to inspect the inputs I have:

for l in a:
-> (653, 1, 7)
   (653, 128)
   (653, 128)

When I run

decoder_inference_model.predict([curr_input, states_value])

I get the following error:

ValueError: Exception encountered when calling layer "model_11" (type Functional).
    Layer "lstm_dec" expects 7 input(s), but it received 1 input tensors. Inputs received: [<tf.Tensor 'IteratorGetNext:0' shape=(None, 1, 7) dtype=float32>]
    Call arguments received:
      • inputs=('tf.Tensor(shape=(None, 1, 7), dtype=float32)', ('tf.Tensor(shape=(None, 128), dtype=float32)', 'tf.Tensor(shape=(None, 128), dtype=float32)'))
      • training=False
      • mask=None
How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum