Pointer-network的tensorflow实现-1
pointer-network是最近seq2seq比较火的一个分支,在基于深度学习的阅读理解,摘要系统中都被广泛应用。
感兴趣的可以阅读原paper 推荐阅读
https://medium.com/@devnag/pointer-networks-in-tensorflow-with-sample-code-14645063f264
这个思路也是比较简单
就是解码的预测限定在输入的位置上
这在很多地方有用
比如考虑机器翻译的大词典问题,词汇太多了很多词是长尾的,词向量训练是不充分的,那么seq2seq翻译的时候很难翻译出这些词
另外专名什么的
很多是可以copy到
解码输出的
另外考虑文本摘要,很多时候就是要copy输入原文中的词,特别是长尾专名
更好的方式是copy而不是generate
网络上有一些pointer-network的实现,比较推荐
https://github.com/ikostrikov/TensorFlow-Pointer-Networks
这个作为入门示例比较好,使用简单的static rnn 实现更好理解,当然 dynamic速度更快,但是从学习角度
先实现static更好一些。
Dynamic rnn的 pointer network实现
https://github.com/devsisters/pointer-network-tensorflow
这里对static rnn实现的做了一个拷贝并做了小修改,改正了其中的一些问题
参见
https://github.com/chenghuige/hasky/tree/master/applications/pointer-network/static
这个小程序对应的应用是输入一个序列
比如,输出排序结果
我们的构造数据
python dataset.py
EncoderInputs: [array([[ 0.74840968]]), array([[ 0.70166106]]), array([[ 0.67414996]]), array([[ 0.9014052]]), array([[ 0.72811645]])]
DecoderInputs: [array([[ 0.]]), array([[ 0.67414996]]), array([[ 0.70166106]]), array([[ 0.72811645]]), array([[ 0.74840968]]), array([[ 0.9014052]])]
TargetLabels: [array([[ 3.]]), array([[ 2.]]), array([[ 5.]]), array([[ 1.]]), array([[ 4.]]), array([[ 0.]])]
训练过程中的eval展示:
2017-06-07 22:35:52 0:28:19 eval_step: 111300 eval_metrics:
['eval_loss:0.070', 'correct_predict_ratio:0.844']
label--: [ 2 6 1 4 9 7 10 8 5 3 0]
predict: [ 2 6 1 4 9 7 10 8 5 3 0]
label--: [ 1 6 2 5 8 3 9 4 10 7 0]
predict: [ 1 6 2 5 3 3 9 4 10 7 0]
大概是这样
第一个我们认为是预测完全正确了,
第二个预测不完全正确
原程序最主要的问题是 Feed_prev 设置为True的时候 原始代码有问题的 因为inp使用的是decoder_input这是不正确的因为
预测的时候其实是没有decoder_input输入的,原代码预测的时候decoder input强制copy/feed了encoder_input
这在逻辑是是有问题的。 实验效果也证明修改成训练也使用encoder_input来生成inp效果好很多。
那么关于feed_prev我们知道在预测的时候是必须设置为True的因为,预测的时候没有decoder_input我们的下一个输出依赖
上一个预测的输出。
训练的时候我们是用decoder_input序列训练(feed_prev==False)还是也使用自身预测产生的结果进行下一步预测feed_prev==True呢
参考tensorflow官网的说明
In the above invocation, we set feed_previous to False. This means that the decoder will use decoder_inputstensors as provided. If we set feed_previous to True, the decoder would only use the first element of decoder_inputs. All other tensors from this list would be ignored, and instead the previous output of the decoder would be used. This is used for decoding translations in our translation model, but it can also be used during training, to make the model more robust to its own mistakes, similar to Bengio et al., 2015 (pdf).
来自 <https://www.tensorflow.org/tutorials/seq2seq>
这里使用
train.sh
和
train-no-feed-prev.sh
做了对比实验
训练时候使用feed_prev==True效果稍好(红色) 特别是稳定性方差小一些

