def __call__(self,i):
# assume hidden, input is of shape [batch,num_h] and [batch,num_in]
hidden = i[0]
inp = i[1]
wz,wr,w = self.wz,self.wr,self.w
dims = tf.rank(inp)
c = tf.concat([hidden,inp],axis=dims-1)
z = tf.sigmoid(wz(c))
r = tf.sigmoid(wr(c))
h_c = tf.tanh(w(tf.concat([hidden*r,inp],axis=dims-1)))
h_new = (1-z) * hidden + z * h_c
return h_new
# GRU2 as reported in *Gate-Variants of Gated Recurrent Unit (GRU) Neural Networks*
# the gates are now only driven by hidden state.
# mod: removed reset gate.
# conclusion 20171220: GRU2(without reset gate) is almost as good as GRU.
评论列表
文章目录