def __init__(self, generate_prompts):
        configs = []

        if not Settings.config.has_option("DEFAULT", "domains"):
            logger.error("You must specify the domains under the DEFAULT section of the config")
        domains = Settings.config.get("DEFAULT", "domains")
        logger.info("--Simulating dialogues over the domains: ", domains)
        self.possible_domains = domains.split(",")
        DomainUtils.checkDomainStrings(domainStrings=self.possible_domains)

        self.maxTurns = 30
        if Settings.config.has_option("simulate", "maxturns"):
            configs.append("maxturns")
            self.maxTurns = Settings.config.getint("simulate", "maxturns")
        self.forceNullPositive = False
        if Settings.config.has_option("simulate", "forcenullpositive"):
            configs.append("forcenullpositive")
            self.forceNullPositive = Settings.config.getboolean("simulate", "forcenullpositive")
        conf_scorer_name = "additive"
        if Settings.config.has_option("simulate", "confscorer"):
            conf_scorer_name = Settings.config.get("simulate", "confscorer")

        if Settings.config.has_section("simulate"):
            for opt in Settings.config.options("simulate"):
                if opt not in configs and opt not in Settings.config.defaults():
                    logger.error("Invalid config: " + opt)

        # [MultiDomain?] Dialogue Management/policy.
        # -----------------------------------------
        self.topic_manager = TopicManager.TopicManager()

        # Simulated User.
        # -----------------------------------------
        # TODO - deal with multi domain simulation - whilst changing Settings.py ill just pass domain here for now
        logger.debug("simulate.py -- XXXXXXX -- directly passing domain name in simulate at present...")
        self.simulator = UserSimulator.SimulatedUsersManager(domainStrings=self.possible_domains)

        # Error Simulator.
        # -----------------------------------------
        # TODO - it is a hack for now passing the domain string directly from config via self.possible_domains. look at this
        # self.errorSimulator = ErrorSimulator.CuedErrorSimulator(conf_scorer_name, domainString=self.possible_domains[0])
        self.errorSimulator = ErrorSimulator.SimulatedErrorManager(conf_scorer_name, self.possible_domains)

        # SemO.
        # -----------------------------------------
        self.semoClass = None
        if generate_prompts:
            self.semo_name = "PassthroughSemO"
            if Settings.config.has_option("hub", "semo"):
                self.semo_name = Settings.config.get("hub", "semo")
            # SemO.
            if self.semo_name == "PassthroughSemO":
                self.semoClass = SemO.PassthroughSemO()
            elif self.semo_name == "BasicSemO":
                self.semoClass = SemO.BasicSemO()
            else:
                logger.warning("Invalid SemO: %s. Using PassthroughSemO." % self.semo_name)
                self.semoClass = SemO.PassthroughSemO()

        # Evaluation Manager.
        # -----------------------------------------
        self.evaluator = Evaluation.EvaluationManager(self.possible_domains)
Пример #2
0
    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)