【发布时间】:2019-06-15 16:22:45
【问题描述】:
当我使用 Spacy 训练 NER 模型并监控我的 CPU 时,我可以看到它只使用 1 个内核。
我在 Spacy 文档中只找到了一个多处理示例,但并未应用于培训:https://github.com/explosion/spaCy/blob/master/examples/pipeline/multi_processing.py 我只是使用示例中提供的训练代码,但 TRAINING_DATA 中的 500000 个元组列表遵循相同的结构: ("rawtext", {"entities": [(entity_start_offset, entity_end_offset, "ENTITY")]})
with nlp.disable_pipes(*other_pipes): # only train NER
for itn in range(n_iter):
random.shuffle(TRAIN_DATA)
losses = {}
batches = spacy.util.minibatch(TRAIN_DATA,
size=spacy.util.compounding(4., 32., 1.001))
for i, batch in enumerate(batches):
print(i)
texts, annotations = zip(*batch)
# Updating the weights
nlp.update(texts, annotations, sgd=optimizer,
drop=0.35, losses=losses)
print('Losses', losses)
我需要使用多核加速训练。目前,使用 1 个单核每个 epoc 需要 40 分钟。
【问题讨论】:
标签: multiprocessing spacy