Keras: AssertionError на LSTM initial_state

Я строю модель кодер-декодер, и при сборке декодера появляется ошибка AssertionError.

Это детали AssertionError

Это уровень кодировщика, я подозреваю, что на выходе кодера есть проблема, которая позже приводит к проблеме назначения декодера LSTM initial_state.

encoder_lstm1 = LSTM(state_size, name='encoder_lstm1', return_state=True, return_sequences=True)
encoder_lstm2 = LSTM(state_size, name='encoder_lstm2', return_state=True, return_sequences=True)
encoder_lstm3 = LSTM(state_size, name='encoder_lstm3', return_state=True, return_sequences=False)

# Start the neural network with its input-layer.
net = encoder_input

# Connect the embedding-layer.
net = encoder_embedding(net)

# Connect all the LSTM-layers.
net = encoder_lstm1(net)
net = encoder_lstm2(net)
net = encoder_lstm3(net)

# This is the output of the encoder.
encoder_output, encoder_h, encoder_c = net
encoder_states = [encoder_h, encoder_c]

Это слой декодера

decoder_initial_state_h = Input(shape=(state_size,),
                              name='decoder_initial_state_h')

decoder_initial_state_c = Input(shape=(state_size,),
                              name='decoder_initial_state_c')

decoder_initial_state = [decoder_initial_state_h, decoder_initial_state_c]

decoder_input = Input(shape=(None, ), name='decoder_input')

decoder_embedding = Embedding(input_dim=num_words,
                              output_dim=embedding_size,
                              name='decoder_embedding')

decoder_lstm1 = LSTM(state_size, name='decoder_lstm1',
                   return_sequences=True, return_state=True)
decoder_lstm2 = LSTM(state_size, name='decoder_lstm2',
                   return_sequences=True, return_state=True)
decoder_lstm3 = LSTM(state_size, name='decoder_lstm3',
                   return_sequences=True, return_state=True)

decoder_dense = Dense(num_words,
                      activation='linear',
                      name='decoder_output')

def connect_decoder(encoder_states):
# Start the decoder-network with its input-layer.
    net = decoder_input

# Connect the embedding-layer.
    net = decoder_embedding(net)

# Connect all the LSTM-layers.
    net = decoder_lstm1(net, initial_state=encoder_states)
    net = decoder_lstm2(net, initial_state=encoder_states)
    net = decoder_lstm3(net, initial_state=encoder_states)

    decoder_output, _ , _ = net

# Connect the final dense layer that converts to
# one-hot encoded arrays.
    decoder_output = decoder_dense(decoder_output)

    return decoder_output

encoder_output = connect_encoder()

Компиляция этого приводит к AssertionError

decoder_output = connect_decoder(encoder_states)

Ждем любых предложений. Большое спасибо.

0 ответов

Другие вопросы по тегам