pyabsa.framework.instructor_class.instructor_template

Module Contents

Classes

BaseTrainingInstructor

Functions

get_resume_checkpoint(config)

class pyabsa.framework.instructor_class.instructor_template.BaseTrainingInstructor(config)[source]
_reset_params()[source]

Reset the parameters of the model before training.

_reload_model_state_dict(ckpt='./init_state_dict.bin')[source]

Reload the model state dictionary from a checkpoint file. :param ckpt: The path to the checkpoint file.

load_cache_dataset(**kwargs)[source]

Load the dataset from cache if it exists and not set to overwrite the cache. Otherwise, return None. :param kwargs: Additional keyword arguments. :return: The path to the cache file if it exists. Otherwise, return None.

save_cache_dataset(cache_path=None, **kwargs)[source]

Save the dataset to cache for faster loading in the future. :param kwargs: Additional arguments for saving the dataset cache. :param cache_path: The path to the cache file. :return: The path to the saved cache file.

_prepare_dataloader()[source]

Prepares the data loaders for training, validation, and testing.

_prepare_env()[source]

Prepares the environment for training, including setting the tokenizer and embedding matrix, removing the initial state dictionary file if it exists, and setting up the model on the appropriate device.

_train(criterion)[source]

Train the model on a given criterion.

Parameters:

criterion – The loss function used to train the model.

Returns:

If there is only one validation dataloader, return the training results. If there are more than one validation dataloaders, perform k-fold cross-validation and return the results.

abstract _init_misc()[source]

Initialize miscellaneous settings specific to the subclass implementation. This method should be implemented in a subclass.

abstract _cache_or_load_dataset()[source]

Cache or load the dataset. This method should be implemented in a subclass.

abstract _train_and_evaluate(criterion)[source]

Train and evaluate the model. This method should be implemented in a subclass.

abstract _k_fold_train_and_evaluate(criterion)[source]

Train and evaluate the model using k-fold cross validation. This method should be implemented in a subclass.

abstract _evaluate_acc_f1(test_dataloader)[source]

Evaluate the accuracy and F1 score of the model. This method should be implemented in a subclass.

abstract _load_dataset_and_prepare_dataloader()[source]

Load the dataset and prepare the dataloader. This method should be implemented in a subclass.

_resume_from_checkpoint()[source]

Resumes training from a checkpoint if a valid checkpoint path is provided in the configuration file, by loading the model, state dictionary, and configuration from the checkpoint files.

pyabsa.framework.instructor_class.instructor_template.get_resume_checkpoint(config)[source]