python - 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
解决方案
你是怎么想出那个代码的?加载的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'
有关更多详细信息,请参阅此处的文档。
推荐阅读
- python - 在不使用 Kmeans 导入的情况下获取 KMeans 轮廓平均分数
- d3.js - D3 sankey 图中更亮的节点颜色
- javascript - 根据嵌套数组中的一些值查找两个数组之间的差异
- windows - 如何在 Visual Studio 2019 集成终端中使用 git 命令
- python - 当我使主窗口全屏时如何使框架扩展?
- python - 如何从 .csv Python 数据框中的列中打印单个字符串单元格?
- javascript - 项目超过限制时引导导航栏折叠菜单
- php - 调用 github api 不会返回任何东西
- embedded - 是否可以对 STM32 设备进行无线编程?
- python - 如何在不丢失数据的情况下通过网络在 python 中发送文件?