我正在尝试使用keras 2.2.4中的注意力模块对一种编码器-解码器网络进行编程,但是出现以下错误,并且无法修复。有人可以帮助我吗?
def model(Tx, Ty, encoder_unit_size, decoder_unit_size, encoder_embedding_input_size, decoder_embedding_input_size, embedding_size, out_size):
"""
Arguments:
Tx -- length of the input sequence
Ty -- length of the output sequence
encoder_unit_size -- hidden state size of the Bi-LSTM
decoder_unit_size -- hidden state size of the LSTM
encoder_embedding_input_size -- size of the input embedding in encoder module
decoder_embedding_input_size -- size of the input embedding in decoder module
embedding_size -- embedding size of the decoder input
Returns:
model -- Keras model instance
"""
# Encoder module
encoder_input = Input(shape=(Tx, encoder_embedding_input_size))
# Step 1: Define Deep Bi-LSTM Enconder
fl_enc_seq, flast_h, flast_s, _, _ = Bidirectional(LSTM(encoder_unit_size,
return_sequences=True,
return_state=True),
merge_mode="concat")(encoder_input)
sl_enc_seq, slast_h, slast_s, _, _ = Bidirectional(LSTM(encoder_unit_size,
return_sequences=True,
return_state=True),
merge_mode="concat")(fl_enc_seq)
# Decoder module
decoder_input = Input(shape=(Ty, decoder_embedding_input_size))
# Step 2: Define Deep LSTM Decoder. Hidden and state initialization with last outputs of encoder.
fl_dec_seq = LSTM(decoder_unit_size,
return_sequences=True,
unroll= False)(decoder_input, initial_state=[flast_h, flast_s])
sl_dec_seq = LSTM(decoder_unit_size,
return_sequences=True,
unroll= False)(fl_dec_seq, initial_state=[slast_h, slast_s])
# Step 3: Attention module
outputs = []
# Iterate for Ty steps
for t in range(Ty):
context_vector = one_step_attention(sl_enc_seq, sl_dec_seq[:,t,:])
decoder_context = concatenator([tf.expand_dims(sl_dec_seq[:,t,:], 1), context_vector])
fc_out = dense_output_layer(decoder_context)
outputs.append(fc_out)
output_tensor = Lambda(lambda x:tf.convert_to_tensor(x, dtype=tf.float32))(outputs)
outputs_layer = TimeDistributed(Dense(out_size, activation="softmax"))(output_tensor)
print(outputs_layer.shape)
model = Model(inputs = [encoder_input, decoder_input], outputs = outputs_layer)
return model
这是输出:
(50,?,1,1024)
...
...
AttributeError:“ NoneType”对象没有属性“ _inbound_nodes”
我认为错误是当您返回输出时