class allennlp.models.model.Model, optimizer: torch.optim.optimizer.Optimizer, iterator:, train_dataset: typing.Iterable[], validation_dataset: typing.Union[typing.Iterable[], NoneType] = None, patience: typing.Union[int, NoneType] = None, validation_metric: str = '-loss', validation_iterator: = None, shuffle: bool = True, num_epochs: int = 20, serialization_dir: typing.Union[str, NoneType] = None, num_serialized_models_to_keep: int = 20, keep_serialized_model_every_num_seconds: int = None, model_save_interval: float = None, cuda_device: typing.Union[int, typing.List] = -1, grad_norm: typing.Union[float, NoneType] = None, grad_clipping: typing.Union[float, NoneType] = None, learning_rate_scheduler: typing.Union[, NoneType] = None, momentum_scheduler: typing.Union[, NoneType] = None, summary_interval: int = 100, histogram_interval: int = None, should_log_parameter_statistics: bool = True, should_log_learning_rate: bool = False, log_batch_size_period: typing.Union[int, NoneType] = None, moving_average: typing.Union[, NoneType] = None) → None[source]


batch_loss(batch_group: typing.List[typing.Dict[str, typing.Union[torch.Tensor, typing.Dict[str, torch.Tensor]]]], for_training: bool) → torch.Tensor[source]

Does a forward pass on the given batches and returns the loss value in the result. If for_training is True also applies regularization penalty.

classmethod from_params(model: allennlp.models.model.Model, serialization_dir: str, iterator:, train_data: typing.Iterable[], validation_data: typing.Union[typing.Iterable[], NoneType], params: allennlp.common.params.Params, validation_iterator: = None) →[source]
rescale_gradients() → typing.Union[float, NoneType][source]
train() → typing.Dict[str, typing.Any][source]

Trains the supplied model with the supplied parameters.


Bases: tuple

We would like to avoid having complex instantiation logic taking place in Trainer.from_params. This helper class has a from_params that instantiates a model, loads train (and possibly validation and test) datasets, constructs a Vocabulary, creates data iterators, and handles a little bit of bookkeeping. If you’re creating your own alternative training regime you might be able to use this.

static from_params(params: allennlp.common.params.Params, serialization_dir: str, recover: bool = False) →[source]

Alias for field number 1


Alias for field number 0


Alias for field number 6


Alias for field number 4


Alias for field number 2


Alias for field number 3


Alias for field number 5