gpt4 book ai didi

python - 如何将整个句子的语言模型得分与句子成分的语言模型得分相关联

转载 作者:行者123 更新时间:2023-12-02 12:10:55 25 4
gpt4 key购买 nike

我用大约 5000 个英语句子/段落训练了 KENLM 语言模型。我想用两个或多个片段查询这个 ARPA 模型,看看它们是否可以连接起来形成一个更长的句子,希望更“符合语法”。下面是我用来获取片段和“句子”的对数分数以及基于十的幂值的 Python 代码。我举了两个例子。显然,第一个例子中的句子比第二个例子中的句子更符合语法。然而,我的问题不是这个,而是如何将整个句子的语言模型分数与句子成分的语言模型分数联系起来。也就是说,该句子在语法上是否优于其组成部分。

import math
import kenlm as kl
model = kl.LanguageModel(r'D:\seg.arpa.bin')
print ('************')
sentence = 'Mr . Yamada was elected Chairperson of'
print(sentence)
p1=model.score(sentence)
p2=math.pow(10,p1)
print(p1)
print(p2)
sentence = 'the Drafting Committee by acclamation .'
print(sentence)
p3=model.score(sentence)
p4=math.pow(10,p3)
print(p3)
print(p4)
sentence = 'Mr . Yamada was elected Chairperson of the Drafting Committee by acclamation .'
print(sentence)
p5=model.score(sentence)
p6=math.pow(10,p5)
print(p5)
print(p6)
print ('-------------')
sentence = 'Cases cited in the present volume ix'
print(sentence)
p1=model.score(sentence)
p2=math.pow(10,p1)
print(p1)
print(p2)
sentence = 'Multilateral instruments cited in the present volume xiii'
print(sentence)
p3=model.score(sentence)
p4=math.pow(10,p3)
print(p3)
print(p4)
sentence = 'Cases cited in the present volume ix Multilateral instruments cited in the present volume xiii'
print(sentence)
p5=model.score(sentence)
p6=math.pow(10,p5)
print(p5)
print(p6)
  • ************ 先生。山田就任会长-34.07065582288.49853715087e-35 起草委员会以鼓掌方式通过。-28.37451934814.22163470933e-29 先生山田以鼓掌方式当选为起草委员会主席。-55.51284408573.07012398337e-56------------- 本卷引用的案例-27.73532485961.83939558773e-28 本卷 xiii 中引用的多边文书-34.45236206053.52888852435e-35 本卷 ix 中引用的案例 本卷 xiii 中引用的多边文书-60.70752334591.9609957573e-61

最佳答案

使用

list(model.full_scores(sent))

返回句子成分的详细信息,即单词。

这会返回一个列表并迭代该列表以访问每个单词的详细信息。每个列表项包含

The above returns log-probability, ngram-length and whether the word is OOV (out-of-vocabulary) for each word in the sentence.

关于python - 如何将整个句子的语言模型得分与句子成分的语言模型得分相关联,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49605248/

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