3

I'm now trying to build seq2seq model on top of Keras.

I referred to this official seq2seq example but I wondered why not using TimeDistibuted layer instead of Dense.

# Set up the decoder, using `encoder_states` as initial state.
decoder_inputs = Input(shape=(None, num_decoder_tokens))
# We set up our decoder to return full output sequences,
# and to return internal states as well. We don't use the
# return states in the training model, but we will use them in inference.
decoder_lstm = LSTM(latent_dim, return_sequences=True, return_state=True)
decoder_outputs, _, _ = decoder_lstm(decoder_inputs,
                                     initial_state=encoder_states)
decoder_dense = Dense(num_decoder_tokens, activation='softmax') # <- Here!
decoder_outputs = decoder_dense(decoder_outputs)

# Define the model that will turn
# `encoder_input_data` & `decoder_input_data` into `decoder_target_data`
model = Model([encoder_inputs, decoder_inputs], decoder_outputs)

Seq2seq model must deal with a many-to-many problem, so each timestep must be processed separately. Therefore I thought this model should have TimeDistributed(Dense()) layer but actually, it's Dense.

Can anyone explain the reason to me?

Sundars
  • 31
  • 3

0 Answers0