如何访问 seq2seq_model 的注意力解码器中的注意力值来绘制 bleu 分数
How to access attention values in attention decoder of seq2seq_model to plot bleu score
我正在研究语言翻译模型。
1. 我想使用 bleu 分数可视化 http://www.wildml.com/2016/01/attention-and-memory-in-deep-learning-and-nlp/ 中提到的数据。
2.
for a in xrange(num_heads):
with variable_scope.variable_scope("Attention_%d" % a):
y = linear(query, attention_vec_size, True)
y = array_ops.reshape(y, [-1, 1, 1, attention_vec_size])
# Attention mask is a softmax of v^T * tanh(...).
s = math_ops.reduce_sum(
v[a] * math_ops.tanh(hidden_features[a] + y), [2, 3])
a = nn_ops.softmax(s)
# Now calculate the attention-weighted vector d.
d = math_ops.reduce_sum(
array_ops.reshape(a, [-1, attn_length, 1, 1]) * hidden,
[1, 2])
ds.append(array_ops.reshape(d, [-1, attn_size]))
return ds
如何修改代码以检索 "a" 值以进行可视化?
您首先需要将对这些张量的引用保存在 python 列表中。然后将 python 列表传递给 session.run
函数。结果将是一个包含这些张量的 numpy 值的列表。
我正在研究语言翻译模型。
1. 我想使用 bleu 分数可视化 http://www.wildml.com/2016/01/attention-and-memory-in-deep-learning-and-nlp/ 中提到的数据。
2.
for a in xrange(num_heads):
with variable_scope.variable_scope("Attention_%d" % a):
y = linear(query, attention_vec_size, True)
y = array_ops.reshape(y, [-1, 1, 1, attention_vec_size])
# Attention mask is a softmax of v^T * tanh(...).
s = math_ops.reduce_sum(
v[a] * math_ops.tanh(hidden_features[a] + y), [2, 3])
a = nn_ops.softmax(s)
# Now calculate the attention-weighted vector d.
d = math_ops.reduce_sum(
array_ops.reshape(a, [-1, attn_length, 1, 1]) * hidden,
[1, 2])
ds.append(array_ops.reshape(d, [-1, attn_size]))
return ds
如何修改代码以检索 "a" 值以进行可视化?
您首先需要将对这些张量的引用保存在 python 列表中。然后将 python 列表传递给 session.run
函数。结果将是一个包含这些张量的 numpy 值的列表。