[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
推荐阅读
- 聪明人养花,这3种“花”怎样也要养一盆,每年能省不少医药费
- 互联网怎样解决“家政服务上门速度慢”的问题
- 怎样看待从1月8号起,QQ钱包开始提现收费
- 银行it人怎样转型
- 汽车|冬天怎样让车内温度快速升高?座椅加热的最佳使用方式二,外循环的作用总结
- 怎样进入通信行业
- 怎样评价扶他柠檬茶的小说《云养汉》的结尾
- 怎样成为一名合格的Python程序员?
- 怎样评价华为、诺基亚、中兴中标中国移动高端路由交换设备扩容集采
- 怎样评价类似前橙会、百老汇、南极圈这样类型的离职帮抱团,对企业的积极意义和消极意义
