|
@@ -128,38 +128,3 @@ class DSSMLayer(nn.Layer):
|
|
|
|
|
|
return left_vec, right_vec
|
|
return left_vec, right_vec
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- def forward(self, input_data, is_infer):
|
|
|
|
- query_fc = input_data[0]
|
|
|
|
- for n_layer in self._query_layers:
|
|
|
|
- query_fc = n_layer(query_fc)
|
|
|
|
- self.query_fc = query_fc
|
|
|
|
-
|
|
|
|
- doc_pos_fc = input_data[1]
|
|
|
|
- for n_layer in self._doc_layers:
|
|
|
|
- doc_pos_fc = n_layer(doc_pos_fc)
|
|
|
|
- self.doc_pos_fc = doc_pos_fc
|
|
|
|
-
|
|
|
|
- self.params = [self._query_layers[-2].bias]
|
|
|
|
-
|
|
|
|
- R_Q_D_p = F.cosine_similarity(
|
|
|
|
- query_fc, doc_pos_fc, axis=1).reshape([-1, 1])
|
|
|
|
-
|
|
|
|
- if is_infer:
|
|
|
|
- return R_Q_D_p, paddle.ones(shape=[self.slice_end, 1])
|
|
|
|
-
|
|
|
|
- R_Q_D_ns = []
|
|
|
|
- for i in range(len(input_data) - 2):
|
|
|
|
- doc_neg_fc_i = input_data[i + 2]
|
|
|
|
- for n_layer in self._doc_layers:
|
|
|
|
- doc_neg_fc_i = n_layer(doc_neg_fc_i)
|
|
|
|
- R_Q_D_n = F.cosine_similarity(
|
|
|
|
- query_fc, doc_neg_fc_i, axis=1).reshape([-1, 1])
|
|
|
|
- R_Q_D_ns.append(R_Q_D_n)
|
|
|
|
- concat_Rs = paddle.concat(x=[R_Q_D_p] + R_Q_D_ns, axis=1)
|
|
|
|
- prob = F.softmax(concat_Rs, axis=1)
|
|
|
|
- hit_prob = paddle.slice(
|
|
|
|
- prob, axes=[0, 1], starts=[0, 0], ends=[self.slice_end, 1])
|
|
|
|
- return R_Q_D_p, hit_prob
|
|
|