kenlm python模块详解

kenlm python模块详解


1.导入模型

import kenlm
model= kenlm.LanguageModel("a.bin")
a.bin 是训练的统计语言模型
  • 1
  • 2
  • 3

2.打分

1. ** model.score()函数**

score=model.score(sentence, bos=True, eos=True)
sentence:如果句子是汉语,那么需要将句子分词
bos,eos:句子的开头和结尾加上标记
model.score():是log(p(sentence)),p(sentence)是0-1之间的数值,取对数(底数是10)之后,为负数,p(sentence)越大越好,取对数之后仍是越大越好
  • 1
  • 2
  • 3
  • 4

2. ** model.full_scores()函数**

total=0.0
for score, _, _ in model.full_scores(sentence,bos=True, eos=True):
  	total+=score
total的结果和model.score()得分是相同的
total==model.score(sentence,bos=True, eos=True)
sentence:同上
bos,eos:
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值