请参考以下帖子了解问题的背景:
TensorFlow的embedding_attention_seq2seq方法是否默认实现双向RNN编码器?
我正在使用相同的模型,并想用双向层替换单向LSTM层。 我意识到我必须使用static_bidirectional_rnn而不是static_rnn,但由于张量形状不匹配而出现错误。
我替换了以下行:
我替换了以下行:
encoder_outputs, encoder_state = core_rnn.static_rnn(encoder_cell, encoder_inputs, dtype=dtype)
使用下面的代码:
encoder_outputs, encoder_state_fw, encoder_state_bw = core_rnn.static_bidirectional_rnn(encoder_cell, encoder_cell, encoder_inputs, dtype=dtype)
这个错误信息如下:
InvalidArgumentError (参见上面的 traceback):不兼容的形状: [32,5,1,256] 和 [16,1,1,256] [[Node: gradients/model_with_buckets/embedding_attention_seq2seq/embedding_attention_decoder/attention_decoder/Attention_0/add_grad/BroadcastGradientArgs = BroadcastGradientArgs[T=DT_INT32, _device="/job:localhost/replica:0/task:0/cpu:0"](gradients/model_with_buckets/embedding_attention_seq2seq/embedding_attention_decoder/attention_decoder/Attention_0/add_grad/Shape, gradients/model_with_buckets/embedding_attention_seq2seq/embedding_attention_decoder/attention_decoder/Attention_0/add_grad/Shape_1)]]
我知道这两种方法的输出是不同的,但我不知道如何修改注意力代码以使其包含这点。我该如何将前向和后向状态都发送到注意力模块中 - 我需要将隐藏状态连接起来吗?