【问题标题】:Training NER model with Spacy only uses one core使用 Spacy 训练 NER 模型仅使用一个核心
【发布时间】: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


    【解决方案1】:

    似乎从 2.1 版开始,Spacy 中的训练仅使用一个单核完成。 (https://github.com/explosion/spaCy/issues/3507) 当矩阵乘法的并行化在其他框架中被证明是值得的时,我觉得有点奇怪。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-04-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-03
      • 2021-06-11
      • 2020-10-16
      • 2021-04-08
      相关资源
      最近更新 更多