Esempio n. 1
0
    def _initialize_weights(self):
        weights = dict()

        # weight matrix for translation
        weights['w_trans'] = noise_weight_variable([self.d_w2v, self.d_w2v],
                                                   'w_trans')
        weights['b_trans'] = noise_bias_variable([self.d_w2v], 'b_trans')

        # NOT USED! weight matrix from cell_w2v -> cell_vec
        weights['wc'] = noise_weight_variable([self.d_w2v, self.d_vec], 'wc')
        weights['bc'] = noise_bias_variable([self.d_vec], 'bc')

        # NOT USED! weight matrix from entity_w2v -> ent_vec
        weights['we'] = noise_weight_variable([self.d_w2v, self.d_vec], 'we')
        weights['be'] = noise_bias_variable([self.d_vec], 'be')

        # weight matrix from concat(cell_vec, context_vec) -> left mention feature
        weights['w1'] = noise_weight_variable([self.d_vec * 2, self.d_hidden],
                                              'w1')
        weights['b1'] = noise_bias_variable([self.d_hidden], 'b1')

        # weight matrix from ent_vec -> right entity feature
        weights['w2'] = noise_weight_variable([self.d_vec, self.d_hidden],
                                              'w2')
        weights['b2'] = noise_bias_variable([self.d_hidden], 'b2')

        return weights
Esempio n. 2
0
    def _build_graph(self):

        self.weights = self._initialize_weights()
        # weight matrix from concat(vec_1, vec_2, vec_3) -> final_vec
        self.coherence = tf.placeholder(tf.float32, [None, 1])
        self.weights['wf'] = noise_weight_variable(
            [self.d_hidden * 2 + 1, self.d_final], 'wf')

        # build two similarity features
        self._build_cell_feature()
        self._build_context_feature()

        # build coherence features
        self.vec_Three = self.coherence

        # OLD
        # self.vec_Three, intermediate_dict = \
        #     build_colwise_coherence_feature(self.coherence, self.d_vec, self.d_vec)

        # concatenate all vectors together, shape = (batch_size, d_hidden * n)
        # final fully connected layer, shape = (batch_size, d_final)
        self.final_layer = self.transfer(
            tf.add(
                tf.matmul(
                    tf.concat([
                        tf.concat([self.vec_ONE, self.vec_TWO], 1),
                        self.vec_Three
                    ], 1), self.weights['wf']), self.weights['bf']))

        # output layer has only one number, shape = (batch_size, 1)
        self._build_score_layer_rank()
Esempio n. 3
0
    def _build_graph(self):
        self.weights = self._initialize_weights()
        # weight matrix from concat(vec_1, vec_2) -> final_vec
        self.weights['wf'] = noise_weight_variable(
            [self.d_hidden, self.d_final], 'wf')

        # model 5 only use coherence features
        self.vec_Three = self.coherence

        # final fully connected layer, shape = (batch_size, d_final)
        self.final_layer = self.transfer(
            tf.add(tf.matmul(self.vec_Three, self.weights['wf']),
                   self.weights['bf']))

        # output layer has only one number, shape = (batch_size, 1)
        self._build_score_layer_rank()
Esempio n. 4
0
    def _build_graph(self):
        self.weights = self._initialize_weights()
        # weight matrix from concat(vec_1, vec_2) -> final_vec
        self.weights['wf'] = noise_weight_variable(
            [self.d_hidden, self.d_final], 'wf')

        # model 4 only use cell vs. entity context similarity features
        self._build_context_feature()

        # final fully connected layer, shape = (batch_size, d_final)
        self.final_layer = self.transfer(
            tf.add(tf.matmul(self.vec_TWO, self.weights['wf']),
                   self.weights['bf']))

        # output layer has only one number, shape = (batch_size, 1)
        self._build_score_layer()
Esempio n. 5
0
    def _build_graph(self):

        self.weights = self._initialize_weights()
        # weight matrix from concat(vec_1, vec_2) -> final_vec
        self.weights['wf'] = noise_weight_variable(
            [self.d_hidden * 2, self.d_final], 'wf')

        # model 1 only use cell vs. entity surface similarity features
        self._build_cell_feature()
        self.vec_Three = self.coherence

        # concatenate 2 vectors together, shape = (batch_size, d_hidden * 2)
        # final fully connected layer, shape = (batch_size, d_final)
        self.final_layer = self.transfer(
            tf.add(
                tf.matmul(tf.concat([self.vec_ONE, self.vec_Three], 1),
                          self.weights['wf']), self.weights['bf']))

        # output layer has only one number, shape = (batch_size, 1)
        self._build_score_layer_rank()
Esempio n. 6
0
    def _initialize_weights(self):
        weights = dict()

        # weight matrix for translation
        weights['w_trans'] = noise_weight_variable([self.d_w2v, self.d_w2v],
                                                   'w_trans')
        weights['b_trans'] = noise_bias_variable([self.d_w2v], 'b_trans')

        # weight matrix from cell_w2v -> cell_vec
        weights['wc'] = noise_weight_variable([self.d_w2v, self.d_vec], 'wc')
        weights['bc'] = noise_bias_variable([self.d_vec], 'bc')

        # weight matrix from entity_w2v -> ent_vec
        # todo: consider gloss by a CNN layer
        weights['we'] = noise_weight_variable([self.d_w2v, self.d_vec], 'we')
        weights['be'] = noise_bias_variable([self.d_vec], 'be')

        # weight matrix from row cells & column cells -> context vec
        # todo: consider specialize header vector
        # weights['wcx'] = noise_weight_variable([1, 3, self.d_w2v, self.d_vec], 'wcx')
        # weights['bcx'] = noise_bias_variable([self.d_vec], 'bcx')

        # weight matrix from concat(cell, ent) -> feature NO.1
        weights['w1'] = noise_weight_variable([self.d_vec * 2, self.d_hidden],
                                              'w1')
        weights['b1'] = noise_bias_variable([self.d_hidden], 'b1')

        # weight matrix from concat(context, ent) -> feature NO.2
        weights['w2'] = noise_weight_variable([self.d_vec * 2, self.d_hidden],
                                              'w2')
        weights['b2'] = noise_bias_variable([self.d_hidden], 'b2')

        # define weight matrix from concatenation of 1~3 features -> final_vec in derived class
        weights['bf'] = noise_bias_variable([self.d_final], 'bf')

        # weight matrix from final_vec -> score_layer
        weights['wo'] = noise_weight_variable([self.d_final, 1], 'wo')
        weights['bo'] = noise_bias_variable([1], 'bo')

        return weights