snorkel.classification.Trainer¶
-
class
snorkel.classification.
Trainer
(name=None, **kwargs)[source]¶ Bases:
object
A class for training a MultitaskClassifier.
- Parameters
name (
Optional
[str
]) – An optional name for this trainer objectkwargs (
Any
) – Settings to be merged into the default Trainer config dict
-
__init__
(name=None, **kwargs)[source]¶ Initialize self. See help(type(self)) for accurate signature.
- Return type
None
Methods
__init__
([name])Initialize self.
fit
(model, dataloaders)Train a MultitaskClassifier.
load
(trainer_path, model)Load trainer config and optimizer state from the specified json file path to the trainer object.
save
(trainer_path)Save the trainer config to the specified file path in json format.
-
fit
(model, dataloaders)[source]¶ Train a MultitaskClassifier.
- Parameters
model (
MultitaskClassifier
) – The model to traindataloaders (
List
[DictDataLoader
]) – A list of DataLoaders. These will split into train, valid, and test splits based on thesplit
attribute of the DataLoaders.
- Return type
None
-
load
(trainer_path, model)[source]¶ Load trainer config and optimizer state from the specified json file path to the trainer object. The optimizer state is stored, too. However, it only makes sense if loaded with the correct model again.
- Parameters
trainer_path (
str
) – The path to the saved trainer config to be loadedmodel (
Optional
[MultitaskClassifier
]) – MultitaskClassifier for which the optimizer has been set. Parameters of optimizer must fit to model parameters. This model shall be the model which was fit by the stored Trainer.
Example
Saving model and corresponding trainer: >>> model.save(‘./my_saved_model_file’) # doctest: +SKIP >>> trainer.save(‘./my_saved_trainer_file’) # doctest: +SKIP Now we can resume training and load the saved model and trainer into new model and trainer objects: >>> new_model.load(‘./my_saved_model_file’) # doctest: +SKIP >>> new_trainer.load(‘./my_saved_trainer_file’, model=new_model) # doctest: +SKIP >>> new_trainer.fit(…) # doctest: +SKIP
- Return type
None