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
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
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)
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
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
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
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'))
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
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)
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
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
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)
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())
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
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
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)
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
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) ) )
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)
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)
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)
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
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})
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
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
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
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)
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)
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 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')
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
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
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
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]
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
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)