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


Python DialogueActConfusionNetwork.sort方法代码示例

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


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

示例1: test_merge

# 需要导入模块: from alex.components.slu.da import DialogueActConfusionNetwork [as 别名]
# 或者: from alex.components.slu.da.DialogueActConfusionNetwork import sort [as 别名]
    def test_merge(self):
        dacn = DialogueActConfusionNetwork()
        dacn.add(0.05, DialogueActItem(dai='inform(food=chinese)'))
        dacn.add(0.9, DialogueActItem(dai='inform(food=czech)'))
        dacn.add(0.00005, DialogueActItem(dai='inform(food=russian)'))

        dacn.merge(dacn, combine='max')

        # Russian food should be pruned.
        dacn.sort().prune()
        self.assertTrue(not DialogueActItem(dai='inform(food=russian)') in dacn)
开发者ID:UFAL-DSG,项目名称:alex,代码行数:13,代码来源:test_da.py

示例2: test_sort

# 需要导入模块: from alex.components.slu.da import DialogueActConfusionNetwork [as 别名]
# 或者: from alex.components.slu.da.DialogueActConfusionNetwork import sort [as 别名]
    def test_sort(self):
        dacn = DialogueActConfusionNetwork()
        dacn.add(0.05, DialogueActItem(dai='inform(food=chinese)'))
        dacn.add(1.0, DialogueActItem(dai='inform(food=czech)'))
        dacn.add(0.00005, DialogueActItem(dai='inform(food=russian)'))

        dacn.sort()

        cn = list(dacn)
        self.assertEqual(cn[0][1], DialogueActItem(dai='inform(food=czech)'))
        self.assertEqual(cn[1][1], DialogueActItem(dai='inform(food=chinese)'))
        self.assertEqual(cn[2][1], DialogueActItem(dai='inform(food=russian)'))
开发者ID:UFAL-DSG,项目名称:alex,代码行数:14,代码来源:test_da.py

示例3: parse_nblist

# 需要导入模块: from alex.components.slu.da import DialogueActConfusionNetwork [as 别名]
# 或者: from alex.components.slu.da.DialogueActConfusionNetwork import sort [as 别名]
    def parse_nblist(self, obs, *args, **kwargs):
        """
        Parses an observation featuring an utterance n-best list using the
        parse_1_best method.

        Arguments:
            obs -- a dictionary of observations
                :: observation type -> observed value
                where observation type is one of values for `obs_type' used in
                `ft_props', and observed value is the corresponding observed
                value for the input
            args -- further positional arguments that should be passed to the
                `parse_1_best' method call
            kwargs -- further keyword arguments that should be passed to the
                `parse_1_best' method call

        """
        nblist = obs['utt_nbl']
        if len(nblist) == 0:
            return DialogueActConfusionNetwork()

        obs_wo_nblist = copy.deepcopy(obs)
        del obs_wo_nblist['utt_nbl']
        dacn_list = []
        for prob, utt in nblist:
            if "_other_" == utt:
                dacn = DialogueActConfusionNetwork()
                dacn.add(1.0, DialogueActItem("other"))
            elif "_silence_" == utt:
                dacn = DialogueActConfusionNetwork()
                dacn.add(1.0, DialogueActItem("silence"))
            else:
                obs_wo_nblist['utt'] = utt
                dacn = self.parse_1_best(obs_wo_nblist, *args, **kwargs)

            dacn_list.append((prob, dacn))

        dacn = merge_slu_confnets(dacn_list)
        dacn.prune()
        dacn.sort()

        return dacn
开发者ID:AoJ,项目名称:alex,代码行数:44,代码来源:base.py

示例4: parse_X

