【发布时间】:2021-02-14 17:02:40
【问题描述】:
这个想法是用不同的新语料库更新特定的预训练 word2vec 模型。我有以下
# c1, c2 are each a list of 100 files
filelist = [c1, c2, c3, c4, c5, c6, c7, c8, c9, c10]
def update_model(files):
# loading a pre-trained model
trained_model = gensim.models.Word2Vec.load("model_both_100")
# Document feeder is an iterable
docs = DocumentFeeder(files)
trained_model.build_vocab(docs, update=True)
trained_model.train(docs, total_examples=trained_model.corpus_count, epochs=trained_model.epochs)
with Pool(processes=10) as P:
P.map(update_model, filelist)
运行大约需要 13 分钟。但是非并行版本(循环filelist)需要大约 11 分钟。为什么会这样?在 12 核 cpu 上运行。
【问题讨论】:
标签: parallel-processing nlp python-multiprocessing gensim word2vec