def step(self, x_input, states):
#print "x_input:", x_input, x_input.shape
# <TensorType(float32, matrix)>
input_shape = self.input_spec[0].shape
en_seq = states[-1]
_, [h, c] = super(PointerLSTM, self).step(x_input, states[:-1])
# vt*tanh(W1*e+W2*d)
dec_seq = K.repeat(h, input_shape[1])
Eij = time_distributed_dense(en_seq, self.W1, output_dim=1)
Dij = time_distributed_dense(dec_seq, self.W2, output_dim=1)
U = self.vt * tanh(Eij + Dij)
U = K.squeeze(U, 2)
# make probability tensor
pointer = softmax(U)
return pointer, [h, c]
python类time_distributed_dense()的实例源码
def step(self, x, states):
h_tm1, c_tm1, y_tm1, B, U, H = states
s = K.dot(c_tm1, self.W_h) + self.b_h
s = K.repeat(s, self.input_length)
energy = time_distributed_dense(s + H, self.W_a, self.b_a)
energy = K.squeeze(energy, 2)
alpha = K.softmax(energy)
alpha = K.repeat(alpha, self.input_dim)
alpha = K.permute_dimensions(alpha, (0, 2, 1))
weighted_H = H * alpha
v = K.sum(weighted_H, axis=1)
y, new_states = super(AttentionDecoder, self).step(v, states[:-1])
return y, new_states
def preprocess_input(self, x):
if self.consume_less == 'cpu':
input_shape = self.input_spec[0].shape
input_dim = input_shape[2]
timesteps = input_shape[1]
return time_distributed_dense(x, self.W, self.b, self.dropout_W,
input_dim, self.output_dim,
timesteps)
else:
return x
layer_normalization_RNN.py 文件源码
项目:New_Layers-Keras-Tensorflow
作者: WeidiXie
项目源码
文件源码
阅读 26
收藏 0
点赞 0
评论 0
def preprocess_input(self, x):
if self.consume_less == 'cpu':
input_shape = self.input_spec[0].shape
input_dim = input_shape[2]
timesteps = input_shape[1]
return time_distributed_dense(x, self.W, self.b, self.dropout_W,
input_dim, self.output_dim,
timesteps)
else:
return x
def preprocess_input(self, x):
if self.consume_less == 'cpu':
input_shape = K.int_shape(x)
input_dim = input_shape[2]
timesteps = input_shape[1]
x_f = time_distributed_dense(x, self.W_f, self.b_f, self.dropout_W,
input_dim, self.output_dim, timesteps)
x_h = time_distributed_dense(x, self.W_h, self.b_h, self.dropout_W,
input_dim, self.output_dim, timesteps)
return K.concatenate([x_f, x_h], axis=2)
else:
return x
def preprocess_input(self, x):
if self.consume_less == 'cpu':
input_shape = K.int_shape(x)
input_dim = input_shape[2]
timesteps = input_shape[1]
return time_distributed_dense(x, self.W, self.b, self.dropout_W,
input_dim, self.hidden_recurrent_dim,
timesteps)
else:
return x