def save(self, dirpath=None): """ Saves picked automaton object into dirpath. Parameters ---------- dirpath : str path to directory where model will be saved Returns ------- None """ if self.model_ is None: raise ValueError( "No model found, use fit() to train or load() pretrained.") if not os.path.exists(dirpath): os.makedirs(dirpath) log.info("Saving model...") model_file = os.path.join(dirpath, "dictionary-ner.pkl") joblib.dump(self.model_, model_file) write_param_file(self.get_params(), os.path.join(dirpath, "params.yaml"))
def save(self, dirpath): """ Saves model to local disk, given a dirpath Parameters ----------- dirpath : str a directory where model artifacts will be saved. Model saves a weights.h5 weights file, a params.json parameter file, and a preprocessor.pkl preprocessor file. Returns ------- None """ if self.model_ is None or self.preprocessor_ is None: raise ValueError( "No model artifacts to save, either run fit() to train or load() a trained model" ) if not os.path.exists(dirpath): os.makedirs(dirpath) weights_file = os.path.join(dirpath, "weights.h5") params_file = os.path.join(dirpath, "params.json") preprocessor_file = os.path.join(dirpath, "preprocessor.pkl") save_model(self.model_, weights_file, params_file) self.preprocessor_.save(preprocessor_file) write_param_file(self.get_params(), os.path.join(dirpath, "params.yaml"))
def save(self, dirpath): """ Save trained FLAIR NER model at dirpath. Parameters ---------- dirpath : str path to model directory. Returns ------- None """ if self.model_ is None: raise ValueError("Cannot save empty model, run fit() to train or load() pretrained model.") if not(os.path.exists(dirpath) and os.path.isdir(dirpath)): os.makedirs(dirpath) self.model_.save(os.path.join(dirpath, "final-model.pt")) write_param_file(self.get_params(), os.path.join(dirpath, "params.yaml"))
def save(self, dirpath): """ Save trained SpaCy NER model at dirpath. Parameters ---------- dirpath : str path to model directory. Returns ------- None """ if self.model_ is None: raise ValueError( "Cannot save empty model, run fit() to train or load() pretrained model" ) log.info("Saving model...") if not os.path.exists(dirpath): os.makedirs(dirpath) self.model_.to_disk(dirpath) write_param_file(self.get_params(), os.path.join(dirpath, "params.yaml"))
def save(dirpath): write_param_file(self.get_params(), os.path.join(dirpath, "params.yaml"))