def _step_forward_with_context(self, x_t, x_m, h_tm1, c_z, c_r, c_h):
"""
x_t: input at time t
x_m: mask of x_t
h_tm1: previous state
c_x: contex of the rnn
"""
z_t = T.nnet.sigmoid(T.dot(x_t, self.W_xz) +
T.dot(h_tm1, self.W_hz) + c_z + self.b_z)
r_t = T.nnet.sigmoid(T.dot(x_t, self.W_xr) +
T.dot(h_tm1, self.W_hr) + c_r + self.b_r)
can_h_t = T.tanh(T.dot(x_t, self.W_xh) +
r_t * T.dot(h_tm1, self.W_hh) + c_h +
self.b_h)
h_t = (1 - z_t) * h_tm1 + z_t * can_h_t
h_t = x_m[:, None] * h_t + (1. - x_m[:, None]) * h_tm1
return h_t
评论列表
文章目录