Пример #1
0
    def process_nbest_handler( self , param_dict ):
    
        # ----- COMMON TO ALL DMs ----- #                        
        # Fill in action parts away from defaults: 
        feature_set = tbh_compute_text_feature_set.compute_feature_set( param_dict['nbest_list'] \
                                                                            , self.feature_type_list )

        # add feature set to param_dict for storage and other purposes
        param_dict[ 'feature_set' ] = feature_set
        
        # map features to actions
        action_dict = self.determine_action( feature_set )
      
        # --- CUSTOM TO YOUR DM --- #
        # Adjust things based on this action dictionary and send to
        # everyone who might want to use it
        if action_dict['gui_state'] is not None:
            self.system_state = action_dict['gui_state']
        

        # FOR ENVIRONMENTAL CONTROL
        if action_dict['environmental_control_action'] is not None:
            self._process_environmental_control_event( action_dict['environmental_control_action'] )

        # ----- COMMON TO ALL DMs ----- #
        # Send the action_dict to everyone that might need it: common
        # to all dialog managers; you probably don't want to change
        # this part of the code.
        if action_dict['skype_manager_phone_action'] is not None:
            self._process_phone_event( action_dict['skype_manager_phone_action'] )

        param_dict[ 'action_dict' ] = action_dict
        self._processed_nbest_event( param_dict )
Пример #2
0
    def process_nbest_handler( self , param_dict ):
        
        # ----- COMMON TO ALL DMs ----- #                        
        # Fill in action parts away from defaults: 
        # Using confidence scores 
        feature_set_list = []

        # if we want all 10 hypotheses:
        # use this for computing confidence scores

        ### custom for this experiment ###
        ### for computing the confidence score
        action_code_list = []
        for index, nbest_item in enumerate( param_dict['nbest_list'] ):
            feature_set = \
                tbh_compute_text_feature_set.compute_feature_set( \
                [ nbest_item ], self.feature_type_list )
            action_code = self.determine_action_code( feature_set )
            action_code_list.append( action_code )

        if len( action_code_list ) > 0:
            top_action_code = action_code_list[0]
            confidence_score = 0
            for code in action_code_list:
                if code == top_action_code:
                    confidence_score += 0.1
            confidence_score = confidence_score / float( len( action_code_list ) ) * 10 - 0.03
        else:
            confidence_score = 0

        print "CONFIDENCE SCORE:", confidence_score

        ### end of computing confidence score



        #### LOAD ENTRIES INTO PARAM_DICT
        param_dict['confidence_score'] = confidence_score
        feature_set = \
            tbh_compute_text_feature_set.compute_feature_set( \
            param_dict['nbest_list'] , self.feature_type_list )
        # add feature set to param_dict for storage and other purposes
        param_dict[ 'feature_set' ] = feature_set


        # for the pomdp
        # Search over the features to determine the right action

        # --- CUSTOM TO YOUR DM --- #
        # Adjust things based on this action dictionary and send to
        # everyone who might want to use it

        # ----- COMMON TO ALL DMs ----- #
        # Send the action_dict to everyone that might need it: common
        # to all dialog managers; you probably don't want to change
        # this part of the code.

        #if action_dict['skype_manager_phone_action'] is not None:
        #    self._process_phone_event( action_dict['skype_manager_phone_action'] )


        if self.current_experiment_log.experiment_name[0] == "POMDP":
            action_dict = self.determine_action_confidence( param_dict )
            self.machine_action = action_dict['pomdp_dict']['new_machine_action']
            self.belief_for_policy = action_dict['pomdp_dict']['belief_for_policy']

            print "\n================="
            print "CURRENT POLICY"
            print self.belief_for_policy
            print "================="

            #print "==========BELIEF=========="
            #print self.belief_for_policy
            #print "=========================="

            # Update the belief as appropriate
            self.pomdp.belief = action_dict['pomdp_dict']['final_belief']

            current_turn = tbh_experiment_controller.experiment_turn( \
                time = time.time(), \
                    utterance_file = None, \
                    param_dict = param_dict, \
                    utterance_hypothesis = param_dict['nbest_list'][0]['text'],
                    hypothesis_code = \
                    self.determine_action_code( param_dict['feature_set'] ), \
                    confidence_score = confidence_score, \
                    system_response = \
                    action_dict['pomdp_dict']['new_machine_action'] )

        elif self.current_experiment_log.experiment_name[0] == "THRESHOLD":
            threshold = 0.75
            action_dict = self.determine_action_threshold( param_dict, threshold )
            self.belief_for_policy = tbh_pomdp_util.reset_belief( self.pomdp )
            self.pomdp.belief = tbh_pomdp_util.reset_belief( self.pomdp )

            if confidence_score < threshold:
                self.machine_action = action_dict['pomdp_dict']['new_machine_action']

                current_turn = tbh_experiment_controller.experiment_turn( \
                    time = time.time(), \
                        utterance_file = None, \
                        param_dict = param_dict, \
                        utterance_hypothesis = param_dict['nbest_list'][0]['text'],
                        hypothesis_code = \
                        self.determine_action_code( param_dict['feature_set'] ), \
                        confidence_score = confidence_score, \
                        system_response = \
                        action_dict['pomdp_dict']['new_machine_action'] )

            else:
                self.machine_action = action_dict['pomdp_dict']['new_machine_action']

                current_turn = tbh_experiment_controller.experiment_turn( \
                    time = time.time(), \
                        utterance_file = None, \
                        param_dict = param_dict, \
                        utterance_hypothesis = param_dict['nbest_list'][0]['text'],
                        hypothesis_code = \
                        self.determine_action_code( param_dict['feature_set'] ), \
                        confidence_score = confidence_score, \
                        system_response = \
                        self.determine_action_code( param_dict['feature_set'] ) )

        else:
            raise NameError( 'neither option as name of experiment' )


        self.current_experiment_log.turn_list.append( current_turn )

        # print self.current_experiment_log.turn_list

        # add this to the param_dict
        param_dict[ 'action_dict' ] = action_dict      
        
        if len( self.current_experiment_log.turn_list ) > 0:
            for turn in self.current_experiment_log.turn_list:
                print turn.time, turn.utterance_file, turn.utterance_hypothesis, turn.hypothesis_code, turn.confidence_score, turn.system_response

        self._processed_nbest_event( param_dict )