# 需要导入模块: from alex.components.slu.da import DialogueActConfusionNetwork [as 别名]
# 或者: from alex.components.slu.da.DialogueActConfusionNetwork import sort [as 别名]
    def parse_X(self, utterance, verbose=False):
        if verbose:
            print '='*120
            print 'Parsing X'
            print '-'*120
            print unicode(utterance)

        if self.preprocessing:
            utterance = self.preprocessing.normalise(utterance)
            utterance_fvcs = self.get_fvc(utterance)

        if verbose:
            print unicode(utterance)
            print unicode(utterance_fvcs)


        da_confnet = DialogueActConfusionNetwork()
        for clser in self.trained_classifiers:
            if verbose:
                print "Using classifier: ", unicode(clser)

            if self.parsed_classifiers[clser].value and self.parsed_classifiers[clser].value.startswith('CL_'):
                # process abstracted classifiers

                for f, v, c in utterance_fvcs:
                    cc = "CL_" + c.upper()

                    if self.parsed_classifiers[clser].value == cc:
                        #print clser, f, v, c

                        classifiers_features = self.get_features(utterance, (f, v, cc), utterance_fvcs)
                        classifiers_inputs = np.zeros((1, len(self.classifiers_features_mapping[clser])))
                        classifiers_inputs[0] = classifiers_features.get_feature_vector(self.classifiers_features_mapping[clser])

                        #if verbose:
                        #    print classifiers_features
                        #    print self.classifiers_features_mapping[clser]

                        p = self.trained_classifiers[clser].predict_proba(classifiers_inputs)

                        if verbose:
                            print '  Probability:', p

                        dai = DialogueActItem(self.parsed_classifiers[clser].dat, self.parsed_classifiers[clser].name, v)
                        da_confnet.add_merge(p[0][1], dai, combine='max')
            else:
                # process concrete classifiers
                classifiers_features = self.get_features(utterance, (None, None, None), utterance_fvcs)
                classifiers_inputs = np.zeros((1, len(self.classifiers_features_mapping[clser])))
                classifiers_inputs[0] = classifiers_features.get_feature_vector(self.classifiers_features_mapping[clser])

                #if verbose:
                #    print classifiers_features
                #    print self.classifiers_features_mapping[clser]

                p = self.trained_classifiers[clser].predict_proba(classifiers_inputs)

                if verbose:
                    print '  Probability:', p

                dai = self.parsed_classifiers[clser]
                da_confnet.add_merge(p[0][1], dai, combine='max')

        da_confnet.sort().prune()

        return da_confnet
开发者ID:UFAL-DSG,项目名称:alex,代码行数:68,代码来源:dailrclassifier.py

示例5: test_session_logger

# 需要导入模块: from alex.components.slu.da import DialogueActConfusionNetwork [as 别名]
# 或者: from alex.components.slu.da.DialogueActConfusionNetwork import sort [as 别名]
    def test_session_logger(self):
        cfg = Config.load_configs(config=CONFIG_DICT, use_default=False)

        sl = SessionLogger()

        # test 3 calls at once
        for i in range(3):
            sess_dir = "./%d" % i
            if not os.path.isdir(sess_dir):
                os.mkdir(sess_dir)
            sl.session_start(sess_dir)
            sl.config('config = ' + unicode(cfg))
            sl.header(cfg['Logging']["system_name"], cfg['Logging']["version"])
            sl.input_source("voip")

            sl.dialogue_rec_start(None, "both_complete_dialogue.wav")
            sl.dialogue_rec_start("system", "system_complete_dialogue.wav")
            sl.dialogue_rec_start("user", "user_complete_dialogue.wav")
            sl.dialogue_rec_end("both_complete_dialogue.wav")
            sl.dialogue_rec_end("system_complete_dialogue.wav")
            sl.dialogue_rec_end("user_complete_dialogue.wav")

            sl.turn("system")
            sl.dialogue_act("system", "hello()")
            sl.text("system", "Hello.")
            sl.rec_start("system", "system1.wav")
            sl.rec_end("system1.wav")

            sl.turn("user")
            sl.rec_start("user", "user1.wav")
            sl.rec_end("user1.wav")

            A1, A2, A3 = 0.90, 0.05, 0.05
            B1, B2, B3 = 0.70, 0.20, 0.10
            C1, C2, C3 = 0.80, 0.10, 0.10

            asr_confnet = UtteranceConfusionNetwork()
            asr_confnet.add([[A1, "want"], [A2, "has"], [A3, 'ehm']])
            asr_confnet.add([[B1, "Chinese"],  [B2, "English"], [B3, 'cheap']])
            asr_confnet.add([[C1, "restaurant"],  [C2, "pub"],   [C3, 'hotel']])
            asr_confnet.merge()
            asr_confnet.normalise()
            asr_confnet.sort()

            asr_nblist = asr_confnet.get_utterance_nblist()

            sl.asr("user", "user1.wav", asr_nblist, asr_confnet)

            slu_confnet = DialogueActConfusionNetwork()
            slu_confnet.add(0.7, DialogueActItem('hello'))
            slu_confnet.add(0.6, DialogueActItem('thankyou'))
            slu_confnet.add(0.4, DialogueActItem('restart'))
            slu_confnet.add(0.1, DialogueActItem('bye'))
            slu_confnet.merge()
            slu_confnet.normalise()
            slu_confnet.sort()

            slu_nblist = slu_confnet.get_da_nblist()

            sl.slu("user", "user1.wav", slu_nblist, slu_confnet)

            sl.turn("system")
            sl.dialogue_act("system", "thankyou()")
            sl.text("system", "Thank you.", cost = 1.0)
            sl.rec_start("system", "system2.wav")
            sl.rec_end("system2.wav")
            sl.barge_in("system", tts_time = True)

            sl.turn("user")
            sl.rec_start("user", "user2.wav")
            sl.rec_end("user2.wav")
            sl.hangup("user")
开发者ID:AoJ,项目名称:alex,代码行数:74,代码来源:test_sessionlogger.py


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