def __init__( self, user_profile=None, test_mode=False ): self.speech_to_action_map = \ tbh_action_map.get_speech_to_action_map() if test_mode: self.user_profile = tbh_user_profile.tbh_user_profile_t( 0 ) else: self.user_profile = user_profile self.intent_matrix = self.initialize_intent_matrix() self.answer_text_manager = \ tbh_answer_text_manager.tbh_answer_text_manager_t()
def get_intents( self ): speech_dict = tbh_action_map.get_speech_to_action_map() # print intent_vector information_codes = [] system_codes = [] phone_call_codes = [] for code in speech_dict.keys(): category = speech_dict[code]['category'] if category in ( 'time', 'activities', 'weather', 'menus' ): information_codes.append( code ) elif category in ( 'system', 'voice_synthesizer' ): system_codes.append( code ) elif category in ( 'phone_call', 'digits' ): phone_call_codes.append( code ) possible_intents = information_codes + \ system_codes + phone_call_codes return possible_intents
def initialize_intent_matrix( self ): speech_dict = tbh_action_map.get_speech_to_action_map() intent_keys = speech_dict.keys() intent_matrix = {} for item in intent_keys: intent_matrix[item] = {} # Create intent matrix that maps codes to actions. This is a # conditional probability table with a high value along its # diagonals and low probabilities off diagonal possible_intents = self.get_intents() MATCH_VALUE = 0.95 for i in possible_intents: for j in possible_intents: if j == i: intent_matrix[i][j] = log( MATCH_VALUE ) else: intent_matrix[i][j] = \ log ( 1 - MATCH_VALUE ) - \ log( len( possible_intents ) - 1 ) return intent_matrix