Exemplo n.º 1
0
def default_agent(default_domain):
    agent = Agent(default_domain,
                  policies=[MemoizationPolicy()],
                  interpreter=RegexInterpreter(),
                  tracker_store=InMemoryTrackerStore(default_domain))
    training_data = agent.load_data(DEFAULT_STORIES_FILE)
    agent.train(training_data)
    return agent
Exemplo n.º 2
0
def default_agent(default_domain):
    agent = Agent(default_domain,
                  policies=[MemoizationPolicy()],
                  interpreter=RegexInterpreter(),
                  tracker_store=InMemoryTrackerStore(default_domain))
    training_data = agent.load_data(DEFAULT_STORIES_FILE)
    agent.train(training_data)
    return agent
Exemplo n.º 3
0
def train_dialogue(domain_file='restaurant_domain.yml',
                   model_path='./models/dialogue',
                   training_data_file='./data/stories.md'):
    agent = Agent(domain_file, policies=[MemoizationPolicy(), KerasPolicy()])
    training_data = agent.load_data(training_data_file)
    agent.train(training_data)

    agent.persist(model_path)
    return agent
Exemplo n.º 4
0
def train_dialog(dialog_training_data_file,
                 domain_file,
                 path_to_model='models/dialogue'):
    logging.basicConfig(level='INFO')
    agent = Agent(domain_file, policies=[MemoizationPolicy(max_history=1)])
    training_data = agent.load_data(dialog_training_data_file)
    agent.train(training_data)

    agent.persist(path_to_model)
Exemplo n.º 5
0
def dialogue_train(domain_file = 'w_domain.yml',
					model_path = './models/dialogue',
					training_data_file = './data/stories.md'):
					
	agent = Agent(domain_file, policies = [MemoizationPolicy(), KerasPolicy(max_history=3, epochs=200, batch_size=50)])
	data = agent.load_data(training_data_file)	
	agent.train(data)
	agent.persist(model_path)
	return agent
Exemplo n.º 6
0
def train_dialogue():
    agent = Agent('domain.yml', policies=[MemoizationPolicy(), KerasPolicy()])
    training_data = agent.load_data('stories.md')

    agent.train(
        training_data)

    agent.persist('models/dialogue')
    return agent
Exemplo n.º 7
0
def train_dialogue(domain_file="data/domain.yml",
                   training_data_file='data/stories.md',
                   model_dir="./models/dialogue"):

    agent = Agent(domain_file, policies=[MemoizationPolicy(), KerasPolicy()])

    agent.train(training_data_file, max_history=3, epochs=300)
    agent.persist(model_dir)
    return agent
Exemplo n.º 8
0
    def train_dialogue(self):
        domain_file = os.path.join(self.TRAINING_DIR, 'domain.yml')
        stories_file = os.path.abspath(os.path.join(self.TRAINING_DIR, 'story.md'))

        domain = TemplateDomain.load(domain_file)
        # domain.compare_with_specification(os.path.join(self.TRAINING_DIR, 'dialogue'))
        agent = Agent(domain, policies=[MemoizationPolicy(), KerasPolicy()])
        agent.train(stories_file,validation_split=0.1)
        agent.persist(os.path.join(self.TRAINING_DIR, 'dialogue'))
Exemplo n.º 9
0
def train_dialogue(domain_file='domain.yml',
                   model_path='./models/dialogue',
                   training_data_file='./data/stories.md'):

    agent = Agent(domain_file, policies=[MemoizationPolicy(), KerasPolicy()])
    data = agent.load_data(training_data_file)
    agent.train(data, epochs=300, batch_size=50, validation_split=0.2)

    agent.persist(model_path)
    return agent
Exemplo n.º 10
0
def train_dialogue(domain_file, stories_file, dialogue_path):
    # loading our neatly defined training dialogues
    agent = Agent(domain_file, policies=[MemoizationPolicy(), KerasPolicy(epochs=200, max_history = 6)])
    training_data = agent.load_data(stories_file)


    agent.train(
        training_data)

    agent.persist(dialogue_path)
Exemplo n.º 11
0
def train_dialogue(domain_file="domain.yml",
                   model_path="models/dialogue",
                   training_data_file="data/stories.md"):
    print("Dialogue Trainer")
    agent = Agent(domain_file, policies=[SklearnPolicy()])

    agent.train(training_data_file, max_history=12)

    agent.persist(model_path)
    return agent
