gpt4 book ai didi

python - ViterbiParser 和 ChartParser 在 NLTK 中为 PCFG 返回 None

转载 作者:太空宇宙 更新时间:2023-11-03 15:07:53 24 4
gpt4 key购买 nike

我正在尝试使用 ViterbiParser 和 ChartParser 来解析句子“Birds Fly”。跟踪进程,看起来应该可以工作,但总是返回 None

这是痕迹。(维特比):

Inserting tokens into the most likely constituents table...
Insert: |=.| Birds
Insert: |.=| fly
Finding the most likely constituents spanning 1 text elements...
Insert: |=.| NNS -> 'Birds' [1.0]
Insert: |=.| NP -> NNS [0.206897]
Insert: |.=| VB -> 'fly' [1.0]
Insert: |.=| VP -> VB [0.21875]
Finding the most likely constituents spanning 2 text elements...
Insert: |==| S -> NP VP [1.0]

图表解析器:

|.     Birds     .      fly      .|
Leaf Init Rule:
|[---------------] .| [0:1] 'Birds'
|. [---------------]| [1:2] 'fly'
Bottom Up Predict Combine Rule:
|[---------------] .| [0:1] NNS -> 'Birds' *
Bottom Up Predict Combine Rule:
|[---------------] .| [0:1] NP -> NNS *
Bottom Up Predict Combine Rule:
|[---------------> .| [0:1] NP -> NP * NP
|[---------------> .| [0:1] S -> NP * VP
Bottom Up Predict Combine Rule:
|. [---------------]| [1:2] VB -> 'fly' *
Bottom Up Predict Combine Rule:
|. [---------------]| [1:2] VP -> VB *
|. [--------------->| [1:2] VP -> VB * VP
|. [--------------->| [1:2] VP -> VB * ADJP
|. [--------------->| [1:2] VP -> VB * PP
Bottom Up Predict Combine Rule:
|. [--------------->| [1:2] VP -> VP * PP
|. [--------------->| [1:2] VP -> VP * NP
|. [--------------->| [1:2] VP -> VP * VP
Single Edge Fundamental Rule:
|[===============================]| [0:2] S -> NP VP *

两个解析器似乎都正确构建了句子,但仍然返回 None。这是怎么回事?

最佳答案

经过几个小时的研究,我确实发现了问题。我正在使用 PCFG 语法。语法中加载的第一条规则需要将左侧设置为语法的开始状态。没有明确的方法来覆盖它。我更改了语法规则的顺序,现在可以正常工作了。

问题的确切原因...PCFG 正在尝试提出一种规则安排,以创建一棵以“起始状态”为根的树。在我的例子中,它是“S”(代表句子),我加载的规则是乱序的,所以它试图找到一个名词短语,因此无法想出一棵有效的树。

关于python - ViterbiParser 和 ChartParser 在 NLTK 中为 PCFG 返回 None,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44478126/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com