rasa/core/policies/two_stage_fallback.py
def predict_action_probabilities(self,
                                     tracker: DialogueStateTracker,
                                     domain: Domain) -> List[float]:
        """Predicts the next action if NLU confidence is low.
        """

        if self.deny_suggestion_intent_name not in domain.intents:
            raise InvalidDomain('The intent {} must be present in the '
                                'domain file to use the '
                                '`TwoStageFallbackPolicy`.'
                                ''.format(self.deny_suggestion_intent_name))

        nlu_data = tracker.latest_message.parse_data
        nlu_confidence = nlu_data["intent"].get("confidence", 1.0)
        last_intent_name = nlu_data['intent'].get('name', None)
        should_nlu_fallback = self.should_nlu_fallback(
            nlu_confidence, tracker.latest_action_name)
        user_rephrased = has_user_rephrased(tracker)

        if self._is_user_input_expected(tracker):
            result = confidence_scores_for(ACTION_LISTEN_NAME, 1.0,
                                           domain)
        elif self._has_user_denied(last_intent_name, tracker):
            logger.debug("User '{}' denied suggested intents.".format(
                tracker.sender_id))
            result = self._results_for_user_denied(tracker, domain)
        elif user_rephrased and should_nlu_fallback:
            logger.debug("Ambiguous rephrasing of user '{}' "
                         "for intent '{}'".format(tracker.sender_id,
                                                  last_intent_name))
            result = confidence_scores_for(ACTION_DEFAULT_ASK_AFFIRMATION_NAME,
                                           1.0,
                                           domain)
        elif user_rephrased:
            logger.debug(
                "User '{}' rephrased intent".format(tracker.sender_id))
            result = confidence_scores_for(ACTION_REVERT_FALLBACK_EVENTS_NAME,
                                           1.0, domain)
        elif tracker.last_executed_action_has(
                ACTION_DEFAULT_ASK_AFFIRMATION_NAME):
            if not should_nlu_fallback:
                logger.debug("User '{}' affirmed intent '{}'"
                             "".format(tracker.sender_id,
                                       last_intent_name))
                result = confidence_scores_for(
                    ACTION_REVERT_FALLBACK_EVENTS_NAME,
                    1.0, domain)
            else:
                result = confidence_scores_for(self.fallback_nlu_action_name,
                                               1.0, domain)
        elif should_nlu_fallback:
            logger.debug("User '{}' has to affirm intent '{}'.".format(
                tracker.sender_id, last_intent_name))
            result = confidence_scores_for(ACTION_DEFAULT_ASK_AFFIRMATION_NAME,
                                           1.0,
                                           domain)
        else:
            result = self.fallback_scores(domain, self.core_threshold)

        return result
Predicts the next action if NLU confidence is low.
        
