示例#1
0
    def __init__(self, domainString):
        
        #DomainUtils() instance, which accesses ontology and database.
        self.domainUtil = DomainUtils.DomainUtils(domainString=domainString)

        configs = []
        # self.reward_every_turn = True
        # if Settings.config.has_option("eval", "rewardeveryturn"):
        #     configs.append('rewardeveryturn')
        #     self.reward_every_turn = Settings.config.getboolean('eval', 'rewardeveryturn')
        self.reward_venue_recommended = 100
        if Settings.config.has_option('eval', 'rewardvenuerecommended'):
            configs.append('rewardvenuerecommended')
            self.reward_venue_recommended = Settings.config.getint('eval', 'rewardvenuerecommended')
        self.penalise_all_turns = False
        if Settings.config.has_option('eval', 'penaliseallturns'):
            configs.append('penaliseallturns')
            self.penalise_all_turns = Settings.config.getboolean('eval', 'penaliseallturns')
        self.wrong_venue_penalty = 4
        if Settings.config.has_option('eval', 'wrongvenuepenalty'):
            configs.append('wrongvenuepenalty')
            self.wrong_venue_penalty = Settings.config.getint('eval', 'wrongvenuepenalty')
        self.not_mentioned_value_penalty = 4
        if Settings.config.has_option('eval', 'notmentionedvaluepenalty'):
            configs.append('notmentionedvaluepenalty')
            self.not_mentioned_value_penalty = Settings.config.getint('eval', 'notmentionedvaluepenalty')

        self.restart()

        if Settings.config.has_section('eval'):
            for opt in Settings.config.options('eval'):
                if opt not in configs and opt not in Settings.config.defaults():
                    logger.error('Invalid config: '+opt)
示例#2
0
 def __init__(self, domainString):
     domainUtil = DomainUtils.DomainUtils(domainString)
     self.generator = GoalGenerator(domainUtil)
     self.goal = None
     self.prev_goal = None
     self.hdcSim = UMHdcSim.UMHdcSim(domainUtil)
     self.lastUserAct = None
     self.lastSysAct = None
示例#3
0
    def __init__(self, domainString):
        self.domainUtil = DomainUtils.DomainUtils(domainString)

        self.CONFUSE_TYPE = 0.2
        self.CONFUSE_SLOT = 0.3
        self.CONFUSE_VALUE = 0.5
        self.newUserActs = [
            'hello', 'thankyou', 'ack', 'bye', 'inform', 'request', 'reqalts',
            'reqmore', 'confirm', 'affirm', 'negate', 'deny', 'repeat', 'null'
        ]
        self.nNewUserActs = len(self.newUserActs)
