Keras LSTM Eng 2French Seq2Seq模型中的AssertionError

时间:2020-10-29 04:55:45

标签: keras lstm

我正在构建用于英语到法语翻译的编码器解码器。数据集具有x_train和y_train。

x_train.shape= 124074, 15
y_train.shape = 124074, 23

编码器解码器来自https://www.tensorflow.org/guide/keras/rnn

encoder_vocab = 200
decoder_vocab = 351

encoder_input = layers.Input(shape=(None,))
encoder_embedded = layers.Embedding(input_dim=encoder_vocab, output_dim=64)(
    encoder_input
)

# Return states in addition to output
output, state_h, state_c = layers.LSTM(64, return_state=True, name="encoder")(
    encoder_embedded
)
encoder_state = [state_h, state_c]

decoder_input = layers.Input(shape=(None,))
decoder_embedded = layers.Embedding(input_dim=decoder_vocab, output_dim=64)(
    decoder_input
)

# Pass the 2 states to a new LSTM layer, as initial state
decoder_output = layers.LSTM(64, name="decoder")(
    decoder_embedded, initial_state=encoder_state
)
output = layers.Dense(10)(decoder_output)

model = keras.Model([encoder_input, decoder_input], output)
model.summary()

我适合的时候

model.fit(x_train, y_train, batch_size=1024, validation_split=0.2, epochs=10)

我收到错误消息

AssertionError: Could not compute output Tensor("dense_3/BiasAdd:0", shape=(None, 10), dtype=float32)

如何解决?

0 个答案:

没有答案