示例#1
0
    def _check_USER_ending(self, state=None, sys_act=None):
        '''Sets boolean self.ENDING_DIALOG if user has ended call. 
        
        .. note:: can change the semo str if user ended.

        :param state: system's state (belief)
        :type state: :class:`~utils.DialgoueState.DialgoueState`

        :param sys_act: system's dialogue act
        :type sys_act: string

        :return: bool -- whether to end the dialogue or not
        '''
        #         assert(not self.ENDING_DIALOG)

        self.ENDING_DIALOG = state.check_user_ending()
        if self.ENDING_DIALOG:
            if self.semo_manager is not None:
                if 'bye' not in self.prompt_str:
                    self.logger.warning(
                        'Ignoring system act: %s and saying goodbye as user has said bye'
                        % sys_act)
                    self.prompt_str = 'Goodbye. '  # TODO - check how system can say bye --otherwise user has said bye,
                    #  and we get some odd reply like 'in the south. please enter the 5 digit id ...'
            sys_act = DiaAct('bye()')
        return sys_act
示例#2
0
    def continue_call(self, asr_info, uact=None, domainString=None, domainSimulatedUsers=None):
        '''
        Works through topictracking > semi belief > policy > semo > evaluation -- for turns > 0
        
        Input consists of a n-best list of either ASR hypotheses (with confidence) or (mostly only in case of simulation) pre-interpreted DiaActWithProb objects.
              
        :param asr_info: information fetched from the asr
        :type asr_info: list of string or DiaActWithProb objects

        :param domainString: domain name
        :type domainString: string

        :param domainSimulatedUsers: simulated users in different domains
        :type domainSimulatedUsers: dict
        
        :return: DiaAct -- the system's reponse dialogue act with verbalization
        ''' 

        logger.dial("user input: {}".format([(x.to_string() if isinstance(x,DiaAct) else x[0], round(x.P_Au_O, 3) if isinstance(x,DiaAct) else x[1]) for x in asr_info]))

        # @XINNUO: Translate user_act to str by calling _agents_semo()
        #self._agents_semo(uact, domainString)
        
        # Check if user says bye and whether this is already valid
        self.callValidator.validate() # update time once more
        if self.callValidator.check_if_user_bye(asr_info) and not self.callValidator.isValid:
            logger.info("User tries to end dialogue before min dialogue length.")
            return self.callValidator.getNonValidPrompt() + " " + self.prompt_str

        # 0. Increment turn and possibly set ENDING_DIALOG if max turns reached:
        #--------------------------------------------------------------------------------------------------------------
        if self._increment_turn_and_check_maxTurns():
            sys_act = DiaAct('bye()')
            sys_act.prompt = self.MAX_TURNS_PROMPT
            return sys_act
        
        # 1. USER turn:
        #--------------------------------------------------------------------------------------------------------------
        
        # Make sure there is some asr information:
        if not len(asr_info):
            sys_act = DiaAct('null()')
            sys_act.prompt = self.NO_ASR_MSG
            return sys_act
        
        # TOPIC TRACKING: Note: can pass domainString directly here if cheating/developing or using simulate
        currentDomain = self._track_topic_and_hand_control(domainString=domainString, userAct_hyps=asr_info)
        prev_sys_act = self.retrieve_last_sys_act(currentDomain)
        
        
        # 2. SYSTEM response:
        #--------------------------------------------------------------------------------------------------------------
        
        # SYSTEM ACT:
                # 1. Belief state tracking -- (currently just in single domain as directed by topic tracker)
        logger.debug('active domain is: '+currentDomain)
        
        state = self.semi_belief_manager.update_belief_state(ASR_obs=asr_info, sys_act=prev_sys_act,
                                                     dstring=currentDomain, turn=self.currentTurn,hub_id = self.hub_id, sim_lvl=self.sim_level)
        
        self._print_usr_act(state, currentDomain)
        
        # 2. Policy -- Determine system act/response
        sys_act = self.policy_manager.act_on(dstring=currentDomain, state=state)

        # Check ending the call:
        sys_act = self._check_ENDING_CALL(state, sys_act)  # NB: this may change the self.prompt_str

        self._print_sys_act(sys_act)

        # SEMO:
        self.prompt_str = self._agents_semo(sys_act)
        sys_act.prompt = self.prompt_str
        
        
        # 3. TURN ENDING
        #-----------------------------------------------------------------------------------------------------------------
        
        # EVALUATION: - record the system action taken in the current domain if using tasks for evaluation (ie DialogueServer)
        self._evaluate_agents_turn(domainSimulatedUsers, sys_act, state)
        
        self.callValidator.validate(sys_act)
        
        sys_act.prompt = self.prompt_str
        state.setLastSystemAct(sys_act)
        
        #---Return the generated prompt---------------------------------------------------
        return sys_act