NLTK句子分词器在句子中存在"例如"或"即"时,分词不正确,

33qvvth1  于 2个月前  发布在  其他
关注(0)|答案(5)|浏览(29)

如何解决这个问题?

要解决这个问题,您可以使用句子标记器(如NLTK库中的punkt模块)对文本进行分句。以下是一个使用Python和NLTK库的示例:

import nltk
from nltk.tokenize import sent_tokenize

text = "The first approach, single-molecule simulation, taken by the StochSim simulator, tracks individual molecules and their state (e.g., what other molecules they are bound to) so that only the complexes formed at any given time are enumerated (and not all possible complexes) [11]."
sentences = sent_tokenize(text)
print(sentences)

这将输出以下结果:

['The first approach, single-molecule simulation, taken by the StochSim simulator, tracks individual molecules and their state (e.g., what other molecules they are bound to) so that only the complexes formed at any given time are enumerated (and not all possible complexes) [11].']

这样,您就可以得到一个包含原始句子的列表,而不是被分割成两个句子。

a11xaf1n

a11xaf1n1#

这与描述的不符,训练算法实际上会捕捉到类似的例子,例如如果它们后面跟着一个逗号。然而,没有逗号的情况下确实会出现错误的行为。看起来像是用于训练预打包的英语pickle模型的宾州树库语料库实际上并不包含例如或即使用必要的频率来识别。
如果这个诊断是准确的,我想到了几个可能的解决方案:

  1. 在不同的或扩展的语料库上重新训练
  2. 添加一个已知缩写列表,其中包括例如和即
yhxst69z

yhxst69z2#

我认为这个punkt模型是在维基百科上训练的,而不是在PTB上。我认为将这些作为已知缩写添加到模型中是可以的(在abbrev_types中)。但是我不确定nltk是如何更新它的模型的。

quhf5bfb

quhf5bfb3#

README中提到的分词器使用的是英文。pickle文件是在PTB上训练的,样本中的5%数据集不包含"例如"和"即"这样的示例,所以这是有道理的。我从English.pickle模型中提取了abbrev_types集合(如下所示),但它们似乎不存在。
我可以手动将这些添加到English.pickle文件中(在本地测试过并可以正常工作),但我不知道如何部署一个新的english.pickle模型。

z4iuyo4d

z4iuyo4d4#

好的。虽然那是很久以前的事了,但我们可能选择在PTB上进行训练,因为英语维基百科使用很少的缩写,因此可能对训练一个时期消歧器没有用。

yzuktlbb

yzuktlbb5#

我也遇到了错误的分割,比如我的句子是

Similarly, while Version A doesn’t relate to anything in particular, Version B immediately suggests that the prior paragraph addresses the biological pathway (i.e. etiology) of a disease and that the new paragraph will bolster the emerging hypothesis with a different kind of evidence. As a reader, it’s easy to keep track of how the paragraph about cells and chemicals and such relates to the paragraph about populations in different places

基本上这个文本只包含两个句子,但是 PunktSentenceTokenizer 说有三个句子。

相关问题