コード例 #1
0
    def __init__(self, **kwargs):
        self.n_entity = kwargs.pop('n_entity')
        self.n_relation = kwargs.pop('n_relation')
        self.dim = kwargs.pop('dim')
        self.margin = kwargs.pop('margin')
        mode = kwargs.pop('mode', 'pairwise')
        if mode == 'pairwise':
            self.compute_gradients = self._pairwisegrads
        elif mode == 'single':
            self.compute_gradients = self._singlegrads
        else:
            raise NotImplementedError

        self.params = {'e': LookupParameter(name='e', shape=(self.n_entity, self.dim)),
                       'r': LookupParameter(name='r', shape=(self.n_relation, self.dim))}
コード例 #2
0
    def __init__(self, **kwargs):
        self.n_entity = kwargs.pop('n_entity')
        self.n_relation = kwargs.pop('n_relation')
        self.dim = kwargs.pop('dim')
        self.margin = kwargs.pop('margin')
        self.complex_ratio = kwargs.pop('cp_ratio')
        assert self.complex_ratio >= 0 and self.complex_ratio <= 1
        mode = kwargs.pop('mode', 'pairwise')
        if mode == 'pairwise':
            self.compute_gradients = self._pairwisegrads
        elif mode == 'single':
            self.compute_gradients = self._singlegrads
        else:
            raise NotImplementedError
        comp_dim = int(self.dim * self.complex_ratio)
        dist_dim = self.dim - comp_dim

        self.params = {'e_re': LookupParameter(name='e_re', shape=(self.n_entity, comp_dim)),
                       'e_im': LookupParameter(name='e_im', shape=(self.n_entity, comp_dim)),
                       'r_re': LookupParameter(name='r_re', shape=(self.n_relation, comp_dim)),
                       'r_im': LookupParameter(name='r_im', shape=(self.n_relation, comp_dim)),
                       'e': LookupParameter(name='e', shape=(self.n_entity, dist_dim)),
                       'r': LookupParameter(name='r', shape=(self.n_relation, dist_dim))}