我正在编写一个用于计算ngram概率的小型库。
我有一个由arpa文件描述的LM(它的格式很简单:概率ngram backoff_weight):
...
-5.1090264 Hello -0.05108307
-5.1090264 Bob -0.05108307
-3.748848 we -0.38330063
...
-2.5558481 Hello Bob -0.012590006
...
-1.953679 Hello Bob how -0.0022290824
...
-0.58411354 Hello Bob how are -0.0007929117
...
-1.4516809 Hello Bob how are you
...
但我如何正确计算P(we|Hello Bob how are)
?
P(we|Hello Bob how are) = P(we) * BWt(Hello Bob how are) ?
或者这是正确的方法:
P(we|Hello Bob how are) = P(are we) * BWt(Hello Bob how) ?
如果我没有4克(Hello Bob how are)
的退避权重怎么办?
请指出一些计算概率的通用公式或我在哪里可以阅读它,我真的找不到任何好的东西......
答案 0 :(得分:1)
如果LM是这样的
...
\1-grams:
p1 word1 bw1
\2-grams:
p2 word1 word2 bw2
p4 word2 word3 bw4
\3-grams:
p3 word1 word2 word3 bw3
...
如何计算P(word3 | word1, word2)
?
if(exist(word1, word2, word3)):
P(word3 | word1, word2) = p3
return P(word3 | word1, word2)
else if(exist(word1, word2)):
bw(word1, word2) = bw2
P(word3 | word2) = p4
return bw(word1, word2) * P(word3 | word2)
else:
P(word3 | word2) = p4
return P(word3 | word2)
当语料库中没有ngrams时,我们需要退回到低阶ngram。
如果退避权重不存在,则表示退避权重等于1(log10(bw)== 0)