Exemple #1
0
    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)
Exemple #2
0
    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)