Ejemplo n.º 1
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)
def test_agent_and_persist():
    policies = config.load('policies.yml')
    policies[0] = KerasPolicy(epochs=2)       # Keep training times low

    agent = Agent('domain.yml', policies=policies)
    training_data = agent.load_data('data/stories.md')
    agent.train(training_data, validation_split=0.0)
    agent.persist('./tests/models/dialogue')

    loaded = Agent.load('./tests/models/dialogue')

    assert agent.handle_text('/greet') is not None
    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
Ejemplo n.º 3
0
def train_dialogue(domain_file="restaurant_domain.yml",
				   model_path="models/dialogue",
				   training_data_file="data/babi_stories.md"):
	agent = Agent(domain_file,[MemoizationPolicy(max_history=3),
								RestaurantPolicy()])

	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
Ejemplo n.º 4
0
def train_dialogue(doman_file="../weather_domain.yml",
                   model_path="../models/dialogue",
                   training_data_file="../data/stories.md"):
    agent = Agent(domain=doman_file,
                  policies=[MemoizationPolicy(),
                            KerasPolicy()])

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

    agent.persist(model_path)
    return agent
Ejemplo n.º 5
0
def train_dialogue(domain_file="../../../models/domain.yml",
                   model_path="../../../models/models/dialogue",
                   training_data_file="../../../models/stories.md"):
    agent = Agent(domain_file,
                  policies=[
                      MemoizationPolicy(max_history=3),
                      FastSearchPolicy(batch_size=100,
                                       epochs=400,
                                       validation_split=0.2)
                  ])

    training_data = agent.load_data(training_data_file)
    agent.train(training_data)

    agent.persist(model_path)
    return agent
Ejemplo n.º 6
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(), fallback])

    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
Ejemplo n.º 7
0
def train_dialogue(domain_file='restaurant_domain.yml',
                   model_path="models/dialogue",
                   training_data_file='data/babi_stories.md'):
    featurizer = MaxHistoryTrackerFeaturizer(BinarySingleStateFeaturizer(),
                                             max_history=5)
    agent = Agent(
        domain_file,
        policies=[MemoizationPolicy(max_history=5),
                  KerasPolicy(featurizer)])
    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
Ejemplo n.º 8
0
def train_dialogue(domain_file="order_domain.yml",
                   model_path="models/dialogue",
                   training_data_file="data/babi_stories.md"):
    agent = Agent(domain_file,
                  policies=[MemoizationPolicy(), OrderPolicy()])

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

    agent.persist(model_path)
    return agent
Ejemplo n.º 9
0
def train_dialog(dialog_training_data_file,
                 domain_file,
                 path_to_model='models/dialogue'):
    logging.basicConfig(level='INFO')
    fallback = FallbackPolicy(fallback_action_name="utter_unclear",
                              core_threshold=0.3,
                              nlu_threshold=0.3)

    agent = Agent(domain_file,
                  policies=[
                      MemoizationPolicy(max_history=1),
                      KerasPolicy(epochs=200, batch_size=20), fallback
                  ])
    training_data = agent.load_data(dialog_training_data_file)
    agent.train(training_data, augmentation_factor=50, validation_split=0.2)
    agent.persist(path_to_model)
def train_dialogue(domain_file = 'restaurant_domain.yml',
					model_path = './models/dialogue',
					training_data_file = './data/core_stories.md'):
					
	featurizer = MaxHistoryTrackerFeaturizer(BinarySingleStateFeaturizer(), max_history=5)
	agent = Agent(domain_file, policies = [MemoizationPolicy(max_history = 5), KerasPolicy(featurizer)])
	
	agent.train(
				training_data_file,
				epochs = 300,
				batch_size = 50,
				validation_split = 0.2,
				augmentation_factor = 50)
				
	agent.persist(model_path)
	return agent
Ejemplo n.º 11
0
def train_babi_dm():
    training_data_file = 'data/babi_task5_trn_rasa_with_slots.md'
    model_path = 'models/policy/current'

    agent = Agent("../restaurant_domain.yml",
                  policies=[MemoizationPolicy(),
                            RestaurantPolicy()])

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

    agent.persist(model_path)
Ejemplo n.º 12
0
def train_dialog(domain_file, training_data_file, model_dir, interpreter):
    _agent = Agent(domain_file,
                   policies=[
                       MemoizationPolicy(max_history=6),
                       KerasPolicy(MaxHistoryTrackerFeaturizer(
                           BinarySingleStateFeaturizer(), max_history=6),
                                   augmentation_factor=50,
                                   epochs=300,
                                   batch_size=50,
                                   validation_split=0.2)
                   ],
                   interpreter=interpreter)
    _training_data = _agent.load_data(training_data_file)
    _agent.train(_training_data)
    _agent.persist(model_dir)
    return _agent
