我正在研究文本摘要并建立我的词汇表,我已经训练了一个数据集。现在我需要来自 Google 的 Word2Vec 的这些词汇的向量。我编写了简单的代码,获取每个单词并在包含大约 300 万个单词的 google-vectors 文件中搜索它。但问题是,这种线性搜索实际上需要数周的时间来计算。我正在使用 python 来做这件事。如何以更有效的方式搜索这些单词?
found_counter = 0
file1 = open('vocab_training.txt', 'r').read()
for i, line in enumerate(file1):
if i >= 50:
break
file2 = open('google-vectors.txt', 'r' )
for j, line2 in enumerate(file2):
if line.lower() == line2.split():
found_counter += 1
file2.close()
print(found_counter)