NLP之语言模型

N-grams 语言模型

P(W) = P(W1,W2,W3...Wn)
        = P(W5|W1,W2,W3,W4)
计算给定句子的概率,主要说明了这些词语结合的如何
上面的计算,依赖Chain Rule of Probability.
主要是条件概率

P(A|B) = P(A,B)/P(B)

P(A,B) = P(A)P(A|B)

P(A,B,C,D)=P(A)P(B|A)P(C|A,B)P(D|A,B,C)

更一般:

P(X1,X2,X3,X4,...Xn) = P(X1)P(X1|X2)P(X3|X1,X2)P(X4|PX1,PX2,PX3)...P(Xn|PX1,PX2,PX3...PXn-1)

P(W1,W2...Wn) = {连乘i}P(Wi|W1,W2...Wi-1)

P(the | its water is so transparent that) =
Count(its water is so transparent that the) / Count(its water is so transparent that) ----无法这么计算,句子太多了

所以,用Markov 假设:
P(the |tis water is so transparent that) = P(the |that)  --二元模型
= P(the|transparent that)                --三元模型

所以,更一般的表达式():
P(Wi|W1,W2...Wi-1) ~ P(Wi|Wi-k...Wi-1)

P(W1,W2...Wn) ~ {连乘i}P(Wi|Wi-k..Wi-1)

简单的模型
P(W1,W2...Wn) ~ {连乘i}P(Wi)
二元模型
P(Wi|W1,W2...Wi-1) ~ P(Wi|Wi-1)

虽然有可能句子的距离很长,不过通常三元、四元模型就能很好的解决

计算

P(Wi|Wi-1) = c(Wi-1,Wi) /c(Wi-1)
例如:

P(<s> I want english food </s>) =
P(I|<s>)
* P(want|I)
* P(english|want)
* P(food|english)
* P(</s>|food)
=0.000031

困惑度来评判模型的好坏

PP = [p()]^-(1/n)
更低的困惑度,更好的语言模型

 

转载于:https://www.cnblogs.com/fall12/p/7802559.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值