我只是想按照Spacy 的文档将文档的子部分标记为跨度
import spacy
nlp = spacy.load('en_core_web_sm')
sentence = "The car with the white wheels was being confiscated by the police when the owner returns from robbing a bank"
doc = nlp(sentence)
doc.spans['remove_parts'] = [doc[2:6], doc[9:12]]
doc.spans['remove_parts']
这看起来很简单,但是 Spacy 返回以下错误(并将其归因于第二行,即赋值):
AttributeError: 'spacy.tokens.doc.Doc' object has no attribute 'spans'
我根本看不到发生了什么。这是 Spacy 的错误吗?spans
即使它仍在文档中,它是否已被删除?如果不是,我错过了什么?
PD:我正在为此使用 Colab。并spacy.info
显示:
spaCy version 2.2.4
Location /usr/local/lib/python3.7/dist-packages/spacy
Platform Linux-4.19.112+-x86_64-with-Ubuntu-18.04-bionic
Python version 3.7.10
Models en