Exemple #1
0
 def test_write_training_data_with_rules(self):
     from kairon.shared.data.processor import MongoProcessor
     processor = MongoProcessor()
     training_data = processor.load_nlu(
         "test_load_from_path_yml_training_files")
     story_graph = processor.load_stories(
         "test_load_from_path_yml_training_files")
     domain = processor.load_domain(
         "test_load_from_path_yml_training_files")
     config = processor.load_config(
         "test_load_from_path_yml_training_files")
     http_action = processor.load_http_action(
         "test_load_from_path_yml_training_files")
     rules = processor.get_rules_for_training(
         "test_load_from_path_yml_training_files")
     training_data_path = Utility.write_training_data(
         training_data, domain, config, story_graph, rules, http_action)
     assert os.path.exists(training_data_path)
Exemple #2
0
 async def test_write_training_data(self):
     from kairon.shared.data.processor import MongoProcessor
     processor = MongoProcessor()
     await (processor.save_from_path(
         "./tests/testing_data/yml_training_files",
         bot="test_load_from_path_yml_training_files",
         user="******"))
     training_data = processor.load_nlu(
         "test_load_from_path_yml_training_files")
     story_graph = processor.load_stories(
         "test_load_from_path_yml_training_files")
     domain = processor.load_domain(
         "test_load_from_path_yml_training_files")
     config = processor.load_config(
         "test_load_from_path_yml_training_files")
     http_action = processor.load_http_action(
         "test_load_from_path_yml_training_files")
     training_data_path = Utility.write_training_data(
         training_data, domain, config, story_graph, None, http_action)
     assert os.path.exists(training_data_path)
Exemple #3
0
def train_model_for_bot(bot: str):
    """
    loads bot data from mongo into individual files for training

    :param bot: bot id
    :return: model path

    """
    processor = MongoProcessor()
    nlu = processor.load_nlu(bot)
    if not nlu.training_examples:
        raise AppException("Training data does not exists!")
    domain = processor.load_domain(bot)
    stories = processor.load_stories(bot)
    config = processor.load_config(bot)
    rules = processor.get_rules_for_training(bot)

    directory = Utility.write_training_data(nlu, domain, config, stories,
                                            rules)

    output = os.path.join(DEFAULT_MODELS_PATH, bot)
    if not os.path.exists(output):
        os.mkdir(output)
    model = train(domain=os.path.join(directory, DEFAULT_DOMAIN_PATH),
                  config=os.path.join(directory, DEFAULT_CONFIG_PATH),
                  training_files=os.path.join(directory, DEFAULT_DATA_PATH),
                  output=output,
                  core_additional_arguments={
                      "augmentation_factor": 100
                  },
                  force_training=True).model
    Utility.delete_directory(directory)
    del processor
    del nlu
    del domain
    del stories
    del config
    Utility.move_old_models(output, model)
    return model