def train_dialogue(domain_file='bank_domain.yml',
                   model_path='./models/dialogue',
                   training_data_file='./data/stories.md'):

    agent = Agent(domain_file,
                  policies=[
                      MemoizationPolicy(),
                      KerasPolicy(max_history=3, epochs=150, batch_size=50),
                      AugmentedMemoizationPolicy(max_history=3)
                  ])
    data = agent.load_data(training_data_file)

    agent.train(data)

    agent.persist(model_path)
    return agent
Ejemplo n.º 14
0
def train_dialogue(domain_file="./dialog_data/domain.yml",
                   model_path="./models/current/dialogue",
                   training_data_file="wine_stories.md"):
    agent = Agent(
        domain_file,
        policies=[MemoizationPolicy(max_history=3),
                  KerasPolicy(), fallback])

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

    agent.persist(model_path)
    return agent
Ejemplo n.º 15
0
def train_dialogue(domain_file="restaurant_domain.yml",
                   model_path="models/dialogue",
                   training_data_file="data/restaurant_story.md"):
    agent = Agent(domain_file,
                  policies=[MemoizationPolicy(),
                            RestaurantPolicy()])

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

    agent.persist(model_path)
    return agent
Ejemplo n.º 16
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
Ejemplo n.º 17
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
Ejemplo n.º 18
0
def train_online(project='Lambton'):
    domain_file = "../Chatbots/projects/" + project + "/domain.json",
    model_path = "../Chatbots/projects/" + project + "models/dialogue",
    #training_data_file="projects/"+project+"/stories/stories.md"
    training_data_file = "../Chatbots/projects/" + project + "/stories/stories.md"

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

    agent.train_online(training_data_file,
                       input_channel=ConsoleInputChannel(),
                       max_history=3,
                       batch_size=50,
                       epochs=200,
                       max_training_samples=300)

    agent.persist(model_path)
    return agent
Ejemplo n.º 19
0
def train_dialog(
        dialog_training_data_file,
        domain_file,
        path_to_model='/home/tcs/chatbot_project_phase_1/models/dialogue'):
    logging.basicConfig(level='INFO')
    # first we will give the domain file, and policy to the agent.
    agent = Agent(domain_file, policies=[MemoizationPolicy(max_history=1)])
    # then we will give dialog training data file to it.
    training_data = agent.load_data(dialog_training_data_file)
    # here we will train the dialogue into the agent using the loaded the training data , define out values to the variables to 		# tweak the training
    agent.train(training_data,
                augmentation_factor=50,
                epochs=200,
                batch_size=10,
                validation_split=0.2)
    # then we save the dialogue model
    agent.persist(path_to_model)
Ejemplo n.º 20
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
Ejemplo n.º 21
0
def train_diag(domain_file="dynamo_domain.yml",
                          training_data_file='data/dialouge_stories/stories.md',
                          model_path='models/dialouge'):
    agent = Agent(domain_file,
                  policies=[MemoizationPolicy(max_history=2), KerasPolicy()])

    training_data = agent.load_data(training_data_file)

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

    agent.persist(model_path)

    return agent
def train_dialogue(domain_file='domain.yml',
                   model_path='./models/dialogue',
                   training_data_file='stories.md'):

    fallback = FallbackPolicy(fallback_action_name="action_default_fallback",
                              core_threshold=0.3,
                              nlu_threshold=0.3)

    agent = Agent(
        domain_file,
        policies=[MemoizationPolicy(max_history=4),
                  BotPolicy(), fallback])
    data = agent.load_data(training_data_file)
    agent.train(data, epochs=70, batch_size=8, validation_split=0.2)

    agent.persist(model_path)
    return agent
Ejemplo n.º 23
0
def train_dialogue_model(domain_file, stories_file, output_path,
                         use_online_learning, nlu_model_path, kwargs):
    agent = Agent(domain_file, policies=[MemoizationPolicy(), KerasPolicy()])

    if use_online_learning:
        if nlu_model_path:
            agent.interpreter = RasaNLUInterpreter(nlu_model_path)
        else:
            agent.interpreter = RegexInterpreter()
        agent.train_online(stories_file,
                           input_channel=ConsoleInputChannel(),
                           epochs=10,
                           model_path=output_path)
    else:
        agent.train(stories_file, validation_split=0.1, **kwargs)

    agent.persist(output_path)
Ejemplo n.º 24
0
def train_dialogue(domain_file = './config/domain.yml',
					model_path = './models/dialogue',
					training_data_file = './data/stories.md'):	

	fallback = FallbackPolicy(fallback_action_name="utter_fallback",
                          core_threshold=0.3,
                          nlu_threshold=0.3)	
					
	agent = Agent(domain_file, policies = [MemoizationPolicy(), KerasPolicy(),fallback])
	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
