在进程之间共享 Spacy 模型
Sharing Spacy model between processes
我的代码使用 Python 的多处理进行并行计算。作为计算的一部分,使用了 Spacy。使用 nlp = spacy.load("de_core_news_lg")
创建单个 spacy 对象并通过多个进程访问它以进行命名实体识别是否安全?
您可以通过将 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 documentation, as well as this Speed FAQ 中有更多相关信息。
我的代码使用 Python 的多处理进行并行计算。作为计算的一部分,使用了 Spacy。使用 nlp = spacy.load("de_core_news_lg")
创建单个 spacy 对象并通过多个进程访问它以进行命名实体识别是否安全?
您可以通过将 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 documentation, as well as this Speed FAQ 中有更多相关信息。