有没有办法想象的一样在上面的链接数字输入的一些注意权重(从Bahdanau等,2014),在TensorFlow的seq2seq
模式?我发现TensorFlow's github issue关于这个,但我无法找到如何在会话期间获取注意掩码。
8
A
回答
3
我也想要显示Tensorflow seq2seq操作对我的文本摘要任务的注意力。我认为临时解决方案是使用session.run()来评估上面提到的注意模板张量。有趣的是,原来的seq2seq.py操作被认为是旧版本,并且不能在github中很容易找到,所以我只是在0.12.0轮子分配中使用了seq2seq.py文件并对其进行了修改。为了绘制热图,我使用了'Matplotlib'包,非常方便。
我修改代码如下: https://github.com/rockingdingo/deepnlp/tree/master/deepnlp/textsum#attention-visualization
# Find the attention mask tensor in function attention_decoder()-> attention()
# Add the attention mask tensor to ‘return’ statement of all the function that calls the attention_decoder(),
# all the way up to model_with_buckets() function, which is the final function I use for bucket training.
def attention(query):
"""Put attention masks on hidden using hidden_features and query."""
ds = [] # Results of attention reads will be stored here.
# some code
for a in xrange(num_heads):
with variable_scope.variable_scope("Attention_%d" % a):
# some code
s = math_ops.reduce_sum(v[a] * math_ops.tanh(hidden_features[a] + y),
[2, 3])
# This is the attention mask tensor we want to extract
a = nn_ops.softmax(s)
# some code
# add 'a' to return function
return ds, a
# Use the plot_attention function in eval.py to visual the 2D ndarray during prediction.
eval.plot_attention(attn_matrix[0:ty_cut, 0:tx_cut], X_label = X_label, Y_label = Y_label)
并可能在未来tensorflow将会有更好的方法来提取和可视化的关注权重映射。有什么想法吗?
+0
嘿,尼斯答案,我试过相同的,但我有一个意想不到的关注向量。你可以看看:http://stackoverflow.com/questions/43123105/weird-attention-weights-when-trying-to-learn-to-inverse-sequence-with-seq2seq thx – pltrdy
相关问题
- 1. Tensorflow激活功能
- 2. 使用Keras可视化CNN中的功能和激活示例
- 3. Tensorflow LSTM RNN输出激活功能
- 4. Tensorflow在Win10下不能激活
- 5. Tensorflow Layers Api线性激活功能
- 6. Visual Studio工具提示可视化激活难以点击
- 7. RNetLogo激活开关
- 8. 用户激活注册CodeIgniter
- 9. Angular2:注册表激活
- 10. 如何在初始化后激活/取消激活模块视图?
- 11. 使用Tensorflow可视化多个嵌入
- 12. 激活用户注册,激活布尔值和令牌
- 13. 可可:激活窗口:shouldPopUpDocumentPathMenu:?
- 14. 如何关注上次激活的程序?
- 15. 激活Flex自动化库
- 16. svg:激活/关闭动画
- 17. 在Android中激活视图
- 18. 在Windows中激活注入的DLL
- 19. Django的注册 - 一些激活
- 20. 注册免费激活的COM组件
- 21. 注册用户的激活邮件MVC
- 22. 对可疑用户活动的关注
- 23. Twitter的关系可视化
- 24. 如何在Vim的可视模式中激活相关行编号?
- 25. 在Xcode 9 beta 5中激活“关注选项”?
- 26. MonoTouch激活/重新激活
- 27. 激活/取消激活virtualenv
- 28. 停止激活激活
- 29. 当获取可变序列长度的激活时,Tensorflow GRU单元格错误
- 30. Flexslider当可见时激活
您将该注意掩模(张量)送入session.run。 – yuefengz