【问题标题】:Encoder returning same states for every input Keras seq2seq编码器为每个输入 Keras seq2seq 返回相同的状态
【发布时间】:2018-11-13 11:30:32
【问题描述】:

我在 Keras 中使用 Encoder Decoder seq2seq 架构, 我正在传递一个单热的形状数组(num_samples、max_sentence_length、max_words)进行训练,并使用教师强制。

#Encoder
latent_dim = 256
encoder_inputs = Input(shape=(None, max_words))
encoder = LSTM(latent_dim, return_state = True)
encoder_outputs, state_h, state_c = encoder(encoder_inputs)
encoder_states = [state_h, state_c]
#Decoder
decoder_inputs = Input(shape=(None, max_words))
decoder_lstm = LSTM(latent_dim, return_state = True, return_sequences = 
True)
decoder_outputs, _, _ = decoder_lstm(decoder_inputs, initial_state= 
encoder_states)
decoder_dense = Dense(max_words, activation = 'softmax')
decoder_outputs = decoder_dense(decoder_outputs)

对于推理模型:

# Inference model
encoder_model = Model(encoder_inputs, encoder_states)

decoder_state_input_h = Input(shape=(latent_dim,))
decoder_state_input_c = Input(shape=(latent_dim,))
decoder_states_inputs = [decoder_state_input_h, decoder_state_input_c]
decoder_outputs, state_h, state_c = decoder_lstm(
    decoder_inputs, initial_state=decoder_states_inputs)
decoder_states = [state_h, state_c]
decoder_outputs = decoder_dense(decoder_outputs)
decoder_model = Model(
    [decoder_inputs] + decoder_states_inputs,
    [decoder_outputs] + decoder_states)

我尝试打印出 encoder_model 状态,但它总是为任何输入返回相同的状态。任何帮助将不胜感激!

【问题讨论】:

    标签: machine-learning keras chatbot seq2seq encoder-decoder


    【解决方案1】:

    这几乎只是来自 Keras 的例子,对吗?

    https://blog.keras.io/a-ten-minute-introduction-to-sequence-to-sequence-learning-in-keras.html

    你训练过模型吗?您发布的所有内容都与 Keras 文档中的内容相同,因此我认为这不是问题。

    这是一个有效的示例,它也基于 Keras 文档,看起来与您所拥有的非常相似。也许尝试通过这个来看看你的不同之处?

    https://github.com/JEddy92/TimeSeries_Seq2Seq/blob/master/notebooks/TS_Seq2Seq_Intro.ipynb

    【讨论】:

      猜你喜欢
      • 2018-07-18
      • 2018-11-21
      • 2018-09-13
      • 2022-10-18
      • 2016-08-13
      • 2021-07-10
      • 2022-01-24
      • 2017-01-06
      • 2020-07-05
      相关资源
      最近更新 更多