Пример #1
0
 def create_policy(self, featurizer, priority):
     max_history = None
     if isinstance(featurizer, MaxHistoryTrackerFeaturizer):
         max_history = featurizer.max_history
     p = AugmentedMemoizationPolicy(priority=priority,
                                    max_history=max_history)
     return p
Пример #2
0
 def create_policy(
     self, featurizer: Optional[TrackerFeaturizer], priority: int
 ) -> Policy:
     max_history = None
     if isinstance(featurizer, MaxHistoryTrackerFeaturizer):
         max_history = featurizer.max_history
     return AugmentedMemoizationPolicy(priority=priority, max_history=max_history)
Пример #3
0
def test_agent_wrong_use_of_load():
    training_data_file = "examples/moodbot/data/stories.yml"
    agent = Agent("examples/moodbot/domain.yml",
                  policies=[AugmentedMemoizationPolicy()])

    with pytest.raises(ValueError):
        # try to load a model file from a data path, which is nonsense and
        # should fail properly
        agent.load(training_data_file)
Пример #4
0
async def prepared_agent(tmpdir_factory) -> Agent:
    model_path = tmpdir_factory.mktemp("model").strpath

    agent = Agent("data/test_domains/default.yml",
                  policies=[AugmentedMemoizationPolicy(max_history=3)])

    training_data = await agent.load_data(DEFAULT_STORIES_FILE)
    agent.train(training_data)
    agent.persist(model_path)
    return agent
Пример #5
0
async def default_processor(default_domain, default_nlg):
    agent = Agent(default_domain,
                  SimplePolicyEnsemble([AugmentedMemoizationPolicy()]),
                  interpreter=RegexInterpreter())

    training_data = await agent.load_data(DEFAULT_STORIES_FILE)
    agent.train(training_data)
    tracker_store = InMemoryTrackerStore(default_domain)
    return MessageProcessor(agent.interpreter, agent.policy_ensemble,
                            default_domain, tracker_store, default_nlg)
Пример #6
0
async def test_missing_template_breaks_training(tmpdir,
                                                domain_missing_template):
    training_data_file = "examples/moodbot/data/stories.md"
    domain_path = utilities.write_text_to_file(tmpdir, "domain.yml",
                                               domain_missing_template)

    agent = Agent(domain_path, policies=[AugmentedMemoizationPolicy()])
    training_data = await agent.load_data(training_data_file)
    with pytest.raises(InvalidDomain):
        agent.train(training_data)
Пример #7
0
async def test_training_data_is_reproducible():
    training_data_file = "examples/moodbot/data/stories.yml"
    agent = Agent("examples/moodbot/domain.yml",
                  policies=[AugmentedMemoizationPolicy()])

    training_data = await agent.load_data(training_data_file)
    # make another copy of training data
    same_training_data = await agent.load_data(training_data_file)

    # test if both datasets are identical (including in the same order)
    for i, x in enumerate(training_data):
        assert str(x.as_dialogue()) == str(same_training_data[i].as_dialogue())
Пример #8
0
async def _trained_default_agent(tmpdir_factory: TempdirFactory) -> Tuple[Agent, str]:
    model_path = tmpdir_factory.mktemp("model").strpath

    agent = Agent(
        "data/test_domains/default_with_slots.yml",
        policies=[AugmentedMemoizationPolicy(max_history=3)],
    )

    training_data = await agent.load_data(DEFAULT_STORIES_FILE)
    agent.train(training_data)
    agent.persist(model_path)
    return agent
Пример #9
0
async def _trained_default_agent() -> Tuple[Agent, str]:
    model_path = "{}/models/".format(prj_dir)

    agent = Agent(
        "{}/data/default_with_slots.yml".format(prj_dir),
        policies=[AugmentedMemoizationPolicy(max_history=3)],
    )

    training_data = await agent.load_data(
        "{}/data/stories_defaultdomain.md".format(prj_dir))
    agent.train(training_data)
    agent.persist(model_path)
    return agent
Пример #10
0
async def _trained_default_agent(tmpdir_factory: TempdirFactory,
                                 stories_path: Text) -> Agent:
    model_path = tmpdir_factory.mktemp("model").strpath

    agent = Agent(
        "data/test_domains/default_with_slots.yml",
        policies=[AugmentedMemoizationPolicy(max_history=3),
                  RulePolicy()],
    )

    training_data = await agent.load_data(stories_path)
    agent.train(training_data)
    agent.persist(model_path)
    return agent
Пример #11
0
async def test_agent_train(tmpdir, default_domain):
    training_data_file = "examples/moodbot/data/stories.md"
    agent = Agent("examples/moodbot/domain.yml",
                  policies=[AugmentedMemoizationPolicy()])

    training_data = await agent.load_data(training_data_file)
    agent.train(training_data)
    agent.persist(tmpdir.strpath)

    loaded = Agent.load(tmpdir.strpath)

    # test domain
    assert loaded.domain.action_names == agent.domain.action_names
    assert loaded.domain.intents == agent.domain.intents
    assert loaded.domain.entities == agent.domain.entities
    assert loaded.domain.templates == agent.domain.templates
    assert [s.name for s in loaded.domain.slots
            ] == [s.name for s in agent.domain.slots]

    # test policies
    assert isinstance(loaded.policy_ensemble, type(agent.policy_ensemble))
    assert [type(p) for p in loaded.policy_ensemble.policies
            ] == [type(p) for p in agent.policy_ensemble.policies]