首页 > 解决方案 > spacy v3 en_core_web_trf 管道和 en_core_web_lg 管道之间的区别

问题描述

我正在使用 spacy 版本 3 进行一些性能测试,以便在生产中正确调整我的实例大小。我正在观察以下内容

观察:

型号名称 没有NER的时间 NER时间 注释
en_core_web_lg 4.89 秒 21.9 秒 NER 将原始时间增加 350%
en_core_web_trf 43.64 秒 52.83 秒 NER 只比原来的时间增加了 20%

为什么在 Transformer 模型的情况下,有 NER没有 NER场景之间没有显着差异?在 en_core_web_trf 的情况下,NER 只是 POS 标记后的增量任务吗?

测试环境: GPU实例

测试代码:

import spacy

assert(spacy.__version__ == '3.0.3')
spacy.require_gpu()
texts = load_sample_texts()  # loads 10,000 texts from a file
assert(len(texts) == 10000)

def get_execution_time(nlp, texts, N):
    return timeit.timeit(stmt="[nlp(text) for text in texts]", 
                           globals={'nlp': nlp, 'texts': texts}, number=N) / N


#  load models
nlp_lg_pos = spacy.load('en_core_web_lg', disable=['ner', 'parser'])
nlp_lg_all = spacy.load('en_core_web_lg')
nlp_trf_pos = spacy.load('en_core_web_trf', disable=['ner', 'parser'])
nlp_trf_all = spacy.load('en_core_web_trf')

#  get execution time
print(f'nlp_lg_pos = {get_execution_time(nlp_lg_pos, texts, N=1)}')
print(f'nlp_lg_all = {get_execution_time(nlp_lg_all, texts, N=1)}')
print(f'nlp_trf_pos = {get_execution_time(nlp_trf_pos, texts, N=1)}')
print(f'nlp_trf_all = {get_execution_time(nlp_trf_all, texts, N=1)}')

标签: pythonspacyspacy-transformersspacy-3

解决方案


推荐阅读