如何在双向LSTM的两个方向上合并最后的隐藏状态

时间:2019-03-25 12:05:51

标签: lstm encoder bidirectional decoder

我正在使用编解码器网络进行文本汇总

编码器是双向GRU

解码器是一个简单的GRU

这是我尝试过的

## ENCODER
encoder_inputs = Input(shape = (MAX_LEN,), dtype = 'int32')

encoder_embeds = embedding_layer(encoder_inputs)

x, forward_h, backward_h = Bidirectional(GRU(MAX_LEN, return_sequences = True, return_state = True))(encoder_embeds) #return state is by default True

encoder_state = Concatenate()([forward_h, backward_h])

## DECODER
decoder_inputs = Input(shape = (MAX_LEN,), dtype = 'float32')

decoder_embeds = embedding_layer(decoder_inputs)

decoder_outputs, state_s = GRU(MAX_LEN, return_sequences = True, return_state = True)(decoder_embeds, initial_state = encoder_state)

这是我得到的错误

An `initial_state` was passed that is not compatible with `cell.state_size`. Received `state_spec`=[InputSpec(shape=(None, 198), ndim=2)]; however `cell.state_size` is 99

我知道错误表明当期望99时,它收到的第二维为(99 + 99 =)198

由于 Concatenate()操作

而发生错误

当我要考虑两个方向上的最后一个隐藏状态时, Concatenate()的替代方法是什么

0 个答案:

没有答案