ImportError: cannot import name 'SentenceSegmenter' from 'spacy.pipeline'
空间版本:3.2.1
我知道这个类是针对较早版本的 spacy,但是对于这个版本的 spacy 会有类似的东西吗?
最佳答案
在 spacy 中有几种方法可以进行句子分割。您可以在此处的文档中阅读这些内容:https://spacy.io/usage/linguistic-features#sbd .
此示例按原样从文档中复制,展示了如何根据英语语言模型对句子进行切分。
import spacy
nlp = spacy.load("en_core_web_sm")
doc = nlp("This is a sentence. This is another sentence.")
assert doc.has_annotation("SENT_START")
for sent in doc.sents:
print(sent.text)
您还可以使用基于规则的规则来仅根据语言执行标点符号拆分,就像这样(也来自文档):
import spacy
from spacy.lang.en import English
nlp = English() # just the language with no pipeline
nlp.add_pipe("sentencizer")
doc = nlp("This is a sentence. This is another sentence.")
for sent in doc.sents:
print(sent.text)
这应该适用于 spacy 3.0.5
及更高版本。
关于python-3.x - 尝试从 'SentenceSegmenter'包导入 'spacy.pipeline'时出现导入问题如何解决?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70533739/