首页 > 解决方案 > 如何使用双向 lstm 预测摘要问题中的新输入

问题描述

我使用双向 lstm 创建了一个汇总模型,该模型在训练中的准确率约为 90%。但是对于测试传统的 model.predict 方法是行不通的。有没有其他方法可以预测新输入的摘要?

我的模型如下

encoder_inputs = Input(shape=(MAX_LEN,))
encoder_embedding = encoder_embedding_layer(encoder_inputs)
encoder_LSTM = LSTM(HIDDEN_UNITS, return_state=True)
encoder_LSTM_R = LSTM(HIDDEN_UNITS, return_state=True, go_backwards=True)
encoder_outputs_R, state_h_R, state_c_R = encoder_LSTM_R(encoder_embedding)
encoder_outputs, state_h, state_c = encoder_LSTM(encoder_embedding)

final_h = Add()([state_h, state_h_R])
final_c = Add()([state_c, state_c_R])
encoder_states = [final_h, final_c]
decoder_inputs = Input(shape=(MAX_LEN,))
decoder_embedding = decoder_embedding_layer(decoder_inputs)
decoder_LSTM = LSTM(HIDDEN_UNITS, return_sequences=True, return_state=True)
decoder_outputs, _, _ = decoder_LSTM(decoder_embedding, initial_state=encoder_states) 
decoder_dense = Dense(VOCAB_SIZE, activation='softmax')
decoder_outputs = decoder_dense(decoder_outputs)

model_2= Model(inputs=[encoder_inputs,decoder_inputs], outputs=decoder_outputs)

标签: pythontensorflowkerasdeep-learninglstm

解决方案


推荐阅读