test_bigram_lms.py 文件源码

python
阅读 18 收藏 0 点赞 0 评论 0

项目:segmentalist 作者: kamperh 项目源码 文件源码
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))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号