Ejemplo n.º 25
0
def train_online(project='Lambton'):
    domain_file = './Core/models/' + project + '/dialogue/domain.yml'
    model_path = './NLU/models/default/' + project,
    training_data_file = './Core/models/' + project + '/stories/stories.md'

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

    agent.train_online(training_data_file,
                       input_channel=ConsoleInputChannel(),
                       max_history=2,
                       batch_size=10,
                       epochs=250,
                       max_training_samples=300,
                       validation_split=0.2)

    agent.persist(model_path)
    return agent
Ejemplo n.º 26
0
def train_dm():
    training_data_file = 'stories.md'
    model_path = 'models/policy/current'

    agent = Agent("domain.yml",
                  policies=[MemoizationPolicy(), MusicPlayerPolicy()])

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

    agent.persist(model_path)
Ejemplo n.º 27
0
def train_tickets_order_dm():
    training_data_file = "../tickets/data/stories.md"
    domain_path = '../tickets/domain.yml'
    model_path = '../models/policy/current'

    agent = Agent(domain=domain_path,
                  policies=[MemoizationPolicy(),
                            TicketsPolicy()])

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

    agent.persist(model_path)
Ejemplo n.º 28
0
def train_dialogue(domain_id="default"):
    domain_file = "{}/{}/domain.yml".format(data_folder, domain_id)
    model_path = "{}/{}/dialogue".format(model_folder, domain_id)
    training_data_file = "{}/{}/stories.md".format(data_folder, domain_id)
    agent = Agent(
        domain_file,
        policies=[MemoizationPolicy(max_history=3),
                  IntelleiPolicy()])

    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
def train_dialogue(domain_file='weather_domain.yml',
                   model_path='./models/dialogue',
                   training_data_file='./data/stories.md'):
    agent = Agent(domain_file,
                  policies=[MemoizationPolicy(), WeatherPolicy()])

    agent.train(#TODO set the model parameters
                training_data_file,
                max_history = ,
                epochs = ,
                batch_size = ,
                augmentation_factor = ,
                validation_split = 
    )

    agent.persist(model_path)
    return agent	
Ejemplo n.º 30
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
Ejemplo n.º 31
0
def train_dialogue(domain_file='domain.yml',
                   model_path='./models/dialogue',
                   training_data_file='stories.md'):
    fallback = FallbackPolicy(fallback_action_name='utter_unclear',
                              core_threshold=0.2,
                              nlu_threshold=0.6)
    agent = Agent(domain_file,
                  policies=[MemoizationPolicy(),
                            KerasPolicy(), fallback])

    agent.train(training_data_file,
                epochs=300,
                batch_size=50,
                validation_split=0.2)

    agent.persist(model_path)
    return agent
def train_dialogue(domain_file='Sell4BidsBot_domain.yml',
                   model_path='./models/dialogue',
                   training_data_file='./data/stories.md'):

    fallback = FallbackPolicy(fallback_action_name="action_default_fallback",
                              core_threshold=0.3,
                              nlu_threshold=0.2)
    agent = Agent(domain_file,
                  policies=[
                      MemoizationPolicy(),
                      KerasPolicy(max_history=3, epochs=200, batch_size=50),
                      fallback
                  ])
    data = agent.load_data(training_data_file)
    agent.train(data)
    agent.persist(model_path)
    return agent
Ejemplo n.º 33
0
def train_dialogue(domain_file="domain.yml",
                   model_path="models/dialogue",
                   training_data_file="data/core/stories.md"):

    fallback = FallbackPolicy(fallback_action_name="action_default_fallback",
                              nlu_threshold=0.5,
                              core_threshold=0.3)

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

    training_data = agent.load_data(training_data_file)
    agent.train(training_data)

    agent.persist(model_path)
    return agent
Ejemplo n.º 34
0
def train_dialouge(domain_file='domain.yml',
                   output_model_path='./models/dialogue',
                   training_data_file='./data/stories.md'):

    fallback = FallbackPolicy(fallback_action_name='action_default_fallback',
                              core_threshold = 0.3,
                              nlu_threshold=0.1)

    agent = Agent(domain_file,
                  policies=[MemoizationPolicy(),
                            KerasPolicy(max_history=3, epochs=50, batch_size=2),
                            fallback])
    data = agent.load_data(training_data_file)
    agent.train(data)
    agent.persist(output_model_path)

    return agent
Ejemplo n.º 35
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]
Ejemplo n.º 36
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
Ejemplo n.º 37
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)