首页 > 解决方案 > AttributeError: 'English' 对象没有属性 'noun_chunks

问题描述

我正在尝试使用 spacy noun_chunks,但它会引发错误。我下载了模型 python -m spacy download en_core_web_sm

AttributeError: 'English' object has no attribute 'noun_chunks'

NLP = spacy.load('en_core_web_sm')
NOUN_CHUNKS = NLP.noun_chunks

标签: pythonpython-3.xspacy

解决方案


你是怎么想出那个代码的?加载的nlp处理对象没有属性noun_chunks——相反,您希望访问已处理文档的名词块:

nlp = spacy.load("en_core_web_sm")  # load the English model
doc = nlp("There is a big dog.")    # process a text and create a Doc object
for chunk in doc.noun_chunks:       # iterate over the noun chunks in the Doc
   print(chunk.text)
# 'a big dog'

有关更多详细信息,请参阅此处的文档


推荐阅读