Пример #3
0
    def process_nbest_handler( self , param_dict ):
    
        # ----- COMMON TO ALL DMs ----- #                        
        # Fill in action parts away from defaults: 
        if USE_CONFIDENCE_SCORES == False:
            feature_set = tbh_compute_text_feature_set.compute_feature_set( \
                param_dict['nbest_list'] , self.feature_type_list )

            # add feature set to param_dict for storage and other purposes
            param_dict[ 'feature_set' ] = feature_set

            # map features to actions
            action_dict = self.determine_action( feature_set )

            # --- CUSTOM TO YOUR DM --- #
            # Adjust things based on this action dictionary and send to
            # everyone who might want to use it
            if action_dict['gui_state'] is not None:
                self.system_state = action_dict['gui_state']

            # ----- COMMON TO ALL DMs ----- #
            # Send the action_dict to everyone that might need it: common
            # to all dialog managers; you probably don't want to change
            # this part of the code.
            if action_dict['skype_manager_phone_action'] is not None:
                self._process_phone_event( action_dict['skype_manager_phone_action'] )
            param_dict[ 'action_dict' ] = action_dict

            self._processed_nbest_event( param_dict )

        else:
            feature_set_list = []
            for index, nbest_item in enumerate( param_dict['nbest_list'] ):
                
                feature_set = tbh_compute_text_feature_set.compute_feature_set( \
                    [ nbest_item ], self.feature_type_list )

                # add feature set to param_dict for storage and other purposes
                param_dict[ 'feature_set' ] = feature_set
                feature_set_list.append( feature_set )


            action_dict = self.determine_action( feature_set_list, USE_CONFIDENCE_SCORES )

                

                # --- CUSTOM TO YOUR DM --- #
                # Adjust things based on this action dictionary and send to
                # everyone who might want to use it






            if action_dict['gui_state'] is not None:
                self.system_state = action_dict['gui_state']

            # ----- COMMON TO ALL DMs ----- #
            # Send the action_dict to everyone that might need it: common
            # to all dialog managers; you probably don't want to change
            # this part of the code.

            if action_dict['skype_manager_phone_action'] is not None:
                self._process_phone_event( action_dict['skype_manager_phone_action'] )
            param_dict[ 'action_dict' ] = action_dict





            self._processed_nbest_event( param_dict )
Пример #4
0
## 
# Description
# Allows user to input a string, and prints out the features

import tbh_compute_text_feature_set
import pprint

