我一直在尝试了解有关seq2seq2的keras上的示例代码。
链接:https://blog.keras.io/a-ten-minute-introduction-to-sequence-to-sequence-learning-in-keras.html
如果我理解它,则decoder_model
下面的输入为:decoder_inputs
,decoder_states_inputs
其中where[decoder_inputs]
应该用作“实际”输入并decoder_states_inputs
初始化lstm层的状态。
创建模型时,看似用于不同事物的两个输入与“ +”运算符组合在一起。如何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)
它们是对list
对象求和,而不是对值求和。
decoder_states_inputs
是一个list
。(制造[decoder_state_input_h, decoder_state_input_c]
)[decoder_inputs]
是list
(请看[]
)Alist + list
只是两个列表的串联。
因此:[decoder_inputs] + [decoder_state_input_h, decoder_state_input_c]
等于:[decoder_inputs, decoder_state_input_h, decoder_state_input_c]
这只是模型输入的列表。您始终需要传递列表中的所有输入以创建模型。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句