【发布时间】:2018-02-09 11:47:28
【问题描述】:
我注意到,将文档添加到 gensim Dictionary 时,执行时间从 0.2 秒跃升至 6 秒以上,达到 200 万字。
下面的代码是一个简单的例子。我遍历 int 并在每次迭代时将数字添加到字典中。
from gensim import corpora
import time
dict_transcript = corpora.Dictionary()
for i in range(1,10000000):
start_time = time.time()
doc = [str(i)]
dict_transcript.add_documents([doc])
print("Iter "+str(i)+" done in " + str(time.time() - start_time) + ' w/ '+str(len(doc)) + ' words and dico size ' +
str(len(dict_transcript)))
当达到 200 万字时,我确实得到了以下输出:
Iter 1999999 done in 0.0 w/ 1 words and dico size 1999999
Iter 2000000 done in 0.0 w/ 1 words and dico size 2000000
Iter 2000001 done in 0.0 w/ 1 words and dico size 2000001
Iter 2000002 done in 7.940511226654053 w/ 1 words and dico size 2000001
有什么原因吗?有谁知道如何绕过这个问题? 我在一个大语料库上使用这本字典,我将它标记为二元组,所以我希望字典有几百万行。
非常感谢
【问题讨论】:
标签: python dictionary nlp gensim