def __call__(self, inputs, state, scope=None):
"""Gated recurrent unit (GRU) with nunits cells."""
with _checked_scope(self, scope or "gru_cell"):
with vs.variable_scope("gates"): # Reset gate and update gate.
# We start with bias of 1.0 to not reset and not update.
value = sigmoid(_linear(
[inputs, state], 2 * self._num_units, True, 1.0))
r, u = array_ops.split(
value=value,
num_or_size_splits=2,
axis=1)
with vs.variable_scope("candidate"):
res = self._activation(_linear([inputs, r * state],
self._num_units, True))
if self._batch_norm:
c = batch_norm(res,
center=True, scale=True,
is_training=self._is_training,
scope='bn1')
else:
c = res
new_h = u * state + (1 - u) * c
return new_h, new_h
评论列表
文章目录