【发布时间】:2019-10-18 09:01:17
【问题描述】:
我想把文本分成句子。
查看堆栈溢出我发现:
使用 NLTK
from nltk.tokenize import sent_tokenize
text="""Hello Mr. Smith, how are you doing today? The weathe is great, and city is awesome. The sky is pinkish-blue. You shouldn't eat cardboard"""
tokenized_text=sent_tokenize(text)
print(tokenized_text)
宽敞
from spacy.lang.en import English # updated
raw_text = 'Hello, world. Here are two sentences.'
nlp = English()
nlp.add_pipe(nlp.create_pipe('sentencizer')) # updated
doc = nlp(raw_text)
sentences = [sent.string.strip() for sent in doc.sents]
问题是 spacy 在后台必须使用所谓的 create_pipe 以不同方式执行此操作。 句子对于训练你自己的 NLP 词嵌入很重要。 spaCy 不直接包含开箱即用的句子标记器应该是有原因的。
谢谢。
注意:请注意,简单的 .split(.) 不起作用,文本中有几个十进制数字和其他包含“.”的标记
【问题讨论】:
-
我想我明白你的意思了。请记住,spaCy 是一个简单的框架,首先为初学者或通才从业者提供简单的 NLP。它可以自定义,但默认情况下,如果您使用更专业的解决方案,您必须进行一些调整 - 您甚至可以为它训练模型!
标签: python nlp nltk spacy sentence