- pointer network
- Recursive Structure
十九、Pointer Network(指针网络)
解一系列演算法:
给十个data point,用自动的方法找出一些点,连接起来可以把其余的点包进去。
一个neural network,它的input就是十个data point,每一个data point就用xy坐标表示,所以input就是10个二维的vector,丢到network里去,期待它的output为(4 2 7 6 5 3):
那这个pointer network怎么解呢?
input一排sequence,output另一个sequence,好像可以直接用sequence-to-sequence直接解:
结果是不work的。为什么?如果input sequence长短不一样的时候,由于encoder是一个RNN,encoder可以处理,但是decoder的长短无法改变。
解决:one can add attention。对attention做一下改造,让network可以动态地决定它输出的set有多大。
做法:用attention的model,把sequence读进来,但是要加一个特别的符号 ( x 0 y 0 ) \begin{pmatrix} x_0\\ y_0 \end{pmatrix} (x0y0),代表“END”这个值。采用attention-based model,产生一个key z 0 z^0 z0,用这个key对input做attention,对每一个input产生一个attention weight,这个attention的weight就是output 的distribution,根据这个attention weight去取argmax,假设现在 h 1 h^1 h1的值最大,就是output 1,如下图所示:
如何training?
labeled data告诉我们,在第一个time state,output 1才是对的,就会希望在training的时候,得到由attention所构成的distribution它在 h 1 h^1 h1的值最大,其它值都趋近于0,然后去minimize cross-entropy。
好处:随着input sequence的变化,现在output的set也会跟着改变。
假设上图的output为1 ,现在就把 ( x 1 y 1 ) \begin{pmatrix} x_1\\ y_1 \end{pmatrix} (x1y1)丢进去,产生新的key z 1 z^1