def __call__(self, inputs, state, scope=None):
"""Gated recurrent unit (GRU) with nunits cells."""
with tf.variable_scope(scope or type(self).__name__): # "GRUCell"
if self.pretanh:
state = state[:, :self.num_units]
with tf.variable_scope("Gates"): # Reset gate and update gate.
# We start with bias of 1.0 to not reset and not update.
r, u = tf.split(1, 2, utils.linear([inputs, state], 2 * self.num_units, True, 1.0))
r, u = tf.nn.sigmoid(r), tf.nn.sigmoid(u)
with tf.variable_scope("Candidate"):
preact = utils.linear([inputs, r * state], self.num_units, True)
c = self.activation(preact)
new_h = u * state + (1 - u) * c
if self.pretanh:
new_state = tf.concat(1, [new_h, preact])
else:
new_state = new_h
return new_h, new_state
评论列表
文章目录