【问题标题】:Sharing Spacy model between processes在进程之间共享 Spacy 模型
【发布时间】:2022-01-31 11:31:00
【问题描述】:

我的代码使用 Python 的多处理进行并行计算。作为计算的一部分,使用了 Spacy。使用nlp = spacy.load("de_core_news_lg")创建一个singel spacy对象并通过多个进程访问它以进行命名实体识别是否节省?

【问题讨论】:

    标签: python-multiprocessing spacy


    【解决方案1】:

    您可以通过将 n_process 参数传递给 nlp.pipe 来利用 spaCy 的多处理优势。例如:

    docs = ["This is the first doc", "this is the second doc"]
    
    nlp = spacy.load("en_core_web_sm")  # use your model here
    
    docs_tokens = []
    for doc in nlp.pipe(docs, n_process=2):
        tokens = [t.text for t in doc]
        docs_tokens.append(tokens)
    

    spaCy documentationSpeed FAQ 中有更多相关信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-05-07
      • 2012-07-22
      • 2012-04-09
      • 2011-07-06
      • 2014-10-22
      • 1970-01-01
      • 2012-06-02
      相关资源
      最近更新 更多