[TF] Dynamic RNN 怎样实现 Attention ,若不能,应该咋实现呢

用dynamic rnn实现attention是非常自然非常简单的事情。
1.定义attention
【[TF] Dynamic RNN 怎样实现 Attention ,若不能,应该咋实现呢】 2. 定义rnn_cell
3. 用attention wrapper和cell和起来

#定义要使用的attention机制。 attentionMechanism = tf.contrib.seq2seq.BahdanauAttention(num_units=self.args.hiddenSize, memory=encoderOutputs, memory_sequence_length=encoderInputsLength) # 定义decoder阶段要是用的LSTMCell,然后为其封装attention wrapperdecoder_cell = self.create_rnn_cell()
decoder_cell = tf.contrib.seq2seq.AttentionWrapper(cell=decoder_cell, attention_mechanism=attentionMechanism, attention_layer_size=self.args.hiddenSize, name=\u0026#39;Attention_Wrapper\u0026#39;)

完整代码参考
mrlongzhang/LongDialog


    推荐阅读