示例#4
0
    def create_domain_dependent_regex(self):
        """Can overwrite any of the regular expressions set in RegexSemI.RegexParser.init_regular_expressions(). 
        This doesn't deal with slot,value (ie domain dependent) semantics. For those you need to handcraft 
        the _decode_[inform,request,confirm] etc.
        """
        # REDEFINES OF BASIC SEMANTIC ACTS (ie those other than inform, request): (likely nothing needs to be done here)
        #eg: self.rHELLO = "anion"

        domain_util = DomainUtils.DomainUtils(domainString=self.domainTag,
                                              rootIn=self.repoRoot)
        self.USER_REQUESTABLE = domain_util.ontology["requestable"]
        self.USER_INFORMABLE = domain_util.ontology["system_requestable"]
        self.domains_type = domain_util.ontology["type"]
        # DOMAIN DEPENDENT SEMANTICS:
        self.slot_vocab = {}
        # FIXME: define slot specific language -  for requests
        #-------------------------------------------------------------------------------------------
        self.slot_vocab["warranty"] = "(warranty)"
        self.slot_vocab["design"] = "(design)"
        self.slot_vocab["display"] = "(display)"
        self.slot_vocab["graphadaptor"] = "(graphadaptor)"
        self.slot_vocab["sysmemory"] = "(sysmemory)"
        self.slot_vocab["processor"] = "(processor)"
        self.slot_vocab["processorclass"] = "(processorclass)"
        self.slot_vocab["platform"] = "(platform)"
        self.slot_vocab["utility"] = "(utility)"
        self.slot_vocab["price"] = "(price|cost|expense)(?!(\ ?range))"
        self.slot_vocab["pricerange"] = "(price\ ?range)"
        self.slot_vocab["dimension"] = "(size|dimension)"
        self.slot_vocab["weight"] = "(weight)(?!(\ ?range))"
        self.slot_vocab["weightrange"] = "(weight|weight\ ?range)"
        self.slot_vocab[
            "batteryrating"] = "(battery|battery\ ?rating|rating\ of\ the\ (laptops\ )*battery)"
        self.slot_vocab[
            "isforbusinesscomputing"] = "(business\ computing|gaming|fun|games|work|play)"
        self.slot_vocab["drive"] = "(drive|hard\ *drive)(?!(\ ?range))"
        self.slot_vocab["driverange"] = "(hard\ *)*drive(\ ?range)"
        self.slot_vocab["name"] = "(name)"
        self.slot_vocab["family"] = "(family|class)"
        #-------------------------------------------------------------------------------------------
        # Generate regular expressions for requests:
        self._set_request_regex()
        # Generate regular expressions for informs:
        self.slot_values = dict.fromkeys(self.USER_INFORMABLE)
        for slot in self.slot_values.keys():
            self.slot_values[slot] = {
                value: "(" + str(value) + ")"
                for value in domain_util.ontology["informable"][slot]
            }

        # FIXME:  many value have synonyms -- deal with this here:
        self._set_value_synonyms()  # At end of file - this can grow very long
        self._set_inform_regex()
 def bootup(self, domainString, previousDomainString=None, episodeNum=1):
     """
     """
     # also fire up the DMUtils - pass the slots too below...
     domain_utils = DomainUtils.DomainUtils(domainString=domainString)
     self.domainManagers[domainString] = DMan.DMan(domainUtil=domain_utils)
     self.domainManagers[domainString].restart()
     self.operatingDomain = domainString
     self.startLearningEpisode(episodeNum)
     # and note that this domain is now involved in current dialog:
     self.in_present_dialog.append(domainString)
     return self._conditionally_init_new_domains_belief(
         previousDomainString)
    def create_domain_dependent_regex(self):
        """Can overwrite any of the regular expressions set in RegexSemI.RegexParser.init_regular_expressions(). 
        This doesn't deal with slot,value (ie domain dependent) semantics. For those you need to handcraft 
        the _decode_[inform,request,confirm] etc.
        """
        # REDEFINES OF BASIC SEMANTIC ACTS (ie those other than inform, request): (likely nothing needs to be done here)
        #eg: self.rHELLO = "anion"

        domain_util = DomainUtils.DomainUtils(domainString=self.domainTag, rootIn=self.repoRoot)
        self.USER_REQUESTABLE = domain_util.ontology["requestable"]
        self.USER_INFORMABLE = domain_util.ontology["system_requestable"]
        self.domains_type = domain_util.ontology["type"]
        # DOMAIN DEPENDENT SEMANTICS:
        self.slot_vocab= {}
        # FIXME: define slot specific language -  for requests
        #-------------------------------------------------------------------------------------------    
        exit("below are the slots for the domain - fix up self.slot_vocab below")
    def create_domain_dependent_regex(self):
        """Can overwrite any of the regular expressions set in RegexSemI.RegexParser.init_regular_expressions(). 
        This doesn't deal with slot,value (ie domain dependent) semantics. For those you need to handcraft 
        the _decode_[inform,request,confirm] etc.
        """
        # REDEFINES OF BASIC SEMANTIC ACTS (ie those other than inform, request): (likely nothing needs to be done here)
        #eg: self.rHELLO = "anion"

        domain_util = DomainUtils.DomainUtils(domainString=self.domainTag,
                                              rootIn=self.repoRoot)
        self.USER_REQUESTABLE = domain_util.ontology["requestable"]
        self.USER_INFORMABLE = domain_util.ontology["system_requestable"]
        self.domains_type = domain_util.ontology["type"]
        # DOMAIN DEPENDENT SEMANTICS:
        self.slot_vocab = {}
        # FIXME: define slot specific language -  for requests
        #-------------------------------------------------------------------------------------------
        self.slot_vocab["price"] = "(price|cost|expense)(?!(\ ?range))"
        self.slot_vocab["pricerange"] = "(price\ ?range)"
        self.slot_vocab["accessories"] = "(extras|accessories)"
        self.slot_vocab["power"] = "(power)"
        self.slot_vocab["pixels"] = "(pixels)"
        self.slot_vocab["audio"] = "(audio|sound)"
        self.slot_vocab["cabinet"] = "(cabinet)"
        self.slot_vocab["eco"] = "((eco|environment(al)*)\ rating)"
        self.slot_vocab["screensizerange"] = "(screen\ ?size)(?!(\ ?range))"
        self.slot_vocab["screensize"] = "(screen\ ?size))"
        self.slot_vocab["hdmi"] = "(hdmi)"
        self.slot_vocab["usb"] = "(usb)"
        self.slot_vocab["name"] = "(name)"
        self.slot_vocab["series"] = "(series|family|class)"
        #-------------------------------------------------------------------------------------------
        # Generate regular expressions for requests:
        self._set_request_regex()
        # Generate regular expressions for informs:
        self.slot_values = dict.fromkeys(self.USER_INFORMABLE)
        for slot in self.slot_values.keys():
            self.slot_values[slot] = {
                value: "(" + str(value) + ")"
                for value in domain_util.ontology["informable"][slot]
            }

        # FIXME:  many value have synonyms -- deal with this here:
        self._set_value_synonyms()  # At end of file - this can grow very long
        self._set_inform_regex()
    def create_domain_dependent_regex(self):
        """Can overwrite any of the regular expressions set in RegexSemI.RegexParser.init_regular_expressions(). 
        This doesn't deal with slot,value (ie domain dependent) semantics. For those you need to handcraft 
        the _decode_[inform,request,confirm] etc.
        """
        # REDEFINES OF BASIC SEMANTIC ACTS (ie those other than inform, request): (likely nothing needs to be done here)
        #eg: self.rHELLO = "anion"

        domain_util = DomainUtils.DomainUtils(domainString=self.domainTag,
                                              rootIn=self.repoRoot)
        self.USER_REQUESTABLE = domain_util.ontology["requestable"]
        self.USER_INFORMABLE = domain_util.ontology["system_requestable"]
        self.domains_type = domain_util.ontology["type"]
        # DOMAIN DEPENDENT SEMANTICS:
        self.slot_vocab = {}
        # FIXME: define slot specific language -  for requests
        #---------------------------------------------------------------------------------------------------
        exit("THESE NEED FIXING FOR THIS DOMAIN")

        self.slot_vocab["addr"] = "(address)"
        self.slot_vocab["pricerange"] = "(price|cost)(\ ?range)*"
        self.slot_vocab["area"] = "(area|location)"
        self.slot_vocab["near"] = "(near)"
        self.slot_vocab["kind"] = "(kind)"
        self.slot_vocab["stars"] = "(stars|rating)"
        self.slot_vocab["phone"] = "(phone(\ number)*)"
        self.slot_vocab["postcode"] = "(postcode)"
        self.slot_vocab["hasinternet"] = "(internet)"
        self.slot_vocab["hasparking"] = "(parking|car(\ ?park))"
        self.slot_vocab["name"] = "(name)"
        #---------------------------------------------------------------------------------------------------
        # Generate regular expressions for requests:
        self._set_request_regex()
        # Generate regular expressions for informs:
        self.slot_values = dict.fromkeys(self.USER_INFORMABLE)
        for slot in self.slot_values.keys():
            self.slot_values[slot] = {
                value: "(" + str(value) + ")"
                for value in domain_util.ontology["informable"][slot]
            }

        # FIXME:  many value have synonyms -- deal with this here:
        self._set_value_synonyms()  # At end of file - this can grow very long
        self._set_inform_regex()
    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)
示例#10
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)
示例#11
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)
示例#12
0
    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)