def predict(self, left_slots, right_slots): """ predict graph of this net """ left = left_slots[self.left_name] right = right_slots[self.right_name] left_emb = self.emb_layer.ops(left) # (N, len, D) right_emb = self.emb_layer.ops(right) # (N, len, D) ## left bi_left_outputs, _ = tf.nn.bidirectional_dynamic_rnn(self.fw_cell, self.bw_cell, left_emb, sequence_length=utility.seq_length(left), dtype=tf.float32) left_seq_encoder = tf.concat(bi_left_outputs, -1) ## right bi_right_outputs, _ = tf.nn.bidirectional_dynamic_rnn(self.fw_cell, self.bw_cell, right_emb, sequence_length=utility.seq_length(right), dtype=tf.float32) right_seq_encoder = tf.concat(bi_right_outputs, -1) cross = tf.matmul(left_seq_encoder, tf.transpose(right_seq_encoder, [0, 2, 1])) # (N, len, len) if self.match_mask: cross_mask = utility.get_cross_mask(left, right) else: cross_mask = None conv_pool = self.cnn_layer.ops(cross, mask=cross_mask) pool_relu = self.relu_layer.ops(conv_pool) relu_hid1 = self.fc1_layer.ops(pool_relu) hid1_tanh = self.tanh_layer.ops(relu_hid1) pred = self.fc2_layer.ops(hid1_tanh) return pred
def predict(self, left_slots, right_slots): """ predict graph of this net """ left = left_slots[self.left_name] right = right_slots[self.right_name] left_emb = self.emb_layer.ops(left) # (N, len, D) right_emb = self.emb_layer.ops(right) # (N, len, D) cross = tf.matmul(left_emb, tf.transpose(right_emb, [0, 2, 1])) # (N, len, len) if self.match_mask: cross_mask = get_cross_mask(left, right) else: cross_mask = None conv_pool = self.cnn_layer.ops(cross, mask=cross_mask) pool_relu = self.relu_layer.ops(conv_pool) relu_hid1 = self.fc1_layer.ops(pool_relu) hid1_tanh = self.tanh_layer.ops(relu_hid1) pred = self.fc2_layer.ops(hid1_tanh) return pred