import os,sys
os.chdir(sys.path[0]) #相对路径

import numpy as np
import logging


# 加载词向量
def load_glove(glove_dir,size):
    embeddings_index = {}
    glove_path = ("/home/zhangxj/WorkFile/本科毕业设计/glove/vectors.txt")

    logging.debug("Loading GloVe pre-trained embeddings from %s" % glove_path)

    f = open(os.path.join(glove_dir, glove_path))
    for line in f:
        values = line.split()
        word = values[0]
        coefs = np.asarray(values[1:], dtype='float32')
        embeddings_index[word] = coefs
    f.close()

    logging.debug('Total embeddings found: %s.' % len(embeddings_index))

    return embeddings_index