if __name__ == '__main__':
    while 1:
        x = raw_input( "Type in a string " + \
                           "(lowercase, no commas or periods, " + \
                           "compose words if necessary, q to exit): " )

        # Create an artificial nbest list
        nbest_list = []
        for index in range(0,10):
            nbest_list.append( { 'text': x, 'score': 0 } )

        #print nbest_list

        feature_set = tbh_compute_text_feature_set.compute_feature_set( nbest_list, ['tbh_first_word', 'tbh_keyword', 'tbh_keyword_sequence', 'tbh_digits' ]  )

        #for feature_type in feature_set: 
        #    for feature in feature_set[ feature_type ]:                
        #        print feature_type, feature, feature_set[ feature_type ][ feature ]
        # print in a human-readable way
        pp = pprint.PrettyPrinter(indent=4)
        pprint.pprint( feature_set )   
    def process_nbest_handler( self , param_dict ):
        
        if 'reset_belief' in param_dict.keys() and param_dict['reset_belief']:
            # build action_dict with the 
            pomdp_dict = tbh_pomdp_manager.unit_test_reset_belief( self.pomdp )
            action_dict = {}
            action_dict[ 'pomdp_dict' ] = pomdp_dict
            param_dict[ 'action_dict' ] = action_dict      
        
            # This is for the next belief update
            self.machine_action = pomdp_dict['new_machine_action']
            self.belief_for_policy = pomdp_dict['belief_for_policy']

            print "\n================="
            print "CURRENT POLICY"
            print self.belief_for_policy
            print "================="

            self.pomdp.belief = pomdp_dict['final_belief']

        else:
            # ----- COMMON TO ALL DMs ----- #                        
            # Fill in action parts away from defaults: 
            if USE_CONFIDENCE_SCORES == False:
                feature_set = tbh_compute_text_feature_set.compute_feature_set( \
                    param_dict['nbest_list'] , self.feature_type_list )

                # add feature set to param_dict for storage and other purposes
                param_dict[ 'feature_set' ] = feature_set

                # map features to actions
                action_dict = self.determine_action( feature_set )

                # --- CUSTOM TO YOUR DM --- #
                # Adjust things based on this action dictionary and send to
                # everyone who might want to use it
                if action_dict['gui_state'] is not None:
                    self.system_state = action_dict['gui_state']

                # ----- COMMON TO ALL DMs ----- #
                # Send the action_dict to everyone that might need it: common
                # to all dialog managers; you probably don't want to change
                # this part of the code.
                if action_dict['skype_manager_phone_action'] is not None:
                    self._process_phone_event( action_dict['skype_manager_phone_action'] )
                param_dict[ 'action_dict' ] = action_dict
                self._processed_nbest_event( param_dict )
            else:
                # Using confidence scores 
                if USE_SYNTHETIC_DATA:
                    # just use the Adaboost features directly
                    # this is where we start to integrate the 
                    # tbh_ scripts with our own scripts
                    # or we can just use some sort of pickle file

                    # from the param_dict, process the result
                    # currently, we just take the one-best hypothesis 
                    # from the list and compute a hypothesis
                    feature_set = \
                        tbh_compute_text_feature_set.compute_feature_set( \
                        param_dict['nbest_list'] , self.feature_type_list )

                    # add feature set to param_dict for storage and other purposes
                    param_dict[ 'feature_set' ] = feature_set

                    # map features to actions
                    action_dict = self.determine_action_confidence( param_dict )

                    # ----- COMMON TO ALL DMs ----- #
                    # Send the action_dict to everyone that might need it: common
                    # to all dialog managers; you probably don't want to change
                    # this part of the code.
                    if action_dict['skype_manager_phone_action'] is not None:
                        self._process_phone_event( \
                            action_dict['skype_manager_phone_action'] )
                    param_dict[ 'action_dict' ] = action_dict

                    #self._processed_nbest_event( param_dict )

                # not using synthetic data
                else:
                    feature_set_list = []
                    for index, nbest_item in enumerate( param_dict['nbest_list'] ):

                        feature_set = \
                            tbh_compute_text_feature_set.compute_feature_set( \
                            [ nbest_item ], self.feature_type_list )

                        # add feature set to param_dict for storage and other purposes
                        param_dict[ 'feature_set' ] = feature_set
                        feature_set_list.append( feature_set )


                    action_dict = self.determine_action( feature_set_list, use_confidence_scores=USE_CONFIDENCE_SCORES )

                    # --- CUSTOM TO YOUR DM --- #
                    # Adjust things based on this action dictionary and send to
                    # everyone who might want to use it


                if action_dict['gui_state'] is not None:
                    self.system_state = action_dict['gui_state']

                # ----- COMMON TO ALL DMs ----- #
                # Send the action_dict to everyone that might need it: common
                # to all dialog managers; you probably don't want to change
                # this part of the code.

                if action_dict['skype_manager_phone_action'] is not None:
                    self._process_phone_event( action_dict['skype_manager_phone_action'] )
                param_dict[ 'action_dict' ] = action_dict      

        #print param_dict

        # This sends the action_dict to the corresponding place
        self._processed_nbest_event( param_dict )