示例#1
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)
    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,
    )
    Utility.delete_directory(directory)
    del processor
    del nlu
    del domain
    del stories
    del config
    return model
示例#2
0
 def test_write_training_data_with_rules(self):
     from kairon.data_processor.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)
示例#3
0
 async def test_write_training_data(self):
     from kairon.data_processor.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)
示例#4
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)

    directory = Utility.save_files(
        nlu.nlu_as_markdown().encode(),
        domain.as_yaml().encode(),
        stories.as_story_string().encode(),
        yaml.dump(config).encode(),
    )

    output = os.path.join(DEFAULT_MODELS_PATH, bot)
    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,
    )
    Utility.delete_directory(directory)
    del processor
    del nlu
    del domain
    del stories
    del config
    return model