有没有办法只访问 word2vec 和 GloVe 的预训练向量的词汇表?我不需要整个 n 维嵌入。
word2vec 和 GloVe 的词汇表
数据挖掘
nlp
word2vec
词嵌入
2021-09-23 01:01:06
2个回答
简而言之:是的,你可以。
您需要首先使用 Python 中的 Gensim 模块加载向量。
# Load Google news vectors
word2vec_path = "path_to_the_vectors/GoogleNews-vectors-negative300.bin"
word2vec = gensim.models.KeyedVectors.load_word2vec_format(word2vec_path, binary=True)
# contains the list of all unique words in pre-trained word2vec vectors
w2v_vocabulary = word2vec.vocab
您可以通过以下方式预处理词嵌入文件来完成您想要的操作:
with open('glove.txt') as f:
text = f.readlines()
word_list = [line.strip().split()[0] for line in text]