Exemplo n.º 12
0
def train_dialogue(train = True,domain_file = 'nurse_domain.yml',
					model_path = './models/dialogue',
					training_data_file = './data/stories.md'):
	if(train == True):
		agent = Agent(domain_file, policies = [MemoizationPolicy(), KerasPolicy(max_history=3, epochs=200, batch_size=50)])
		data = agent.load_data(training_data_file)
		agent.train(data)
		#agent.visualize("data/stories.md",output_file="graph.html", max_history=2)
		agent.persist(model_path)
		return agent
Exemplo n.º 13
0
def default_processor(default_domain, default_nlg):
    agent = Agent(default_domain,
                  SimplePolicyEnsemble([AugmentedMemoizationPolicy()]),
                  interpreter=RegexInterpreter())

    training_data = 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)
Exemplo n.º 14
0
def core_server(tmpdir_factory):
    model_path = tmpdir_factory.mktemp("model").strpath

    agent = Agent("data/test_domains/default_with_topic.yml",
                  policies=[ScoringPolicy()])

    agent.train(DEFAULT_STORIES_FILE, max_history=3)
    agent.persist(model_path)

    return RasaCoreServer(model_path, interpreter=RegexInterpreter())
Exemplo n.º 15
0
def train_core(domain_file,
               model_path,
               training_data_file,
               policies=policy_config.load('policy.yml')):
    logging.basicConfig(filename=logfile, level=logging.DEBUG)
    agent = Agent(domain_file, policies=policies)
    training_data = agent.load_data(training_data_file)
    agent.train(training_data)
    agent.persist(model_path)
    return agent
Exemplo n.º 16
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
Exemplo n.º 17
0
def train_rasa_core():
    agent = Agent(RASA_CORE_DOMAIN_PATH,
                  policies=[MemoizationPolicy(),
                            StatusPolicy()])
    agent.train(RASA_CORE_TRAINING_DATA_PATH,
                max_history=RASA_CORE_MAX_HISTORY,
                epochs=RASA_CORE_EPOCHS,
                batch_size=RASA_CORE_BATCH_SIZE,
                validation_split=RASA_CORE_VALIDATION)
    agent.persist(RASA_CORE_MODEL_PATH)
Exemplo n.º 18
0
def train_dialogue(domain_file="domain.yml",model_path="./Model/dialogue",training_data_file="Stories.md"):
    agent = Agent(domain_file,policies=[MemoizationPolicy(max_history=5),RestaurantPolicy()])
    training_data = agent.load_data(training_data_file)
    agent.train(training_data,epochs=100,
            batch_size=5,
            validation_split=0.2
    )

    agent.persist(model_path)
    return agent
Exemplo n.º 19
0
def train_policy(domain_file, stories_file):
    agent = Agent(domain_file, policies=[KerasPolicy()])
    training_data = agent.load_data(stories_file)
    agent.train(training_data, validation_split=0.0, epochs=400)
    agent.persist(DIALOGUE_MODELS_DIR)
    click.echo(
        "Policy model saved to '{}'".format(
            pathlib.Path(DIALOGUE_MODELS_DIR).\
            relative_to(HERE_DIR)
        )
    )
Exemplo n.º 20
0
def train_core(domain, story, dialogue):
    fallback = FallbackPolicy(fallback_action_name="action_default_fallback",
                              core_threshold=1,
                              nlu_threshold=0.7)
    agent = Agent(
        domain,
        policies=[MemoizationPolicy(max_history=3), fallback,
                  KerasPolicy()])
    training_data = agent.load_data(story)
    agent.train(training_data, epochs=100, validation_split=0.2)
    agent.persist(dialogue)
Exemplo n.º 21
0
def train():
    agent = Agent(domainFile, policies=[MemoizationPolicy(max_history = 3), KerasPolicy()])
    agent.train(
        trainingStories,
        epochs = 100,
        batch_size = 10,
        augmentation_factor = 20,
        validation_split = 0.2,
        remove_duplicates = True
    )
    agent.persist(modelPath)
Exemplo n.º 22
0
def train_mom_dm():
    agent = Agent("../mom/domain.yml", policies=[MemoizationPolicy()])

    agent.train(training_data_file,
                max_history=3,
                epochs=100,
                batch_size=50,
                augmentation_factor=50,
                validation_split=0.2)

    agent.persist(model_path)
