ModelSerializer#
- class openstef_models.mixins.model_serializer.ModelSerializer(**data: Any) None[source]
Bases:
BaseConfig,ABCAbstract base class for model serialization.
Defines the interface for converting trained models to and from binary format. Implementations handle the mechanics of serializing model state using specific libraries like joblib, pickle, or custom formats.
The serializer ensures that all stateful components of a model can be persisted and restored, enabling model reuse across sessions and deployments.
Invariants
Serializing and deserializing a model preserves its state
The extension attribute specifies the file extension for saved models
Deserialized models are functionally equivalent to their original state
See also
JoblibModelSerializer: Concrete implementation using joblib.
- Parameters:
data (
Any)
- abstractmethod serialize(model: object, file: BinaryIO) None[source]
Write a model’s state to a binary file.
Converts the model’s internal state to a binary format and writes it to the provided file object. The serialization must capture all information needed to restore the model to its current state.
- abstractmethod deserialize(file: BinaryIO) object[source]
Read a model’s state from a binary file and restore it.
Loads the model state from the binary file and applies it to the provided model instance. The model should be functionally equivalent to the state when it was serialized.
- model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': False, 'extra': 'ignore', 'protected_namespaces': ()}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].