def __init__(self, domainUtil): """ Constructor for Dialogue manager: has a belief state tracker and a policy. :param domainUtil: (instance) of :class:`DomainUtils` :return: """ configlist = ['policytype'] self.useconfreq = False self.actions = SummaryAction.SummaryAction(domainUtil) self.bcm = False self.curr_policy = -1 #TODO adding domainUtil instance to class - for conditional tracking -- may not really be required self.domainUtil = domainUtil # General [policy] config options. (just bcm at present, rest use a domain tag as well) if Settings.config.has_option('policy', 'bcm'): configlist.append('bcm') self.bcm = Settings.config.getboolean('policy', 'bcm') if not Settings.config.has_section('policy_' + domainUtil.domainString): logger.warning("No policy section specified for domain: " + domainUtil.domainString + " - defaulting to HDC") self.pol_type = 'hdc' self.learning = False if Settings.config.has_option('policy_' + domainUtil.domainString, 'learning'): configlist.append('learning') self.learning = Settings.config.getboolean( 'policy_' + domainUtil.domainString, 'learning') if Settings.config.has_option('policy_' + domainUtil.domainString, 'useconfreq'): configlist.append('useconfreq') self.useconfreq = Settings.config.getboolean( 'policy_' + domainUtil.domainString, 'useconfreq') if Settings.config.has_option('policy_' + domainUtil.domainString, "currpolicy"): configs.append('currpolicy') self.curr_policy = Settings.config.getint( 'policy_' + domainUtil.domainString, "currpolicy") in_policy_file = None if Settings.config.has_option('policy_' + domainUtil.domainString, 'inpolicyfile'): configlist.append('inpolicyfile') in_policy_file = Settings.config.get( 'policy_' + domainUtil.domainString, 'inpolicyfile') out_policy_file = None if Settings.config.has_option('policy_' + domainUtil.domainString, 'outpolicyfile'): configlist.append('outpolicyfile') out_policy_file = Settings.config.get( 'policy_' + domainUtil.domainString, 'outpolicyfile') if in_policy_file is None: self.pol_type = 'hdc' else: self.pol_type = "gp" if Settings.config.has_option('policy_' + domainUtil.domainString, 'policytype'): self.pol_type = Settings.config.get( 'policy_' + domainUtil.domainString, 'policytype') if self.pol_type == 'hdc': logger.warning( 'Policy file is given: %s, but policy type is set to hdc.') logger.warning( 'Ignoring the given policy file and using hdc policy.') if self.pol_type == 'hdc': from policy import HDCPolicy self.policy = HDCPolicy.HDCPolicy(use_confreq=self.useconfreq, domainUtil=domainUtil) elif self.pol_type == 'gp': from policy import GPPolicy if self.bcm: policy_files = DomainUtils.get_all_policies( ) # TODO - delete - deprecated -- policy_file.split(";") self.policies = [] for pf in policy_files: self.policies.append( GPPolicy.GPPolicy(pf, len(self.actions.action_names), self.actions.action_names)) else: self.policy = GPPolicy.GPPolicy(in_policy_file, out_policy_file, len(self.actions.action_names), self.actions.action_names, domainUtil, self.learning) elif self.pol_type == 'mcc': from policy import MCCPolicy self.policy = MCCPolicy.MCCPolicy(in_policy_file, out_policy_file, self.useconfreq, self.learning, domainUtil) #------------------------------ # TODO - following policies need to receive the DomainUtils instance that Policy.Policy() requires # --- Not currently implemented as we aren't currently using these policy types elif True: exit('NOT IMPLEMENTED... see msg at this point in code') elif self.pol_type == 'type': from policy import TypePolicy self.policy = TypePolicy.TypePolicy() elif self.pol_type == 'select': from policy import SelectPolicy self.policy = SelectPolicy.SelectPolicy( use_confreq=self.useconfreq) elif self.pol_type == 'nn': from policy import NNPolicy # TODO - further change here - train is now implmented in config file. below needs updating self.policy = NNPolicy.NNPolicy(use_confreq=self.useconfreq, is_training=train) else: logger.error('Invalid policy type: ' + self.pol_type) #------------------------------ if self.pol_type != 'gp' and self.pol_type != 'hdc' and self.pol_type != 'mcc': self.policy.load(policy_file) belief_type = 'baseline' # can alternatively use 'focus' as the default if Settings.config.has_option('policy_' + domainUtil.domainString, 'belieftype'): configlist.append('belieftype') belief_type = Settings.config.get( 'policy_' + domainUtil.domainString, 'belieftype') self.startwithhello = False if Settings.config.has_option('policy_' + domainUtil.domainString, 'startwithhello'): configlist.append('startwithhello') self.startwithhello = Settings.config.getboolean( 'policy_' + domainUtil.domainString, 'startwithhello') if Settings.config.has_section('policy_' + domainUtil.domainString): for opt in Settings.config.options('policy_' + domainUtil.domainString): if opt not in configlist and opt not in Settings.config.defaults( ): logger.error('Invalid config: ' + opt) if belief_type == 'focus': self.beliefs = BeliefTracker.FocusTracker(domainUtil) elif belief_type == 'baseline': self.beliefs = BeliefTracker.BaselineTracker(domainUtil) elif belief_type == 'rnn': self.beliefs = BeliefTracker.RNNTracker() else: logger.error('Invalid belief tracker: ' + belief_type)
def __init__(self,domainUtil): """ Constructor for Dialogue manager: has a belief state tracker and a policy. :param domainUtil: (instance) of :class:`DomainUtils` :return: """ configlist = ['policytype'] self.useconfreq = False self.actions = SummaryAction.SummaryAction(domainUtil) self.bcm = False self.curr_policy = -1 #TODO adding domainUtil instance to class - for conditional tracking -- may not really be required self.domainUtil = domainUtil # General [policy] config options. (just bcm at present, rest use a domain tag as well) if Settings.config.has_option('policy', 'bcm'): configlist.append('bcm') self.bcm = Settings.config.getboolean('policy', 'bcm') if not Settings.config.has_section('policy_'+domainUtil.domainString): logger.warning("No policy section specified for domain: "+domainUtil.domainString+" - defaulting to HDC") self.pol_type = 'hdc' self.learning = False if Settings.config.has_option('policy_'+domainUtil.domainString, 'learning'): configlist.append('learning') self.learning = Settings.config.getboolean('policy_'+domainUtil.domainString, 'learning') if Settings.config.has_option('policy_'+domainUtil.domainString, 'useconfreq'): configlist.append('useconfreq') self.useconfreq = Settings.config.getboolean('policy_'+domainUtil.domainString, 'useconfreq') if Settings.config.has_option('policy_'+domainUtil.domainString, "currpolicy"): configs.append('currpolicy') self.curr_policy = Settings.config.getint('policy_'+domainUtil.domainString,"currpolicy") in_policy_file = None if Settings.config.has_option('policy_'+domainUtil.domainString, 'inpolicyfile'): configlist.append('inpolicyfile') in_policy_file = Settings.config.get('policy_'+domainUtil.domainString, 'inpolicyfile') out_policy_file = None if Settings.config.has_option('policy_'+domainUtil.domainString, 'outpolicyfile'): configlist.append('outpolicyfile') out_policy_file = Settings.config.get('policy_'+domainUtil.domainString, 'outpolicyfile') if in_policy_file is None: self.pol_type = 'hdc' else: self.pol_type = "gp" if Settings.config.has_option('policy_'+domainUtil.domainString, 'policytype'): self.pol_type = Settings.config.get('policy_'+domainUtil.domainString, 'policytype') if self.pol_type == 'hdc': logger.warning('Policy file is given: %s, but policy type is set to hdc.') logger.warning('Ignoring the given policy file and using hdc policy.') if self.pol_type == 'hdc': from policy import HDCPolicy self.policy = HDCPolicy.HDCPolicy(use_confreq=self.useconfreq, domainUtil=domainUtil ) elif self.pol_type == 'gp': from policy import GPPolicy if self.bcm : policy_files = DomainUtils.get_all_policies() # TODO - delete - deprecated -- policy_file.split(";") self.policies = [] for pf in policy_files: self.policies.append(GPPolicy.GPPolicy(pf, len(self.actions.action_names), self.actions.action_names)) else: self.policy = GPPolicy.GPPolicy(in_policy_file, out_policy_file, len(self.actions.action_names), self.actions.action_names, domainUtil, self.learning) elif self.pol_type == 'mcc': from policy import MCCPolicy self.policy = MCCPolicy.MCCPolicy( in_policy_file, out_policy_file, self.useconfreq, self.learning, domainUtil ) #------------------------------ # TODO - following policies need to receive the DomainUtils instance that Policy.Policy() requires # --- Not currently implemented as we aren't currently using these policy types elif True: exit('NOT IMPLEMENTED... see msg at this point in code') elif self.pol_type == 'type': from policy import TypePolicy self.policy = TypePolicy.TypePolicy() elif self.pol_type == 'select': from policy import SelectPolicy self.policy = SelectPolicy.SelectPolicy(use_confreq=self.useconfreq) elif self.pol_type == 'nn': from policy import NNPolicy # TODO - further change here - train is now implmented in config file. below needs updating self.policy = NNPolicy.NNPolicy(use_confreq=self.useconfreq, is_training=train) else: logger.error('Invalid policy type: ' + self.pol_type) #------------------------------ if self.pol_type != 'gp' and self.pol_type != 'hdc' and self.pol_type != 'mcc': self.policy.load(policy_file) belief_type = 'baseline' # can alternatively use 'focus' as the default if Settings.config.has_option('policy_'+domainUtil.domainString, 'belieftype'): configlist.append('belieftype') belief_type = Settings.config.get('policy_'+domainUtil.domainString, 'belieftype') self.startwithhello = False if Settings.config.has_option('policy_'+domainUtil.domainString, 'startwithhello'): configlist.append('startwithhello') self.startwithhello = Settings.config.getboolean('policy_'+domainUtil.domainString, 'startwithhello') if Settings.config.has_section('policy_'+domainUtil.domainString): for opt in Settings.config.options('policy_'+domainUtil.domainString): if opt not in configlist and opt not in Settings.config.defaults(): logger.error('Invalid config: '+opt) if belief_type == 'focus': self.beliefs = BeliefTracker.FocusTracker(domainUtil) elif belief_type == 'baseline': self.beliefs = BeliefTracker.BaselineTracker(domainUtil) elif belief_type == 'rnn': self.beliefs = BeliefTracker.RNNTracker() else: logger.error('Invalid belief tracker: ' + belief_type)