def prep_model(inputs, N, s0pad, s1pad, c, granlevels=1):
# LSTM
lstm = LSTM(N, return_sequences=True, implementation=2,
kernel_regularizer=l2(c['l2reg']), recurrent_regularizer=l2(c['l2reg']),
bias_regularizer=l2(c['l2reg']))
x1 = inputs[0]
x2 = inputs[1]
h1 = lstm(x1)
h2 = lstm(x2)
W_x = Dense(N, kernel_initializer='glorot_uniform', use_bias=True,
kernel_regularizer=l2(c['l2reg']))
W_h = Dense(N, kernel_initializer='orthogonal', use_bias=True,
kernel_regularizer=l2(c['l2reg']))
sigmoid = Activation('sigmoid')
a1 = multiply([x1, sigmoid( add([W_x(x1), W_h(h1)]) )])
a2 = multiply([x2, sigmoid( add([W_x(x2), W_h(h2)]) )])
# Averaging
avg = Lambda(function=lambda x: K.mean(x, axis=1),
output_shape=lambda shape: (shape[0], ) + shape[2:])
gran1 = avg(a1)
gran2 = avg(a2)
return [gran1, gran2], N
评论列表
文章目录