Pointer-network的tensorflow实现-1的更多相关文章
- Convolutional Neural Network in TensorFlow
翻译自Build a Convolutional Neural Network using Estimators TensorFlow的layer模块提供了一个轻松构建神经网络的高端API,它提供了创 ...
- (转)The Road to TensorFlow
Stephen Smith's Blog All things Sage 300… The Road to TensorFlow – Part 7: Finally Some Code leave a ...
- TensorFlow简易学习[3]:实现神经网络
TensorFlow本身是分布式机器学习框架,所以是基于深度学习的,前一篇TensorFlow简易学习[2]:实现线性回归对只一般算法的举例只是为说明TensorFlow的广泛性.本文将通过示例Ten ...
- TensorFlow tutorial
代码示例来自https://github.com/aymericdamien/TensorFlow-Examples tensorflow先定义运算图,在run的时候才会进行真正的运算. run之前需 ...
- 5个最好的TensorFlow网络课程
1. Introduction to TensorFlow for Artificial Intelligence, Machine Learning and Deep Learning This c ...
- Recurrent Neural Network[Content]
下面的RNN,LSTM,GRU模型图来自这里 简单的综述 1. RNN 图1.1 标准RNN模型的结构 2. BiRNN 3. LSTM 图3.1 LSTM模型的结构 4. Clockwork RNN ...
- 改善深层神经网络-week3编程题(Tensorflow 实现手势识别 )
TensorFlow Tutorial Initialize variables Start your own session Train algorithms Implement a Neural ...
- Convolutional Neural Network-week1编程题(TensorFlow实现手势数字识别)
1. TensorFlow model import math import numpy as np import h5py import matplotlib.pyplot as plt impor ...
- 吴恩达课后习题第二课第三周:TensorFlow Introduction
目录 第二课第三周:TensorFlow Introduction Introduction to TensorFlow 1 - Packages 1.1 - Checking TensorFlow ...
随机推荐
- 在latex或者mathtype中如何输入花体,如拉式量L
这个问题困扰我很久,知道我找到这个答案: 把 \mathcal{L} 直接黏贴到mathtype的编辑框中就可以产生花体L了
- ‘百度杯’十月场web ---login
首先一看的题,既然是是web类的,就要查看源码,一看,最先有一行注释,估摸着是用户名和密码 果然登录上去了,显示一段乱码,源码也没有什么东西, 那就抓一次包吧 发现响应头里边有个show:0的响应,而 ...
- django之视图获取用户请求相关信息以及请求头
def index(request): print(type(request)) print(request.environ['HTTP_USER_AGENT'])#字典格式 print(reques ...
- 小甲鱼Python第十四课后习题
字符串格式化符号含义 符 号 说 明 %c 格式化字符及其ASCII码[>>> '%c' %97 'a'] %s ...
- GMA Round 1 大吉大利,晚上吃鸡
传送门 大吉大利,晚上吃鸡 新年走亲访友能干点啥呢,咱开黑吃鸡吧. 这里有32个人,每个人都可能想玩或者不想玩,这样子一共有$2^{32}$种可能.而要开黑当然得4人4人组一队(四人模式),所以说如果 ...
- Quartz Cron表达式 每周、每月执行一次
原文:https://blog.csdn.net/qq_33432559/article/details/75633767 系统中通常有些需要自动执行的任务,这些任务可能每隔一段时间就要执行一次,也可 ...
- 更新 app 操作过期提示
增加的操作过期提示,再让用户选择是否登录,登录成功后自动返回上一次操作的面页
- Linux目录/usr缩写及目录结构说明
在 linux 文件结构中,有一个很神奇的目录 —— /usr. 讨论中,大部分观点认为: usr 是 unix system resources 的缩写: usr 是 user 的缩写: u ...
- 系统架构-设计模式(适配器、观察者、代理、抽象工厂等)及架构模式(C/S、B/S、分布式、SOA、SaaS)(干货)
博客园首页是需要分享干货的地方,今天早上写的<HRMS(人力资源管理系统)-从单机应用到SaaS应用-系统介绍>内容下架了,所以我就按照相关规定,只分享干货,我把之前写完的内容整理发布上来 ...
- Git结合tar自动打升级包
背景最近在看Git,那么看了之后就需要用Git来解决一些工作中遇到的问题,学了不能用在工作中,等于白学. 这次遇到的问题是打包升级的问题,我们公司目前还处于最原始的手工打更新包的状况,每次打包都要找开 ...