Example #1
0
def _lookup(h, t, l):

    ent = var('ent_embeddings')
    mat = var('transfer_matrix')
    rel = var('rel_embeddings')

    return at(ent, h), at(ent, t), at(mat, l), at(rel, l)
Example #2
0
def _lookup(h, t, l):

    nor = var('normal_vectors')
    ent = var('ent_embeddings')
    rel = var('rel_embeddings')

    return at(ent, h), at(ent, t), at(nor, l), at(rel, l)
Example #3
0
def _lookup(h, t, r):
    '''Gets the variables concerning a fact.'''

    eRe = var('ent_re_embeddings')
    rRe = var('rel_re_embeddings')
    eIm = var('ent_im_embeddings')
    rIm = var('rel_im_embeddings')

    return at(eRe, h), at(eRe, t), at(rRe, r), at(eIm, h), at(eIm,
                                                              t), at(rIm, r)
Example #4
0
def _score(h, t, l):
    '''The term to embed triples.'''

    ent = var('ent_embeddings')
    rel = var('rel_embeddings')
    etr = var('ent_transfer')
    rtr = var('rel_transfer')

    return at(ent, h), at(etr, h), at(ent, t), at(etr, t), at(rel,
                                                              l), at(rtr, l)
Example #5
0
    def _embedding_def(self):
        '''Initializes the variables of the model.'''

        e, r, d = self.base[0], self.base[1], self.dimension[0]

        ent = var('ent_embeddings', [e, d, 1])
        rel = var('rel_matrices', [r, d, d])

        yield 'ent_embeddings', ent
        yield 'rel_matrices', rel

        self._entity = squeeze(at(ent, self.predict_h), [-1])
Example #6
0
File: HolE.py Project: xeren/OpenKE
    def _embedding_def(self):
        '''Initializes the variables of the model.'''

        e, r, d = self.base[0], self.base[1], self.dimension[0]

        ent = var('ent_embeddings', [e, d])
        rel = var('rel_embeddings', [r, d])

        yield 'ent_embeddings', ent
        yield 'rel_embeddings', rel

        self._entity = at(ent, self.predict_h)
        self._relation = at(rel, self.predict_l)
Example #7
0
    def _embedding_def(self):
        '''Initializes the variables of the model.'''

        e, r, d = self.base[0], self.base[1], self.dimension[0]

        #Defining required parameters of the model, including embeddings of entities and relations, and normal vectors of planes
        ent = var("ent_embeddings", [e, d])
        rel = var("rel_embeddings", [r, d])
        nor = var("normal_vectors", [r, d])

        yield 'ent_embeddings', ent
        yield 'rel_embeddings', rel
        yield 'normal_vectors', nor

        self._entity = at(ent, self.predict_h)
        self._relation = at(rel, self.predict_l)
Example #8
0
    def _embedding_def(self):
        '''Initializes the variables of the model.'''

        e, r = self.base
        d, k = self.dimension

        ent = var('ent_embeddings', [e, d, 1])
        rel = var('rel_embeddings', [r, k, 1])
        mat = var('transfer_matrix', [r, k, d])

        yield 'ent_embeddings', ent
        yield 'rel_embeddings', rel
        yield 'transfer_matrix', mat

        self._entity = at(ent, self.predict_h)
        self._relation = at(rel, self.predict_l)
Example #9
0
    def _embedding_def(self):
        '''Initializes the variables.'''

        e, r, d = self.base[0], self.base[1], self.dimension[0]

        eRe = var("ent_re_embeddings", [e, d])
        eIm = var("ent_im_embeddings", [e, d])
        rRe = var("rel_re_embeddings", [r, d])
        rIm = var("rel_im_embeddings", [r, d])

        yield 'ent_re_embeddings', eRe
        yield 'ent_im_embeddings', eIm
        yield 'rel_re_embeddings', rRe
        yield 'rel_im_embeddings', rIm

        self._entity = at(eRe, self.predict_h)
        self._relation = at(rRe, self.predict_l)
Example #10
0
    def _update(self, x):
        x = tf.reshape(x, (-1, ) + self.shape)
        n1 = self._n
        n2 = len(x)
        n = n1 + n2
        mean = tf.reduce_mean(x, axis=0)
        M = (n1 * self._M + n2 * mean) / n

        delta = self._M - mean
        delta2 = tf.square(delta)
        var = tf.var(x, axis=0)
        S = (self._S * n1 + var * n2 + n1 * n2 / n * delta2) / n

        self._M = M
        self._n = n
        self._S = S
Example #11
0
def _lookup(h, t, l):

    ent = var('ent_embeddings')
    rel = var('rel_matrices')

    return at(ent, h), at(ent, t), at(rel, l)