Exemplo n.º 23
0
def run_weather_online(interpreter,
                          domain_file="weather_domain.yml",
                          training_data_file='data/stories.md'):
    policies2 = policy_config.load("config.yml")
    action_endpoint = "endpoint.yml"					  
    agent = Agent(domain_file,policies=policies2,interpreter=interpreter,action_endpoint=action_endpoint)
    				  
    data = asyncio.run(agent.load_data(training_data_file))			   
    agent.train(data)
    interactive.run_interactive_learning(agent,training_data_file)
    return agent
Exemplo n.º 24
0
    def train_dst():
        """Processes all the nlu feedback and train the nlu model"""
        logger.info("Training DST")

        agent = Agent(domain, ensemble, None, None)
        training_data = agent.load_data(envconfig['stories_path'])
        agent.train(training_data, epochs=50)
        agent.policy_ensemble.persist(dst_directory, False)
        #Finally setting all the trained data train_status to 1
        logger.info("Training nlu successfull")
        return jsonify({"success": 1})
Exemplo n.º 25
0
def core_server(tmpdir_factory):
    model_path = tmpdir_factory.mktemp("model").strpath

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

    training_data = agent.load_data(DEFAULT_STORIES_FILE)
    agent.train(training_data)
    agent.persist(model_path)

    return server.create_app(model_path, interpreter=RegexInterpreter())
def train_dialogue(domain_file="domain.yml",
                   model_path='./models/dialogue',
                   training_data_file='./data/stories.md'):
    agent = Agent(domain_file, policies=[MemoizationPolicy(), KerasPolicy()])
    agent.train(training_data_file,
                batch_size=50,
                epochs=30,
                validation_split=0.2,
                augmentation_factor=50)
    agent.persist(model_path)

    return agent
Exemplo n.º 27
0
def train_core(domain='domain.yml',
               model_path='./models/dialog',
               train_data='./data/stories.md'):
    agent = Agent(domain,
                  policies=[
                      MemoizationPolicy(),
                      KerasPolicy(batch_size=50, epochs=250, max_history=3)
                  ])
    data = agent.load_data(train_data)
    agent.train(data)
    agent.persist(model_path)
    return agent
Exemplo n.º 28
0
def run_online(interpreter,domain_file="./domain.yml",training_data_file='./backend/stories.md'):					  
    agent = Agent(domain_file,
                  policies=[MemoizationPolicy(max_history=2), KerasPolicy()],
                  interpreter=interpreter) 
    				  
    data = agent.load_data(training_data_file)
    agent.train(data,
                       batch_size=50,
                       epochs=200,
                       max_training_samples=300)				   
    online.serve_agent(agent)
    return agent
Exemplo n.º 29
0
def train_dialogue(domain_file="domain.yml",
                   model_path="models/dialogue",
                   training_data_file="stories.md"):
    agent = Agent(domain_file, policies=[MemoizationPolicy(), KerasPolicy()])

    agent.train(training_data_file,
                max_history=3,
                epochs=400,
                batch_size=10,
                validation_split=0.2)

    agent.persist(model_path)
Exemplo n.º 30
0
def train_dialog(dialog_training_data_file,
                 domain_file,
                 path_to_model='models/dialogue'):
    logging.basicConfig(level='INFO')
    agent = Agent(domain_file, policies=[MemoizationPolicy(max_history=1)])
    training_data = agent.load_data(dialog_training_data_file)
    agent.train(training_data,
                augmentation_factor=50,
                epochs=200,
                batch_size=10,
                validation_split=0.2)
    agent.persist(path_to_model)
Exemplo n.º 31
0
def train_dialogue(domain_file, model_path, training_folder):

    agent = Agent(domain_file, policies=[
            MemoizationPolicy(max_history=6),
            KerasPolicy(MaxHistoryTrackerFeaturizer(BinarySingleStateFeaturizer(),
                                                    max_history=6)),
            FallbackPolicy(nlu_threshold=0.8, core_threshold=0.3)])

    training_data = agent.load_data(training_folder)

    agent.train(training_data, epochs=100)
    agent.persist(model_path)
Exemplo n.º 32
0
def TrainCore():
    fallback = FallbackPolicy(fallback_action_name="utter_unclear",
                              core_threshold=0.2,
                              nlu_threshold=0.1)

    agent = Agent('domain.yml',
                  policies=[MemoizationPolicy(),
                            KerasPolicy(), fallback])
    training_data = agent.load_data('stories.md')

    agent.train(training_data, validation_split=0.0, epochs=500)
    agent.persist('models/dialogue')
Exemplo n.º 33
0
def default_processor(default_domain, default_nlg):
    agent = Agent(default_domain,
                  SimplePolicyEnsemble([AugmentedMemoizationPolicy()]),
                  interpreter=RegexInterpreter())

    training_data = 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)
