问题:
spaCy的依赖符号“compound”和“case”报错为“未定义”,而“nsubj”被识别,尽管所有三个依赖符号在图形输出中都显示为活动状态。难道“from spacy.symbols import *”不应该像对“nsubj”等进行的定义那样定义所有符号吗?
spaCy文档
https://spacy.io/api/annotation#dependency-parsing 显示英语和通用标签依存关系集中都定义了“case”和“compound”。
环境
Windows 10;python 3.7.1;spaCy 2.3.1;使用Anaconda3环境;使用conda安装的包;在Jupyter中运行代码。在下面的代码后列出了所有安装的软件包。
代码示例
import spacy
from spacy import displacy
from spacy.symbols import *
nlp = spacy.load("en_core_web_sm") # loaded the small model but also fails with the large model
doc = nlp("Autonomous family cars and people's drones are the future.")
displacy.render(doc, style='dep') # draw a graph; shows dependencies assigned including 'compound' and 'case'
for t in doc:
if t.dep == nsubj: # dependency 'nsubj' IS recognized
print(f"Found nsub token")
if t.dep == compound: # dependency 'compound' is NOT recognized
print(f"Found compound token")
if t.dep == case: # dependency 'case' is NOT recognized
print(f"Found case token")