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 object

  • kwargs (Any) – Settings to be merged into the default Trainer config dict

name[source]

See above

config[source]

The config dict with the settings for the Trainer

checkpointer[source]

Saves the best model seen during training

log_manager[source]

Identifies when its time to log or evaluate on the valid set

log_writer[source]

Writes training statistics to file or TensorBoard

optimizer[source]

Updates model weights based on the loss

lr_scheduler[source]

Adjusts the learning rate over the course of training

batch_scheduler[source]

Returns batches from the DataLoaders in a particular order for training

__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 train

  • dataloaders (List[DictDataLoader]) – A list of DataLoaders. These will split into train, valid, and test splits based on the split 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 loaded

  • model (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

save(trainer_path)[source]

Save the trainer config to the specified file path in json format.

Parameters

trainer_path (str) – The path where trainer config and optimizer state should be saved.

Return type

None