def GRUStep(name, input_dim, hidden_dim, x_t, h_tm1):
processed_input = lib.ops.Dense(
name+'.Input',
input_dim,
3 * hidden_dim,
x_t
)
gates = T.nnet.sigmoid(
lib.ops.Dense(
name+'.Recurrent_Gates',
hidden_dim,
2 * hidden_dim,
h_tm1,
bias=False
) + processed_input[:, :2*hidden_dim]
)
update = gates[:, :hidden_dim]
reset = gates[:, hidden_dim:]
scaled_hidden = reset * h_tm1
candidate = T.tanh(
lib.ops.Dense(
name+'.Recurrent_Candidate',
hidden_dim,
hidden_dim,
scaled_hidden,
bias=False,
init='orthogonal'
) + processed_input[:, 2*hidden_dim:]
)
one = lib.floatX(1.0)
return (update * candidate) + ((one - update) * h_tm1)
评论列表
文章目录