首页 > 解决方案 > 为什么 Kenlm lm 模型不断为不同的单词返回相同的分数?

问题描述

为什么 kenlm 模型返回相同的值?我也尝试过使用 4-gram arpa 文件。同样的问题。

import kenlm
model = kenlm.mode('lm/test.arpa') # unigram model. 

print( [f'{x[0]:.2f}, {x[1]}, {x[2]}' for x in model.full_scores('this is a sentence', bos=False, eos=False)])
print( [f'{x[0]:.2f}, {x[1]}, {x[2]}' for x in model.full_scores('this is a sentence1', bos=False, eos=False)])
print( [f'{x[0]:.2f}, {x[1]}, {x[2]}' for x in model.full_scores('this is a devil', bos=False, eos=False)])

结果:

['-2.00, 1, True', '-21.69, 1, False', '-1.59, 1, False', '-2.69, 1, True']

['-2.00, 1, True', '-21.69, 1, False', '-1.59, 1, False', '-2.69, 1, True']

['-2.00, 1, True', '-21.69, 1, False', '-1.59, 1, False', '-2.69, 1, True']

标签: lmkenlm

解决方案


我自己想出来的。

输出中的 True/False 告诉您一个单词是否 OOV(超出词汇表)。KenLM 模型为这些词分配一个固定的概率。在问题的示例中,所有最后的单词都是 OOV。


推荐阅读