def _fallback_model(self): meta = Metadata( { "pipeline": [{ "name": "KeywordIntentClassifier", "class": utils.module_path_from_object(KeywordIntentClassifier()) }] }, "") return Interpreter.create(meta, self._component_builder)
def persist(self, path: Text, persistor: Optional[Persistor] = None, project_name: Text = None, fixed_model_name: Text = None) -> Text: """Persist all components of the pipeline to the passed path. Returns the directory of the persisted model.""" timestamp = datetime.datetime.now().strftime('%Y%m%d-%H%M%S') metadata = { "language": self.config["language"], "adapter": self.config['adapter'], "pipeline": [], } if project_name is None: project_name = "default" if fixed_model_name: model_name = fixed_model_name else: model_name = "model_" + timestamp path = make_path_absolute(path) dir_name = os.path.join(path, project_name, model_name) create_dir(dir_name) if self.training_data: metadata.update(self.training_data.persist(dir_name)) for i, component in enumerate(self.pipeline): file_name = self._file_name(i, component.name) update = component.persist(file_name, dir_name) component_meta = component.component_config if update: component_meta.update(update) component_meta["class"] = utils.module_path_from_object(component) metadata["pipeline"].append(component_meta) Metadata(metadata, dir_name).persist(dir_name) if persistor is not None: persistor.persist(dir_name, model_name, project_name) logger.info("Successfully saved model into " "'{}'".format(os.path.abspath(dir_name))) return dir_name
def fallback_model(component_builder: ComponentBuilder): meta = Metadata( { "pipeline": [ { "name": "KeywordIntentClassifier", "class": utils.module_path_from_object( KeywordIntentClassifier() ), } ] }, "", ) interpreter = Interpreter.create(meta, component_builder) return NLUModel(FALLBACK_MODEL_NAME, interpreter)
def persist( self, path: Text, persistor: Optional[Persistor] = None, fixed_model_name: Text = None, persist_nlu_training_data: bool = False, ) -> Text: """Persist all components of the pipeline to the passed path. Returns the directory of the persisted model.""" timestamp = datetime.datetime.now().strftime("%Y%m%d-%H%M%S") metadata = {"language": self.config["language"], "pipeline": []} if fixed_model_name: model_name = fixed_model_name else: model_name = NLU_MODEL_NAME_PREFIX + timestamp path = os.path.abspath(path) dir_name = os.path.join(path, model_name) rasa.shared.utils.io.create_directory(dir_name) if self.training_data and persist_nlu_training_data: metadata.update(self.training_data.persist(dir_name)) for i, component in enumerate(self.pipeline): file_name = self._file_name(i, component.name) update = component.persist(file_name, dir_name) component_meta = component.component_config if update: component_meta.update(update) component_meta["class"] = utils.module_path_from_object(component) metadata["pipeline"].append(component_meta) Metadata(metadata, dir_name).persist(dir_name) if persistor is not None: persistor.persist(dir_name, model_name) logger.info( "Successfully saved model into '{}'".format(os.path.abspath(dir_name)) ) return dir_name