Пример #1
0
    def __init__(self, path, normalize=True, eig=0.0, transpose=False):
        if transpose:
            ut = np.load(path + '.vt.npy')
            self.wi, self.iw = load_vocabulary(path + '.contexts.vocab')
        else:
            ut = np.load(path + '.ut.npy')
            self.wi, self.iw = load_vocabulary(path + '.words.vocab')
        s = np.load(path + '.s.npy')
        
        if eig == 0.0:
            self.m = ut.T
        elif eig == 1.0:
            self.m = s * ut.T
        else:
            self.m = np.power(s, eig) * ut.T

        self.dim = self.m.shape[1]

        if normalize:
            self.normalize()
Пример #2
0
 def load(cls, path, normalize=True, restricted_context=None, thresh=None):
     mat = load_matrix(path, thresh)
     word_vocab, context_vocab = load_vocabulary(mat, path)
     return cls(mat, word_vocab, context_vocab, normalize, restricted_context)