当前位置: 首页>>代码示例>>Python>>正文


Python DialogueActConfusionNetwork.get_best_da_hyp方法代码示例

本文整理汇总了Python中alex.components.slu.da.DialogueActConfusionNetwork.get_best_da_hyp方法的典型用法代码示例。如果您正苦于以下问题:Python DialogueActConfusionNetwork.get_best_da_hyp方法的具体用法?Python DialogueActConfusionNetwork.get_best_da_hyp怎么用?Python DialogueActConfusionNetwork.get_best_da_hyp使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在alex.components.slu.da.DialogueActConfusionNetwork的用法示例。


在下文中一共展示了DialogueActConfusionNetwork.get_best_da_hyp方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_get_best_da_hyp

# 需要导入模块: from alex.components.slu.da import DialogueActConfusionNetwork [as 别名]
# 或者: from alex.components.slu.da.DialogueActConfusionNetwork import get_best_da_hyp [as 别名]
    def test_get_best_da_hyp(self):
        # Test case when only one dai should be included in the hyp.
        dacn = DialogueActConfusionNetwork()
        dacn.add(0.2, DialogueActItem(dai='inform(food=chinese)'))
        dacn.add(0.7, DialogueActItem(dai='inform(food=czech)'))
        dacn.add(0.1, DialogueActItem(dai='inform(food=russian)'))

        best_hyp = dacn.get_best_da_hyp(use_log=False)
        self.assertAlmostEqual(best_hyp.prob, 0.8 * 0.7 * 0.9)
        self.assertEqual(len(best_hyp.da), 1)

        # Test case when 2 dais should be included in the hyp.
        dacn = DialogueActConfusionNetwork()
        dacn.add(0.1, DialogueActItem(dai='inform(food=chinese)'))
        dacn.add(0.7, DialogueActItem(dai='inform(food=czech)'))
        dacn.add(0.9, DialogueActItem(dai='inform(food=russian)'))

        best_hyp = dacn.get_best_da_hyp(use_log=False)
        self.assertAlmostEqual(best_hyp.prob, 0.9 * 0.7 * 0.9)
        self.assertEqual(len(best_hyp.da), 2)

        # Test the case with logarithms.
        dacn = DialogueActConfusionNetwork()
        dacn.add(0.1, DialogueActItem(dai='inform(food=chinese)'))
        dacn.add(0.7, DialogueActItem(dai='inform(food=czech)'))
        dacn.add(0.9, DialogueActItem(dai='inform(food=russian)'))

        best_hyp = dacn.get_best_da_hyp(use_log=True)
        self.assertAlmostEqual(best_hyp.prob, math.log(0.9 * 0.7 * 0.9))
        self.assertEqual(len(best_hyp.da), 2)

        # Test the case with manual thresholds.
        dacn = DialogueActConfusionNetwork()
        dacn.add(0.1, DialogueActItem(dai='inform(food=chinese)'))
        dacn.add(0.7, DialogueActItem(dai='inform(food=czech)'))
        dacn.add(0.9, DialogueActItem(dai='inform(food=russian)'))

        best_hyp = dacn.get_best_da_hyp(
            use_log=True, threshold=0.1, thresholds={
                DialogueActItem(dai='inform(food=chinese)'): 0.5,
                DialogueActItem(dai='inform(food=czech)'): 0.9,
                DialogueActItem(dai='inform(food=russian)'): 0.5
            })
        # Test food=czech should NOT be included.
        self.assertAlmostEqual(best_hyp.prob, math.log(0.9 * 0.3 * 0.9))
        self.assertEqual(len(best_hyp.da), 1)
        self.assertTrue(not DialogueActItem(dai='inform(food=czech)') in best_hyp.da)

        dacn = DialogueActConfusionNetwork()
        dacn.add(0.1, DialogueActItem(dai='inform(food=chinese)'))
        dacn.add(0.7, DialogueActItem(dai='inform(food=czech)'))
        dacn.add(0.9, DialogueActItem(dai='inform(food=russian)'))

        best_hyp = dacn.get_best_da_hyp(
            use_log=True, threshold=0.1, thresholds={
                DialogueActItem(dai='inform(food=chinese)'): 0.5,
                DialogueActItem(dai='inform(food=czech)'): 0.5,
                DialogueActItem(dai='inform(food=russian)'): 0.5
            })
        # Test food=czech should be included.
        self.assertAlmostEqual(best_hyp.prob, math.log(0.9 * 0.7 * 0.9))
        self.assertEqual(len(best_hyp.da), 2)
        self.assertTrue(DialogueActItem(dai='inform(food=czech)') in best_hyp.da)
开发者ID:UFAL-DSG,项目名称:alex,代码行数:65,代码来源:test_da.py


注:本文中的alex.components.slu.da.DialogueActConfusionNetwork.get_best_da_hyp方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。