Exemplo n.º 34
0
def train_dialogue_model(domain_file, stories_file, output_path,
                         nlu_model_path=None,
                         endpoints=None,
                         max_history=None,
                         dump_flattened_stories=False,
                         kwargs=None):
    if not kwargs:
        kwargs = {}

    action_endpoint = utils.read_endpoint_config(endpoints, "action_endpoint")

    fallback_args, kwargs = utils.extract_args(kwargs,
                                               {"nlu_threshold",
                                                "core_threshold",
                                                "fallback_action_name"})

    policies = [
        FallbackPolicy(
                fallback_args.get("nlu_threshold",
                                  DEFAULT_NLU_FALLBACK_THRESHOLD),
                fallback_args.get("core_threshold",
                                  DEFAULT_CORE_FALLBACK_THRESHOLD),
                fallback_args.get("fallback_action_name",
                                  DEFAULT_FALLBACK_ACTION)),
        MemoizationPolicy(
                max_history=max_history),
        KerasPolicy(
                MaxHistoryTrackerFeaturizer(BinarySingleStateFeaturizer(),
                                            max_history=max_history))]

    agent = Agent(domain_file,
                  action_endpoint=action_endpoint,
                  interpreter=nlu_model_path,
                  policies=policies)

    data_load_args, kwargs = utils.extract_args(kwargs,
                                                {"use_story_concatenation",
                                                 "unique_last_num_states",
                                                 "augmentation_factor",
                                                 "remove_duplicates",
                                                 "debug_plots"})

    training_data = agent.load_data(stories_file, **data_load_args)
    agent.train(training_data, **kwargs)
    agent.persist(output_path, dump_flattened_stories)

    return agent
Exemplo n.º 35
0
def train_dialogue(domain_file="domain.yml",
                   model_path="models/dialogue",
                   training_data_file="data/stories.md"):
    agent = Agent(domain_file,
                  policies=[MemoizationPolicy(max_history=3),
                            CustomPolicy()])

    training_data = agent.load_data(training_data_file)
    agent.train(
        training_data,
        epochs=400,
        batch_size=100,
        validation_split=0.2
    )

    agent.persist(model_path)
    return agent
Exemplo n.º 36
0
def train_dialogue(domain_file="mobile_domain.yml",
                   model_path="projects/dialogue",
                   training_data_file="data/mobile_story.md"):
    agent = Agent(domain_file,
                  policies=[MemoizationPolicy(), KerasPolicy()])

    training_data = agent.load_data(training_data_file)
    agent.train(
        training_data,
        epochs=200,
        batch_size=16,
        augmentation_factor=50,
        validation_split=0.2
    )

    agent.persist(model_path)
    return agent
Exemplo n.º 37
0
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 = 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 type(loaded.policy_ensemble) is type(
        agent.policy_ensemble)  # nopep8
    assert [type(p) for p in loaded.policy_ensemble.policies] == \
           [type(p) for p in agent.policy_ensemble.policies]
Exemplo n.º 38
0
def train_dialogue(domain_file="mobile_domain.yml",
                   model_path="models/dialogue",
                   training_data_file="data/mobile_edit_story.md"):

    fallback = FallbackPolicy(
        fallback_action_name="action_default_fallback",
        nlu_threshold=0.5,
        core_threshold=0.3
    )
    
    agent = Agent(domain_file,
                  policies=[MemoizationPolicy(max_history=5),
                            MobilePolicy(), fallback])

    training_data = agent.load_data(training_data_file)
    agent.train(
            training_data,
            epochs=500,
            batch_size=16,
            validation_split=0.2
    )

    agent.persist(model_path)
    return agent
Exemplo n.º 39
0
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

from rasa_core import utils
from rasa_core.agent import Agent
from rasa_core.policies.keras_policy import KerasPolicy
from rasa_core.policies.memoization import MemoizationPolicy

if __name__ == '__main__':
    utils.configure_colored_logging(loglevel="INFO")

    training_data_file = 'data/stories.md'
    model_path = 'models/dialogue'

    agent = Agent("concert_domain.yml",
                  policies=[MemoizationPolicy(), KerasPolicy()])

    training_data = agent.load_data(training_data_file)

    agent.train(
            training_data,
            augmentation_factor=50,
            max_history=2,
            epochs=500,
            batch_size=10,
            validation_split=0.2
    )

    agent.persist(model_path)