我正在使用Spacy 3版本进行性能测试,以便在生产中调整我的实例大小。我观察到以下情况:
观察结果:
模型名称 | 不带NER的时间 | 带NER的时间 | 备注 |
---|---|---|---|
en_core_web_lg | 4.89秒 | 21.9秒 | NER将原始时间增加了350% |
en_core_web_trf | 43.64秒 | 52.83秒 | 在transformer模型的情况下,为什么带NER和不带NER场景之间没有显着差异?在en_core_web_trf的情况下,是NER在POS标记之后的一个增量任务吗? |
为什么在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)}')