在一个程序里两种书写方式
方式一:
from tensorflow.python.ops import math_ops
# decoder_features: (batch_size, 1, 1, attention_vec_size)
# encoder_feature: (batch_size, attn_length, 1, attention_vec_size)
# v: (attention_vec_size)
e = math_ops.reduce_sum(v * math_ops.tanh(encoder_feature + decoder_features), [2, 3]) #shape: (batch_size, attn_length)
方式二:
attn_dist = nn_ops.softmax(e) # take softmax. shape (batch_size, attn_length)
masked_sums = tf.reduce_sum(attn_dist, axis=1) # shape (batch_size)
查了tensorflow官方文档:
原来怎样写都可以,只是一个代码里两种写法真是搞不懂作者怎么想的