Nlp 用于名词快速检测的自然语言处理
我有很长的文本,需要从中提取名词。我使用Nlp 用于名词快速检测的自然语言处理,nlp,spacy,Nlp,Spacy,我有很长的文本,需要从中提取名词。我使用spaCy作为 nlp = spacy.load("en_core_web_lg") # for better name entity detection doc = nlp(text) for token in doc: if token.tag_=='NN' or token.tag_=='NNP': # store token.lemma_ for ent in doc.ents: # store ent.text
spaCy
作为
nlp = spacy.load("en_core_web_lg") # for better name entity detection
doc = nlp(text)
for token in doc:
if token.tag_=='NN' or token.tag_=='NNP':
# store token.lemma_
for ent in doc.ents:
# store ent.text
但是,它非常慢,因为spaCy
会进行完整的分析,我不需要这样做
我可以加快spaCy的速度来执行此特定任务吗?您可以通过禁用不需要的预排水管道来加快spaCy的速度:
with nlp.disable_pipes("tagger", "parser"):
# your code
(请注意,如果仍要访问token.tag
,则不能禁用tagger
)
或者您甚至可以完全避免加载这些组件:
nlp = spacy.load("en_core_web_lg", disable=["tagger", "parser"])
即使只禁用解析器
,也肯定会提高速度
有关详细信息,请参阅