添加句号“.”在使用 spacy NLP 执行摘要时的每个句子行之后
Adding a full stop '.' after every sentence line while using spacy NLP to perform summarisation
我想在执行文本清理后从清理后的文本中得到的每一行句子后添加一个句号,以便使用 heapq 或 gensim 执行摘要。如果我没有句号,heapq 或 Gensim 将无法理解不同的句子,并且会将所有句子视为一个句子。我正在使用以下代码:
import en_core_web_sm
nlp = en_core_web_sm.load()
text = nlp(str1_clean_summary)
for sent in text.sents:
print(sent.string.strip())
str1_clean_summary 看起来像这样:
many price increase options
still believe us need prove consistently
aim please delay end displeasingich
responds wuickly
这让我在不同的行中得到句子,但我需要在每个句子后添加一个句号,以便将它们分开处理。
如果您不想 fiddle 使用跨度索引,我建议您在每个句子 运行 spacy 之前添加最后一个点。
例如:
import en_core_web_sm
sents = "many price increase options\nstill believe us need prove consistently\naim please delay end displeasingich\nresponds wuickly\n"
sents = sents.replace('\n', '.\n')
nlp = en_core_web_sm.load()
text = nlp(sents)
for sent in text.sents:
sentence = sent
print(sentence)
输出:
many price increase options.
still believe us need prove consistently.
aim please delay end displeasingich.
responds wuickly.
否则,您将不得不使用标记定位(跨度是标记列表,并且由于组织词汇表和其他资源的内部方式很宽敞,跨度中的标记是指向标记字典的“指针”。要添加一个新的令牌,你必须向前移动每个跨度的尾部,这比仅仅玩一个简单的替换更糟糕。)
阅读更多 here and here.
我想在执行文本清理后从清理后的文本中得到的每一行句子后添加一个句号,以便使用 heapq 或 gensim 执行摘要。如果我没有句号,heapq 或 Gensim 将无法理解不同的句子,并且会将所有句子视为一个句子。我正在使用以下代码:
import en_core_web_sm
nlp = en_core_web_sm.load()
text = nlp(str1_clean_summary)
for sent in text.sents:
print(sent.string.strip())
str1_clean_summary 看起来像这样:
many price increase options
still believe us need prove consistently
aim please delay end displeasingich
responds wuickly
这让我在不同的行中得到句子,但我需要在每个句子后添加一个句号,以便将它们分开处理。
如果您不想 fiddle 使用跨度索引,我建议您在每个句子 运行 spacy 之前添加最后一个点。
例如:
import en_core_web_sm
sents = "many price increase options\nstill believe us need prove consistently\naim please delay end displeasingich\nresponds wuickly\n"
sents = sents.replace('\n', '.\n')
nlp = en_core_web_sm.load()
text = nlp(sents)
for sent in text.sents:
sentence = sent
print(sentence)
输出:
many price increase options.
still believe us need prove consistently.
aim please delay end displeasingich.
responds wuickly.
否则,您将不得不使用标记定位(跨度是标记列表,并且由于组织词汇表和其他资源的内部方式很宽敞,跨度中的标记是指向标记字典的“指针”。要添加一个新的令牌,你必须向前移动每个跨度的尾部,这比仅仅玩一个简单的替换更糟糕。) 阅读更多 here and here.