SerializableModelMixin¶
- class SerializableModelMixin[source]¶
Bases:
objectProvides convenient methods for saving and loading models via dill serialization.
Warning
The legacy
save()andload()methods are deprecated in v0.9.0 and will be removed in a future release. Please useto_dill()andfrom_dill()respectively.Methods
- classmethod from_dill(file_name)[source]¶
Loads a model from a file. If the loaded model is not an instance of the class whose method was called, then a warning is raised. Nevertheless, the loaded model may be a valid model.
Replaces the deprecated
load()method.- Parameters:
file_name (str) – Path to the dill file containing the serialized model.
- Returns:
An instance of the model loaded from disk.
- Return type:
Example
loaded = MyModel.from_dill('model_state.dill')
- classmethod load(*args)[source]¶
Backwards compatibility with
from_dill(), deprecated in v0.9.0.- Return type:
- to_dill(file_name)[source]¶
Saves this model to the specified file. Internally, the model is serialized via
dill. All parameters are saved, including a primitive instance that is referenced by internal objects. That means if a model is loaded from a file and is used, for instance, for inference, the same primitive will be used even if a cloud primitive was used.Warning
Replaces the deprecated
save()method.- Parameters:
file_name (str) – Path where the serialized model will be written.
Example
model.to_dill('model_state.dill')