deepcarskit.trainer¶
recbole.trainer.trainer¶
- class deepcarskit.trainer.trainer.CARSTrainer(config, model)¶
Bases:
recbole.trainer.trainer.Trainer
The basic Trainer for basic training and evaluation strategies in recommender systems. This class defines common functions for training and evaluation processes of most recommender system models, including fit(), evaluate(), resume_checkpoint() and some other features helpful for model training and evaluation.
Generally speaking, this class can serve most recommender system models, If the training process of the model is to simply optimize a single loss without involving any complex training strategies, such as adversarial learning, pre-training and so on.
Initializing the Trainer needs two parameters: config and model. config records the parameters information for controlling training and evaluation, such as learning_rate, epochs, eval_step and so on. model is the instantiated object of a Model Class.
- evaluate(eval_data, load_best_model=True, model_file=None, show_progress=False)¶
Evaluate the model based on the eval data.
- Args:
eval_data (DataLoader): the eval data load_best_model (bool, optional): whether load the best model in the training process, default: True.
It should be set True, if users want to test the model after training.
- model_file (str, optional): the saved model file, default: None. If users want to test the previously
trained model file, they can set this parameter.
show_progress (bool): Show the progress of evaluate epoch. Defaults to
False
.- Returns:
dict: eval result, key is the eval metric and value in the corresponding metric value.
- class deepcarskit.trainer.CARSTrainer(config, model)¶
Bases:
recbole.trainer.trainer.Trainer
The basic Trainer for basic training and evaluation strategies in recommender systems. This class defines common functions for training and evaluation processes of most recommender system models, including fit(), evaluate(), resume_checkpoint() and some other features helpful for model training and evaluation.
Generally speaking, this class can serve most recommender system models, If the training process of the model is to simply optimize a single loss without involving any complex training strategies, such as adversarial learning, pre-training and so on.
Initializing the Trainer needs two parameters: config and model. config records the parameters information for controlling training and evaluation, such as learning_rate, epochs, eval_step and so on. model is the instantiated object of a Model Class.
- evaluate(eval_data, load_best_model=True, model_file=None, show_progress=False)¶
Evaluate the model based on the eval data.
- Args:
eval_data (DataLoader): the eval data load_best_model (bool, optional): whether load the best model in the training process, default: True.
It should be set True, if users want to test the model after training.
- model_file (str, optional): the saved model file, default: None. If users want to test the previously
trained model file, they can set this parameter.
show_progress (bool): Show the progress of evaluate epoch. Defaults to
False
.- Returns:
dict: eval result, key is the eval metric and value in the corresponding metric value.
- class deepcarskit.trainer.KGATTrainer(config, model)¶
Bases:
recbole.trainer.trainer.Trainer
KGATTrainer is designed for KGAT, which is a knowledge-aware recommendation method.
- class deepcarskit.trainer.KGTrainer(config, model)¶
Bases:
recbole.trainer.trainer.Trainer
KGTrainer is designed for Knowledge-aware recommendation methods. Some of these models need to train the recommendation related task and knowledge related task alternately.
- class deepcarskit.trainer.S3RecTrainer(config, model)¶
Bases:
recbole.trainer.trainer.PretrainTrainer
S3RecTrainer is designed for S3Rec, which is a self-supervised learning based sequential recommenders. It includes two training stages: pre-training ang fine-tuning.
- fit(train_data, valid_data=None, verbose=True, saved=True, show_progress=False, callback_fn=None)¶
Train the model based on the train data and the valid data.
- Args:
train_data (DataLoader): the train data valid_data (DataLoader, optional): the valid data, default: None.
If it’s None, the early_stopping is invalid.
verbose (bool, optional): whether to write training and evaluation information to logger, default: True saved (bool, optional): whether to save the model parameters, default: True show_progress (bool): Show the progress of training epoch and evaluate epoch. Defaults to
False
. callback_fn (callable): Optional callback function executed at end of epoch.Includes (epoch_idx, valid_score) input arguments.
- Returns:
(float, dict): best valid score and best valid result. If valid_data is None, it returns (-1, None)
- class deepcarskit.trainer.Trainer(config, model)¶
Bases:
recbole.trainer.trainer.AbstractTrainer
The basic Trainer for basic training and evaluation strategies in recommender systems. This class defines common functions for training and evaluation processes of most recommender system models, including fit(), evaluate(), resume_checkpoint() and some other features helpful for model training and evaluation.
Generally speaking, this class can serve most recommender system models, If the training process of the model is to simply optimize a single loss without involving any complex training strategies, such as adversarial learning, pre-training and so on.
Initializing the Trainer needs two parameters: config and model. config records the parameters information for controlling training and evaluation, such as learning_rate, epochs, eval_step and so on. model is the instantiated object of a Model Class.
- evaluate(eval_data, load_best_model=True, model_file=None, show_progress=False)¶
Evaluate the model based on the eval data.
- Args:
eval_data (DataLoader): the eval data load_best_model (bool, optional): whether load the best model in the training process, default: True.
It should be set True, if users want to test the model after training.
- model_file (str, optional): the saved model file, default: None. If users want to test the previously
trained model file, they can set this parameter.
show_progress (bool): Show the progress of evaluate epoch. Defaults to
False
.- Returns:
collections.OrderedDict: eval result, key is the eval metric and value in the corresponding metric value.
- fit(train_data, valid_data=None, verbose=True, saved=True, show_progress=False, callback_fn=None)¶
Train the model based on the train data and the valid data.
- Args:
train_data (DataLoader): the train data valid_data (DataLoader, optional): the valid data, default: None.
If it’s None, the early_stopping is invalid.
verbose (bool, optional): whether to write training and evaluation information to logger, default: True saved (bool, optional): whether to save the model parameters, default: True show_progress (bool): Show the progress of training epoch and evaluate epoch. Defaults to
False
. callback_fn (callable): Optional callback function executed at end of epoch.Includes (epoch_idx, valid_score) input arguments.
- Returns:
(float, dict): best valid score and best valid result. If valid_data is None, it returns (-1, None)
- resume_checkpoint(resume_file)¶
Load the model parameters information and training information.
- Args:
resume_file (file): the checkpoint file