A Trainer is responsible for training a Model.

Typically you might create a configuration file specifying the model and training parameters and then use train rather than instantiating a Trainer yourself.

class str, cuda_device: Union[int, List] = -1)[source]

Bases: allennlp.common.registrable.Registrable

The base class for an AllenNLP trainer. It can do pretty much anything you want. Your subclass should implement train and also probably from_params.

default_implementation: str = 'default'
classmethod from_params(params: allennlp.common.params.Params, serialization_dir: str, recover: bool = False, cache_directory: str = None, cache_prefix: str = None)[source]

This is the automatic implementation of from_params. Any class that subclasses FromParams (or Registrable, which itself subclasses FromParams) gets this implementation for free. If you want your class to be instantiated from params in the “obvious” way – pop off parameters and hand them to your constructor with the same names – this provides that functionality.

If you need more complex logic in your from from_params method, you’ll have to implement your own method that overrides this one.

train(self) → Dict[str, Any][source]

Train a model and return the results.