def test_bigram_smooth_lm():
intrp_lambda = 0.1
a = 1.
b = 2.
K = 5.
lm = BigramSmoothLM(intrp_lambda, a, b, K)
data = [
[1, 1, 3, 4, 0],
[4, 4],
[1, 0, 2, 2, 2, 2, 3, 1],
[3, 3, 1]
]
lm.counts_from_data(data)
npt.assert_almost_equal(
lm.prob_i_given_j(1, 3),
intrp_lambda * lm.prob_i(1) + (1 - intrp_lambda) * (2. + b/K) / (4 + b)
)
npt.assert_almost_equal(lm.prob_i(1), (5. + a/K) / (18 + a))
评论列表
文章目录