Exemplo n.º 1
0
def LOAD(path):
    with open(os.path.join(path, "counter-fitted-vectors.txt"), "r") as f:
        id2vec = []
        word2id = {}
        for line in f.readlines():
            tmp = line.strip().split(" ")
            word = tmp[0]
            embed = np.array([float(x) for x in tmp[1:]])
            if len(embed) != 300:
                continue
            word2id[word] = len(word2id)
            id2vec.append(embed)
        id2vec = np.stack(id2vec)
    return WordVector(word2id, id2vec)
Exemplo n.º 2
0
def LOAD(path):
    with open(os.path.join(path, "chinese-merge-word-embedding.txt"),
              "r",
              encoding="utf-8") as f:
        id2vec = []
        word2id = {}
        # f.readline()
        for line in f.readlines():
            tmp = line.strip().split(' ')
            word = tmp[0]
            embed = np.array([float(x) for x in tmp[1:]])
            if len(embed) != 300:
                continue
            word2id[word] = len(word2id)
            id2vec.append(embed)
        id2vec = np.stack(id2vec)
    return WordVector(word2id, id2vec)
Exemplo n.º 3
0
def LOAD(path):
    word2id = pickle.load(open(os.path.join(path, "word2id.pkl"), "rb"))
    wordvec = pickle.load(open(os.path.join(path, "wordvec.pkl"), "rb"))
    return WordVector(word2id, wordvec)