Stanford Stanza 有时会将一个句子分成两个句子

问题描述 投票:0回答:1

我正在使用节 1.6.1。我一直在尝试 Stanza 的选区解析器。

在某些情况下,它将一个句子分成 2 个 Sentence 对象。例如,采用这句话:Pull up Field with low precision.

它在内部将其分成 2 个句子(上拉低精度字段),因此选区解析器输出为 2 棵树(每个句子一棵)。

将上面句子中的“Field”更改为小写,使 Stanza 将其视为一个句子,并且我得到一个树表示(如预期)作为选区输出。

除了转换为小写等字符串操作技术之外,是否有某种方法可以让 Stanza 将其视为一个句子? 或者我可以使用不区分大小写的模型吗?

python nlp stanford-nlp
1个回答
0
投票

该问题似乎与旧版本特别相关,包括其他用户报告的

1.6.1
[1][2]。我可以通过以下方式重现您的问题:

doc = nlp("Pull up Field with low precision") 
for i, sentence in enumerate(doc.sentences):
    print(f'====== Sentence {i+1} tokens =======')
    print(*[f'id: {token.id}\ttext: {token.text}' for token in sentence.tokens], sep='\n')

打印:

====== Sentence 1 tokens =======
id: (1,)    text: Pull
id: (2,)    text: up
====== Sentence 2 tokens =======
id: (1,)    text: Field
id: (2,)    text: with
id: (3,)    text: low
id: (4,)    text: precision

解决方案: 然而,库1.7.0的新

release
似乎没有这个问题。只需安装:

pip install stanza # should install v1.7.0

然后通过以下方式进行测试:

import stanza
stanza.download('en') # to download the default English language package
nlp = stanza.Pipeline('en') # to initialize the pipeline

doc = nlp("Pull up Field with low precision.")
for i, sentence in enumerate(doc.sentences):
    print(f'====== Sentence {i+1} tokens =======')
    print(*[f'id: {token.id}\ttext: {token.text}' for token in sentence.tokens], sep='\n')

打印出:

====== Sentence 1 tokens =======
id: (1,)    text: Pull
id: (2,)    text: up
id: (3,)    text: Field
id: (4,)    text: with
id: (5,)    text: low
id: (6,)    text: precision
id: (7,)    text: .

您还可以在 stanza.run 可视化选区解析

© www.soinside.com 2019 - 2024. All rights reserved.