def test_ask_affirmation(): policy = TwoStageFallbackPolicy.load("{}/models/two_stage_fallback".format(prj_dir)) events = [ActionExecuted(ACTION_LISTEN_NAME), user_uttered("Hi", 0.2)] next_action = _get_next_action(policy, events, default_domain) assert next_action == ACTION_DEFAULT_ASK_AFFIRMATION_NAME
def test_fallback_mapping_restart(): domain = Domain.load("data/test_domains/default.yml") events = [ ActionExecuted(ACTION_DEFAULT_FALLBACK_NAME), utilities.user_uttered(USER_INTENT_RESTART, 1), ] tracker = DialogueStateTracker.from_events("test", events, []) two_stage_fallback_policy = TwoStageFallbackPolicy( priority=2, deny_suggestion_intent_name="deny" ) mapping_policy = MappingPolicy(priority=1) mapping_fallback_ensemble = SimplePolicyEnsemble( [two_stage_fallback_policy, mapping_policy] ) result, best_policy = mapping_fallback_ensemble.probabilities_using_best_policy( tracker, domain, RegexInterpreter() ) max_confidence_index = result.index(max(result)) index_of_mapping_policy = 1 next_action = domain.action_for_index(max_confidence_index, None) assert best_policy == f"policy_{index_of_mapping_policy}_{MappingPolicy.__name__}" assert next_action.name() == ACTION_RESTART_NAME
def test_ask_rephrase(): policy = TwoStageFallbackPolicy.load("{}/models/two_stage_fallback".format(prj_dir)) events = [ ActionExecuted(ACTION_LISTEN_NAME), user_uttered("greet", 0.2), ActionExecuted(ACTION_DEFAULT_ASK_AFFIRMATION_NAME), ActionExecuted(ACTION_LISTEN_NAME), user_uttered("deny", 1), ] next_action = _get_next_action(policy, events, default_domain) assert next_action == ACTION_DEFAULT_ASK_REPHRASE_NAME
def test_unknown_instead_affirmation(): trained_policy = TwoStageFallbackPolicy.load("{}/models/two_stage_fallback".format(prj_dir)) events = [ ActionExecuted(ACTION_LISTEN_NAME), user_uttered("greet", 0.2), ActionExecuted(ACTION_DEFAULT_ASK_AFFIRMATION_NAME), ActionExecuted(ACTION_LISTEN_NAME), user_uttered("greet", 0.2), ] next_action = _get_next_action(trained_policy, events, default_domain) assert next_action == ACTION_DEFAULT_FALLBACK_NAME
def test_should_nlu_fallback( self, trained_policy: TwoStageFallbackPolicy, top_confidence: float, all_confidences: List[float], last_action_name: Text, should_nlu_fallback: bool, ): nlu_data = { "intent": {"confidence": top_confidence}, "intent_ranking": [ {"confidence": confidence} for confidence in all_confidences ], } assert ( trained_policy.should_nlu_fallback(nlu_data, last_action_name) is should_nlu_fallback )
def create_policy(self, featurizer, priority): p = TwoStageFallbackPolicy(priority=priority, deny_suggestion_intent_name="deny") return p
def create_policy( self, featurizer: Optional[TrackerFeaturizer], priority: int ) -> Policy: return TwoStageFallbackPolicy( priority=priority, deny_suggestion_intent_name="deny" )
async def test_train_fallback_policy(): policy = TwoStageFallbackPolicy(priority=1, deny_suggestion_intent_name="deny") policy.persist("{}/models/two_stage_fallback".format(prj_dir))
def test_listen_after_hand_off(): trained_policy = TwoStageFallbackPolicy.load("{}/models/two_stage_fallback".format(prj_dir)) events = [ActionExecuted(ACTION_DEFAULT_FALLBACK_NAME)] next_action = _get_next_action(trained_policy, events, default_domain) assert next_action == ACTION_LISTEN_NAME