我想构建Manhattan LSTM模型。但是计算曼哈顿距离时,输出形状有问题。
关注信息:
Tensor("concatenate_26/concat:0", shape=(?, ?, 100), dtype=float32)
Lambda信息:
Tensor("lambda_25/Exp:0", shape=(?, 1, 100), dtype=float32)
我尝试更改Lambda中的output_shape并更改曼哈顿函数的输入参数。但这没用。
def exponent_neg_manhattan_distance(x, hidden_size=100):
return K.exp(-K.sum(K.abs(x[:,:hidden_size] - x[:,hidden_size:]), axis=1, keepdims=True))
left_input = Input(shape=(max_seq_length,), dtype='int32', name='left_input')
right_input = Input(shape=(max_seq_length,), dtype='int32', name='right_input')
input_left = embed_layer(left_input)
input_right = embed_layer(right_input)
# print(input_left.shape)
# print(input_right.shape)
shared_lstm = LSTM(units=50, return_sequences=True, activation='softmax')
left_output = shared_lstm(input_left)
right_output = shared_lstm(input_right)
concats = concatenate([left_output, right_output], axis=-1)
malstm_output = Lambda(exponent_neg_manhattan_distance, output_shape=(134, ))(concats)
我希望Lambda的形状为(?,134,100)