def get_output_for(self, inputs, **kwargs):
sequence_length = inputs[0].shape[1]/2
input_first = inputs[0][(slice(None),) + (slice(0, sequence_length),)]
input_second = inputs[1]
mask = inputs[self.mask_incoming_index]
if input_second.ndim == 3:
input_second = input_second[(slice(None), -1)]
M = nonlinearities.tanh(T.dot(input_first, self.W_y) + T.dot(input_second.dimshuffle(0, 'x', 1), self.W_h))
# M.shape = N * L * k
alpha = nonlinearities.softmax(T.dot(M, self.w.T).reshape((inputs[0].shape[0], sequence_length)))
# alpha.shape = N * L
alpha = alpha * mask
r = T.batched_dot(alpha, input_first)
# r.shape = N * k
h_star = nonlinearities.tanh(T.dot(r, self.W_p) + T.dot(input_second, self.W_x))
return h_star
评论列表
文章目录