【发布时间】:2020-11-13 20:11:27
【问题描述】:
我正在尝试在 spaCy 中编写一个自定义句子分段器,它将整个文档作为一个句子返回。
我使用here 中的代码编写了一个自定义管道组件。
但我无法让它工作,因为它不会更改句子边界以将整个文档视为一个句子,而是会引发两个不同的错误。
如果我创建一个空白语言实例并且只将我的自定义组件添加到管道中,我会收到以下错误:
ValueError: Sentence boundary detection requires the dependency parse, which requires a statistical model to be installed and loaded.
如果我将解析器组件添加到管道中
nlp = spacy.blank('es')
parser = nlp.create_pipe('parser')
nlp.add_pipe(parser, last=True)
def custom_sbd(doc):
print("EXECUTING SBD!!!!!!!!!!!!!!!!!!!!")
doc[0].sent_start = True
for i in range(1, len(doc)):
doc[i].sent_start = False
return doc
nlp.begin_training()
nlp.add_pipe(custom_sbd, first=True)
我得到同样的错误。
如果我改变它首先解析的顺序,然后改变句子边界,错误就会变成
Refusing to write to token.sent_start if its document is parsed, because this may cause inconsistent state.
因此,如果它抛出一个需要依赖解析的错误,如果它不存在或者它在自定义句子边界检测之后执行,并且在首先执行依赖解析时出现不同的错误,那么合适的方法是什么?
谢谢!
【问题讨论】: