:py:mod:`medcat.utils.checkpoint` ================================= .. py:module:: medcat.utils.checkpoint Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: medcat.utils.checkpoint.Checkpoint medcat.utils.checkpoint.CheckpointConfig medcat.utils.checkpoint.CheckpointManager Attributes ~~~~~~~~~~ .. autoapisummary:: medcat.utils.checkpoint.T medcat.utils.checkpoint.logger .. py:data:: T .. py:data:: logger .. py:class:: Checkpoint(dir_path, *, steps = DEFAULT_STEP, max_to_keep = DEFAULT_MAX_TO_KEEP) Bases: :py:obj:`object` The base class of checkpoint objects :param dir_path: The path to the parent directory of checkpoint files. :type dir_path: str :param steps: The number of processed sentences/documents before a checkpoint is saved (N.B.: A small number could result in error "no space left on device"), :type steps: int :param max_to_keep: The maximum number of checkpoints to keep (N.B.: A large number could result in error "no space left on device"). :type max_to_keep: int .. py:property:: steps :type: int .. py:property:: max_to_keep :type: int .. py:property:: count :type: int .. py:property:: dir_path :type: str .. py:attribute:: DEFAULT_STEP :value: 1000 .. py:attribute:: DEFAULT_MAX_TO_KEEP :value: 1 .. py:method:: __init__(dir_path, *, steps = DEFAULT_STEP, max_to_keep = DEFAULT_MAX_TO_KEEP) .. py:method:: from_latest(dir_path) :classmethod: Retrieve the latest checkpoint from the parent directory. :param dir_path: The path to the directory containing checkpoint files. :type dir_path: str :Returns: **T** -- A new checkpoint object. :raises Exception: If no checkpoint is found. .. py:method:: save(cdb, count) Save the CDB as the latest checkpoint. :param cdb: The MedCAT CDB object to be checkpointed. :type cdb: CDB :param count: The number of the finished steps. :type count: int .. py:method:: restore_latest_cdb() Restore the CDB from the latest checkpoint. :Returns: **cdb** (*CDB*) -- The MedCAT CDB object. :raises Exception: If no checkpoint is found. .. py:method:: _get_ckpt_file_paths(dir_path) :staticmethod: .. py:method:: _get_steps_and_count(file_path) :staticmethod: .. py:class:: CheckpointConfig Bases: :py:obj:`object` .. py:attribute:: output_dir :type: str :value: 'checkpoints' .. py:attribute:: steps :type: int .. py:attribute:: max_to_keep :type: int .. py:class:: CheckpointManager(name, checkpoint_config) Bases: :py:obj:`object` The class for managing checkpoints of specific training type and their configuration :param name: The name of the checkpoint manager (also used as the checkpoint base directory name). :type name: str :param checkpoint_config: The checkpoint config object. :type checkpoint_config: medcat.utils.checkpoint.CheckpointConfig .. py:method:: __init__(name, checkpoint_config) .. py:method:: create_checkpoint(dir_path = None) Create a new checkpoint inside the checkpoint base directory. :param dir_path: The path to the checkpoint directory. :type dir_path: str :Returns: **CheckPoint** -- A checkpoint object. .. py:method:: get_latest_checkpoint(base_dir_path = None) Retrieve the latest checkpoint from the checkpoint base directory. :param base_dir_path: The path to the directory containing checkpoint files. :type base_dir_path: string :Returns: **CheckPoint** -- A checkpoint object .. py:method:: get_latest_training_dir(base_dir_path) :classmethod: Retrieve the latest training directory containing all checkpoints. :param base_dir_path: The path to the directory containing all checkpointed trainings. :type base_dir_path: str :Returns: **str** -- The path to the latest training directory containing all checkpoints. :raises ValueError: If no checkpoint is found.