Predicts the next action if NLU confidence is low.
Predicts the next action if NLU confidence is low .
def predict_action_probabilities(self,
                                     tracker: DialogueStateTracker,
                                     domain: Domain) -> List[float]:
        if self.deny_suggestion_intent_name not in domain.intents:
            raise InvalidDomain('The intent {} must be present in the '
                                'domain file to use the '
                                '`TwoStageFallbackPolicy`.'
                                ''.format(self.deny_suggestion_intent_name))
        nlu_data = tracker.latest_message.parse_data
        nlu_confidence = nlu_data["intent"].get("confidence", 1.0)
        last_intent_name = nlu_data['intent'].get('name', None)
        should_nlu_fallback = self.should_nlu_fallback(
            nlu_confidence, tracker.latest_action_name)
        user_rephrased = has_user_rephrased(tracker)
        if self._is_user_input_expected(tracker):
            result = confidence_scores_for(ACTION_LISTEN_NAME, 1.0,
                                           domain)
        elif self._has_user_denied(last_intent_name, tracker):
            logger.debug("User '{}' denied suggested intents.".format(
                tracker.sender_id))
            result = self._results_for_user_denied(tracker, domain)
        elif user_rephrased and should_nlu_fallback:
            logger.debug("Ambiguous rephrasing of user '{}' "
                         "for intent '{}'".format(tracker.sender_id,
                                                  last_intent_name))
            result = confidence_scores_for(ACTION_DEFAULT_ASK_AFFIRMATION_NAME,
                                           1.0,
                                           domain)
        elif user_rephrased:
            logger.debug(
                "User '{}' rephrased intent".format(tracker.sender_id))
            result = confidence_scores_for(ACTION_REVERT_FALLBACK_EVENTS_NAME,
                                           1.0, domain)
        elif tracker.last_executed_action_has(
                ACTION_DEFAULT_ASK_AFFIRMATION_NAME):
            if not should_nlu_fallback:
                logger.debug("User '{}' affirmed intent '{}'"
                             "".format(tracker.sender_id,
                                       last_intent_name))
                result = confidence_scores_for(
                    ACTION_REVERT_FALLBACK_EVENTS_NAME,
                    1.0, domain)
            else:
                result = confidence_scores_for(self.fallback_nlu_action_name,
                                               1.0, domain)
        elif should_nlu_fallback:
            logger.debug("User '{}' has to affirm intent '{}'.".format(
                tracker.sender_id, last_intent_name))
            result = confidence_scores_for(ACTION_DEFAULT_ASK_AFFIRMATION_NAME,
                                           1.0,
                                           domain)
        else:
            result = self.fallback_scores(domain, self.core_threshold)
        return result
def predict_action_probabilities ( self , tracker : DialogueStateTracker , domain : Domain ) -> List [ float ] : if self . deny_suggestion_intent_name not in domain . intents : raise InvalidDomain ( 'The intent {} must be present in the ' 'domain file to use the ' '`TwoStageFallbackPolicy`.' '' . format ( self . deny_suggestion_intent_name ) ) nlu_data = tracker . latest_message . parse_data nlu_confidence = nlu_data [ "intent" ] . get ( "confidence" , 1.0 ) last_intent_name = nlu_data [ 'intent' ] . get ( 'name' , None ) should_nlu_fallback = self . should_nlu_fallback ( nlu_confidence , tracker . latest_action_name ) user_rephrased = has_user_rephrased ( tracker ) if self . _is_user_input_expected ( tracker ) : result = confidence_scores_for ( ACTION_LISTEN_NAME , 1.0 , domain ) elif self . _has_user_denied ( last_intent_name , tracker ) : logger . debug ( "User '{}' denied suggested intents." . format ( tracker . sender_id ) ) result = self . _results_for_user_denied ( tracker , domain ) elif user_rephrased and should_nlu_fallback : logger . debug ( "Ambiguous rephrasing of user '{}' " "for intent '{}'" . format ( tracker . sender_id , last_intent_name ) ) result = confidence_scores_for ( ACTION_DEFAULT_ASK_AFFIRMATION_NAME , 1.0 , domain ) elif user_rephrased : logger . debug ( "User '{}' rephrased intent" . format ( tracker . sender_id ) ) result = confidence_scores_for ( ACTION_REVERT_FALLBACK_EVENTS_NAME , 1.0 , domain ) elif tracker . last_executed_action_has ( ACTION_DEFAULT_ASK_AFFIRMATION_NAME ) : if not should_nlu_fallback : logger . debug ( "User '{}' affirmed intent '{}'" "" . format ( tracker . sender_id , last_intent_name ) ) result = confidence_scores_for ( ACTION_REVERT_FALLBACK_EVENTS_NAME , 1.0 , domain ) else : result = confidence_scores_for ( self . fallback_nlu_action_name , 1.0 , domain ) elif should_nlu_fallback : logger . debug ( "User '{}' has to affirm intent '{}'." . format ( tracker . sender_id , last_intent_name ) ) result = confidence_scores_for ( ACTION_DEFAULT_ASK_AFFIRMATION_NAME , 1.0 , domain ) else : result = self . fallback_scores ( domain , self . core_threshold ) return result
Predicts the next action if NLU confidence is low.
Predicts the next action if NLU confidence is low .
"""Predicts the next action if NLU confidence is low.
        """
self
tracker
DialogueStateTracker
domain
Domain