本文整理汇总了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)