async def test_memorise(self, trained_policy: FormPolicy, default_domain: Domain): domain = Domain.load("data/test_domains/form.yml") trackers = await training.load_data("data/test_stories/stories_form.md", domain) trained_policy.train(trackers, domain, RegexInterpreter()) ( all_states, all_actions, ) = trained_policy.featurizer.training_states_and_actions(trackers, domain) for tracker, states, actions in zip(trackers, all_states, all_actions): for state in states: if state is not None: # check that 'form: inform' was ignored if state.get(USER): assert not state.get(USER).get(INTENT) == "inform" recalled = trained_policy.recall(states, tracker, domain) active_form = trained_policy._get_active_form_name(states[-1]) if states[0] is not None and states[-1] is not None: # explicitly set intents and actions before listen after # which FormPolicy should not predict a form action and # should add FormValidation(False) event # @formatter:off is_no_validation = ( self._test_for_previous_action_and_intent( states, "default", "some_form" ) or self._test_for_previous_action_and_intent( states, "stop", "some_form" ) or self._test_for_previous_action_and_intent( states, "affirm", "utter_ask_continue" ) or self._test_for_previous_action_and_intent( states, "deny", "utter_ask_continue" ) # comes from the fact that intent_inform after utter_ask_continue # is not read from stories or self._test_for_previous_action_and_intent( states, "stop", "utter_ask_continue" ) ) # @formatter:on else: is_no_validation = False if "intent_start_form" in states[-1]: # explicitly check that intent that starts the form # is not memorized as non validation intent assert recalled is None elif is_no_validation: assert recalled == active_form else: assert recalled is None nums = np.random.randn(domain.num_states) random_states = [{f: num for f, num in zip(domain.input_states, nums)}] assert trained_policy.recall(random_states, None, domain) is None
async def test_train_form_policy(): policy = FormPolicy() trackers = await training.load_data( "{}/data/stories_form.md".format(prj_dir), domain, augmentation_factor=0) policy.train(trackers, domain) policy.persist("{}/models/form".format(prj_dir))