allennlp.models.archival

Helper functions for archiving models and restoring archived models.

class allennlp.models.archival.Archive(model, config)[source]

Bases: tuple

config

Alias for field number 1

model

Alias for field number 0

allennlp.models.archival.archive_model(serialization_dir: str, weights: str = 'best.th', files_to_archive: typing.Dict[str, str] = None) → None[source]

Archive the model weights, its training configuration, and its vocabulary to model.tar.gz. Include the additional files_to_archive if provided.

Parameters:
serialization_dir: ``str``

The directory where the weights and vocabulary are written out.

weights: ``str``, optional (default=_DEFAULT_WEIGHTS)

Which weights file to include in the archive. The default is best.th.

files_to_archive: ``Dict[str, str]``, optional (default=None)

A mapping {hocon_key -> filename} of supplementary files to include in the archive.

allennlp.models.archival.load_archive(archive_file: str, cuda_device: int = -1, overrides: str = '', weights_file: str = None) → allennlp.models.archival.Archive[source]

Instantiates an Archive from an archived tar.gz file.

Parameters:
archive_file: ``str``

The archive file to load the model from.

weights_file: ``str``, optional (default = None)

The weights file to use. If unspecified, weights.th in the archive_file will be used.

cuda_device: ``int``, optional (default = -1)

If cuda_device is >= 0, the model will be loaded onto the corresponding GPU. Otherwise it will be loaded onto the CPU.

overrides: ``str``, optional (default = “”)

HOCON overrides to apply to the unarchived Params object.