利用gensim模块中的glove2word2vec来将glove词向量转化成另一个文件里的glove2word2vec向量,方便以后备用
from gensim.test.utils import datapath,get_tmpfile
from gensim.scripts.glove2word2vec import glove2word2vec
glove_file = datapath(r'F:\data set\NLP\glove.6B.100d.txt')
glove2word2vec_file = get_tmpfile(r'F:\data set\NLP\glove2word2vec.6B.100d.txt')
transformer = glove2word2vec(glove_file,glove2word2vec_file)
#调用
from gensim.models import KeyedVectors
model = KeyedVectors.load_word2vec_format(r'F:\data set\NLP\glove2word2vec.6B.100d.txt')#可以利用KeyedVectors进行词向量的读取
调用结果存放在model中:
调用model内的变量:
model.index2word
['the', ',', '.', 'of', 'to', 'and', 'in', 'a', '"', "'s", 'for', '-', 'that', 'on', 'is', 'was', 'said', 'with', 'he', 'as', 'it', 'by', 'at', '(', ')', 'from', 'his', "''", '``', 'an', 'be', 'has', 'are', 'have', 'but', 'were', 'not', 'this', 'who', 'they', 'had', 'i', 'which', 'will', 'their', ':', 'or', 'its', 'one', 'after', 'new', 'been', 'also', 'we', 'would', 'two', 'more', "'", 'first', 'about', 'up', 'when', 'year', 'there', 'all', '--', 'out', 'she', 'other', 'people', "n't",