def zipped_nlu_model(): spacy_config_path = "sample_configs/config_spacy.yml" cfg = config.load(spacy_config_path) trainer = Trainer(cfg) td = training_data.load_data(DEFAULT_DATA_PATH) trainer.train(td) trainer.persist("test_models", project_name="test_model_spacy_sklearn") model_dir_list = os.listdir(TEST_MODEL_PATH) # directory name of latest model model_dir = sorted(model_dir_list)[-1] # path of that directory model_path = os.path.join(TEST_MODEL_PATH, model_dir) zip_path = zip_folder(model_path) return zip_path
def zipped_nlu_model(): spacy_config_path = "sample_configs/config_pretrained_embeddings_spacy.yml" cfg = config.load(spacy_config_path) trainer = Trainer(cfg) td = training_data.load_data(DEFAULT_DATA_PATH) trainer.train(td) trainer.persist("test_models", project_name="test_model_pretrained_embeddings") model_dir_list = os.listdir(TEST_MODEL_PATH) # directory name of latest model model_dir = sorted(model_dir_list)[-1] # path of that directory model_path = os.path.join(TEST_MODEL_PATH, model_dir) zip_path = zip_folder(model_path) return zip_path
def train(self, request): # if not set will use the default project name, e.g. "default" project = parameter_or_default(request, "project", default=None) # if set will not generate a model name but use the passed one model_name = parameter_or_default(request, "model", default=None) try: model_config, data = self.extract_data_and_config(request) except Exception as e: request.setResponseCode(400) returnValue(json_to_string({"error": "{}".format(e)})) data_file = dump_to_data_file(data) request.setHeader('Content-Type', 'application/zip') try: request.setResponseCode(200) request.setHeader("Content-Disposition", "attachment") path_to_model = yield self.data_router.start_train_process( data_file, project, RasaNLUModelConfig(model_config), model_name) zipped_path = utils.zip_folder(path_to_model) zip_content = io.open(zipped_path, 'r+b').read() return returnValue(zip_content) except MaxTrainingError as e: request.setResponseCode(403) returnValue(json_to_string({"error": "{}".format(e)})) except InvalidProjectError as e: request.setResponseCode(404) returnValue(json_to_string({"error": "{}".format(e)})) except TrainingException as e: request.setResponseCode(500) returnValue(json_to_string({"error": "{}".format(e)}))