mwptoolkit.trainer.supervised_trainer¶
- class mwptoolkit.trainer.supervised_trainer.BertTDTrainer(config, model, dataloader, evaluator)[source]¶
Bases:
SupervisedTrainer
- Parameters
config (config) – An instance object of Config, used to record parameter information.
model (Model) – An object of deep-learning model.
dataloader (Dataloader) – dataloader object.
evaluator (Evaluator) – evaluator object.
expected that config includes these parameters below:
learning_rate (float): learning rate of model
train_batch_size (int): the training batch size.
epoch_nums (int): number of epochs.
trained_model_path (str): a path of file which is used to save parameters of best model.
checkpoint_path (str): a path of file which is used save checkpoint of training progress.
output_path (str|None): a path of a json file which is used to save test output infomation fo model.
resume (bool): start training from last checkpoint.
validset_divide (bool): whether to split validset. if True, the dataset is split to trainset-validset-testset. if False, the dataset is split to trainset-testset.
test_step (int): the epoch number of training after which conducts the evaluation on test.
best_folds_accuracy (list|None): when running k-fold cross validation, this keeps the accuracy of folds that already run.
- class mwptoolkit.trainer.supervised_trainer.EPTTrainer(config, model, dataloader, evaluator)[source]¶
Bases:
AbstractTrainer
ept trainer, used to implement training, testing, parameter searching for deep-learning model EPT.
example of instantiation:
>>> trainer = EPTTrainer(config, model, dataloader, evaluator)
for training:
>>> trainer.fit()
for testing:
>>> trainer.test()
for parameter searching:
>>> trainer.param_search()
- Parameters
config (config) – An instance object of Config, used to record parameter information.
model (Model) – An object of deep-learning model.
dataloader (Dataloader) – dataloader object.
evaluator (Evaluator) – evaluator object.
expected that config includes these parameters below:
learning_rate (float): learning rate of model
train_batch_size (int): the training batch size.
epoch_nums (int): number of epochs.
gradient_accumulation_steps (int): gradient accumulation steps.
epoch_warmup (int): epoch warmup.
fix_encoder_embedding (bool): whether require gradient of embedding module of encoder
trained_model_path (str): a path of file which is used to save parameters of best model.
checkpoint_path (str): a path of file which is used save checkpoint of training progress.
output_path (str|None): a path of a json file which is used to save test output infomation fo model.
resume (bool): start training from last checkpoint.
validset_divide (bool): whether to split validset. if True, the dataset is split to trainset-validset-testset. if False, the dataset is split to trainset-testset.
test_step (int): the epoch number of training after which conducts the evaluation on test.
best_folds_accuracy (list|None): when running k-fold cross validation, this keeps the accuracy of folds that already run.
- _normalize_gradients(*parameters)[source]¶
Normalize gradients (as in NVLAMB optimizer)
- Parameters
parameters – List of parameters whose gradient will be normalized.
- Returns
Frobenious Norm before applying normalization.
- class mwptoolkit.trainer.supervised_trainer.GTSTrainer(config, model, dataloader, evaluator)[source]¶
Bases:
AbstractTrainer
gts trainer, used to implement training, testing, parameter searching for deep-learning model GTS.
example of instantiation:
>>> trainer = GTSTrainer(config, model, dataloader, evaluator)
for training:
>>> trainer.fit()
for testing:
>>> trainer.test()
for parameter searching:
>>> trainer.param_search()
- Parameters
config (config) – An instance object of Config, used to record parameter information.
model (Model) – An object of deep-learning model.
dataloader (Dataloader) – dataloader object.
evaluator (Evaluator) – evaluator object.
expected that config includes these parameters below:
learning_rate (float): learning rate of model.
embedding_learning_rate (float): learning rate of embedding module.
train_batch_size (int): the training batch size.
step_size (int): step_size of scheduler.
epoch_nums (int): number of epochs.
trained_model_path (str): a path of file which is used to save parameters of best model.
checkpoint_path (str): a path of file which is used save checkpoint of training progress.
output_path (str|None): a path of a json file which is used to save test output infomation fo model.
resume (bool): start training from last checkpoint.
validset_divide (bool): whether to split validset. if True, the dataset is split to trainset-validset-testset. if False, the dataset is split to trainset-testset.
test_step (int): the epoch number of training after which conducts the evaluation on test.
best_folds_accuracy (list|None): when running k-fold cross validation, this keeps the accuracy of folds that already run.
- class mwptoolkit.trainer.supervised_trainer.Graph2TreeTrainer(config, model, dataloader, evaluator)[source]¶
Bases:
GTSTrainer
graph2tree trainer, used to implement training, testing, parameter searching for deep-learning model Graph2Tree.
example of instantiation:
>>> trainer = Graph2TreeTrainer(config, model, dataloader, evaluator)
for training:
>>> trainer.fit()
for testing:
>>> trainer.test()
for parameter searching:
>>> trainer.param_search()
- Parameters
config (config) – An instance object of Config, used to record parameter information.
model (Model) – An object of deep-learning model.
dataloader (Dataloader) – dataloader object.
evaluator (Evaluator) – evaluator object.
expected that config includes these parameters below:
learning_rate (float): learning rate of model.
embedding_learning_rate (float): learning rate of embedding module.
train_batch_size (int): the training batch size.
step_size (int): step_size of scheduler.
epoch_nums (int): number of epochs.
trained_model_path (str): a path of file which is used to save parameters of best model.
checkpoint_path (str): a path of file which is used save checkpoint of training progress.
output_path (str|None): a path of a json file which is used to save test output infomation fo model.
resume (bool): start training from last checkpoint.
validset_divide (bool): whether to split validset. if True, the dataset is split to trainset-validset-testset. if False, the dataset is split to trainset-testset.
test_step (int): the epoch number of training after which conducts the evaluation on test.
best_folds_accuracy (list|None): when running k-fold cross validation, this keeps the accuracy of folds that already run.
- class mwptoolkit.trainer.supervised_trainer.HMSTrainer(config, model, dataloader, evaluator)[source]¶
Bases:
GTSTrainer
- Parameters
config (config) – An instance object of Config, used to record parameter information.
model (Model) – An object of deep-learning model.
dataloader (Dataloader) – dataloader object.
evaluator (Evaluator) – evaluator object.
expected that config includes these parameters below:
learning_rate (float): learning rate of model.
embedding_learning_rate (float): learning rate of embedding module.
train_batch_size (int): the training batch size.
step_size (int): step_size of scheduler.
epoch_nums (int): number of epochs.
trained_model_path (str): a path of file which is used to save parameters of best model.
checkpoint_path (str): a path of file which is used save checkpoint of training progress.
output_path (str|None): a path of a json file which is used to save test output infomation fo model.
resume (bool): start training from last checkpoint.
validset_divide (bool): whether to split validset. if True, the dataset is split to trainset-validset-testset. if False, the dataset is split to trainset-testset.
test_step (int): the epoch number of training after which conducts the evaluation on test.
best_folds_accuracy (list|None): when running k-fold cross validation, this keeps the accuracy of folds that already run.
- class mwptoolkit.trainer.supervised_trainer.MWPBertTrainer(config, model, dataloader, evaluator)[source]¶
Bases:
GTSTrainer
- Parameters
config (config) – An instance object of Config, used to record parameter information.
model (Model) – An object of deep-learning model.
dataloader (Dataloader) – dataloader object.
evaluator (Evaluator) – evaluator object.
expected that config includes these parameters below:
learning_rate (float): learning rate of model.
embedding_learning_rate (float): learning rate of embedding module.
train_batch_size (int): the training batch size.
step_size (int): step_size of scheduler.
epoch_nums (int): number of epochs.
trained_model_path (str): a path of file which is used to save parameters of best model.
checkpoint_path (str): a path of file which is used save checkpoint of training progress.
output_path (str|None): a path of a json file which is used to save test output infomation fo model.
resume (bool): start training from last checkpoint.
validset_divide (bool): whether to split validset. if True, the dataset is split to trainset-validset-testset. if False, the dataset is split to trainset-testset.
test_step (int): the epoch number of training after which conducts the evaluation on test.
best_folds_accuracy (list|None): when running k-fold cross validation, this keeps the accuracy of folds that already run.
- class mwptoolkit.trainer.supervised_trainer.MultiEncDecTrainer(config, model, dataloader, evaluator)[source]¶
Bases:
GTSTrainer
multiencdec trainer, used to implement training, testing, parameter searching for deep-learning model MultiE&D.
example of instantiation:
>>> trainer = MultiEncDecTrainer(config, model, dataloader, evaluator)
for training:
>>> trainer.fit()
for testing:
>>> trainer.test()
for parameter searching:
>>> trainer.param_search()
- Parameters
config (config) – An instance object of Config, used to record parameter information.
model (Model) – An object of deep-learning model.
dataloader (Dataloader) – dataloader object.
evaluator (Evaluator) – evaluator object.
expected that config includes these parameters below:
learning_rate (float): learning rate of model.
train_batch_size (int): the training batch size.
step_size (int): step_size of scheduler.
epoch_nums (int): number of epochs.
trained_model_path (str): a path of file which is used to save parameters of best model.
checkpoint_path (str): a path of file which is used save checkpoint of training progress.
output_path (str|None): a path of a json file which is used to save test output infomation fo model.
resume (bool): start training from last checkpoint.
validset_divide (bool): whether to split validset. if True, the dataset is split to trainset-validset-testset. if False, the dataset is split to trainset-testset.
test_step (int): the epoch number of training after which conducts the evaluation on test.
best_folds_accuracy (list|None): when running k-fold cross validation, this keeps the accuracy of folds that already run.
- class mwptoolkit.trainer.supervised_trainer.PretrainSeq2SeqTrainer(config, model, dataloader, evaluator)[source]¶
Bases:
SupervisedTrainer
- Parameters
config (config) – An instance object of Config, used to record parameter information.
model (Model) – An object of deep-learning model.
dataloader (Dataloader) – dataloader object.
evaluator (Evaluator) – evaluator object.
expected that config includes these parameters below:
learning_rate (float): learning rate of model
train_batch_size (int): the training batch size.
epoch_nums (int): number of epochs.
trained_model_path (str): a path of file which is used to save parameters of best model.
checkpoint_path (str): a path of file which is used save checkpoint of training progress.
output_path (str|None): a path of a json file which is used to save test output infomation fo model.
resume (bool): start training from last checkpoint.
validset_divide (bool): whether to split validset. if True, the dataset is split to trainset-validset-testset. if False, the dataset is split to trainset-testset.
test_step (int): the epoch number of training after which conducts the evaluation on test.
best_folds_accuracy (list|None): when running k-fold cross validation, this keeps the accuracy of folds that already run.
- class mwptoolkit.trainer.supervised_trainer.PretrainTRNNTrainer(config, model, dataloader, evaluator)[source]¶
Bases:
TRNNTrainer
- Parameters
config (config) – An instance object of Config, used to record parameter information.
model (Model) – An object of deep-learning model.
dataloader (Dataloader) – dataloader object.
evaluator (Evaluator) – evaluator object.
expected that config includes these parameters below:
seq2seq_learning_rate (float): learning rate of seq2seq module.
ans_learning_rate (float): learning rate of answer module.
train_batch_size (int): the training batch size.
step_size (int): step_size of scheduler.
epoch_nums (int): number of epochs.
trained_model_path (str): a path of file which is used to save parameters of best model.
checkpoint_path (str): a path of file which is used save checkpoint of training progress.
output_path (str|None): a path of a json file which is used to save test output infomation fo model.
resume (bool): start training from last checkpoint.
validset_divide (bool): whether to split validset. if True, the dataset is split to trainset-validset-testset. if False, the dataset is split to trainset-testset.
test_step (int): the epoch number of training after which conducts the evaluation on test.
best_folds_accuracy (list|None): when running k-fold cross validation, this keeps the accuracy of folds that already run.
- class mwptoolkit.trainer.supervised_trainer.SAUSolverTrainer(config, model, dataloader, evaluator)[source]¶
Bases:
GTSTrainer
sausolver trainer, used to implement training, testing, parameter searching for deep-learning model SAUSolver.
example of instantiation:
>>> trainer = SAUSolverTrainer(config, model, dataloader, evaluator)
for training:
>>> trainer.fit()
for testing:
>>> trainer.test()
for parameter searching:
>>> trainer.param_search()
- Parameters
config (config) – An instance object of Config, used to record parameter information.
model (Model) – An object of deep-learning model.
dataloader (Dataloader) – dataloader object.
evaluator (Evaluator) – evaluator object.
expected that config includes these parameters below:
learning_rate (float): learning rate of model.
train_batch_size (int): the training batch size.
step_size (int): step_size of scheduler.
epoch_nums (int): number of epochs.
trained_model_path (str): a path of file which is used to save parameters of best model.
checkpoint_path (str): a path of file which is used save checkpoint of training progress.
output_path (str|None): a path of a json file which is used to save test output infomation fo model.
resume (bool): start training from last checkpoint.
validset_divide (bool): whether to split validset. if True, the dataset is split to trainset-validset-testset. if False, the dataset is split to trainset-testset.
test_step (int): the epoch number of training after which conducts the evaluation on test.
best_folds_accuracy (list|None): when running k-fold cross validation, this keeps the accuracy of folds that already run.
- class mwptoolkit.trainer.supervised_trainer.SalignedTrainer(config, model, dataloader, evaluator)[source]¶
Bases:
SupervisedTrainer
saligned trainer, used to implement training, testing, parameter searching for deep-learning model S-aligned.
example of instantiation:
>>> trainer = SalignedTrainer(config, model, dataloader, evaluator)
for training:
>>> trainer.fit()
for testing:
>>> trainer.test()
for parameter searching:
>>> trainer.param_search()
- Parameters
config (config) – An instance object of Config, used to record parameter information.
model (Model) – An object of deep-learning model.
dataloader (Dataloader) – dataloader object.
evaluator (Evaluator) – evaluator object.
expected that config includes these parameters below:
learning_rate (float): learning rate of model
train_batch_size (int): the training batch size.
epoch_nums (int): number of epochs.
step_size (int): step_size of scheduler.
trained_model_path (str): a path of file which is used to save parameters of best model.
checkpoint_path (str): a path of file which is used save checkpoint of training progress.
output_path (str|None): a path of a json file which is used to save test output infomation fo model.
resume (bool): start training from last checkpoint.
validset_divide (bool): whether to split validset. if True, the dataset is split to trainset-validset-testset. if False, the dataset is split to trainset-testset.
test_step (int): the epoch number of training after which conducts the evaluation on test.
best_folds_accuracy (list|None): when running k-fold cross validation, this keeps the accuracy of folds that already run.
- class mwptoolkit.trainer.supervised_trainer.SupervisedTrainer(config, model, dataloader, evaluator)[source]¶
Bases:
AbstractTrainer
supervised trainer, used to implement training, testing, parameter searching in supervised learning.
example of instantiation:
>>> trainer = SupervisedTrainer(config, model, dataloader, evaluator)
for training:
>>> trainer.fit()
for testing:
>>> trainer.test()
for parameter searching:
>>> trainer.param_search()
- Parameters
config (config) – An instance object of Config, used to record parameter information.
model (Model) – An object of deep-learning model.
dataloader (Dataloader) – dataloader object.
evaluator (Evaluator) – evaluator object.
expected that config includes these parameters below:
learning_rate (float): learning rate of model
train_batch_size (int): the training batch size.
epoch_nums (int): number of epochs.
trained_model_path (str): a path of file which is used to save parameters of best model.
checkpoint_path (str): a path of file which is used save checkpoint of training progress.
output_path (str|None): a path of a json file which is used to save test output infomation fo model.
resume (bool): start training from last checkpoint.
validset_divide (bool): whether to split validset. if True, the dataset is split to trainset-validset-testset. if False, the dataset is split to trainset-testset.
test_step (int): the epoch number of training after which conducts the evaluation on test.
best_folds_accuracy (list|None): when running k-fold cross validation, this keeps the accuracy of folds that already run.
- class mwptoolkit.trainer.supervised_trainer.TRNNTrainer(config, model, dataloader, evaluator)[source]¶
Bases:
SupervisedTrainer
trnn trainer, used to implement training, testing, parameter searching for deep-learning model TRNN.
example of instantiation:
>>> trainer = TRNNTrainer(config, model, dataloader, evaluator)
for training:
>>> trainer.fit()
for testing:
>>> trainer.test()
for parameter searching:
>>> trainer.param_search()
- Parameters
config (config) – An instance object of Config, used to record parameter information.
model (Model) – An object of deep-learning model.
dataloader (Dataloader) – dataloader object.
evaluator (Evaluator) – evaluator object.
expected that config includes these parameters below:
seq2seq_learning_rate (float): learning rate of seq2seq module.
ans_learning_rate (float): learning rate of answer module.
train_batch_size (int): the training batch size.
step_size (int): step_size of scheduler.
epoch_nums (int): number of epochs.
trained_model_path (str): a path of file which is used to save parameters of best model.
checkpoint_path (str): a path of file which is used save checkpoint of training progress.
output_path (str|None): a path of a json file which is used to save test output infomation fo model.
resume (bool): start training from last checkpoint.
validset_divide (bool): whether to split validset. if True, the dataset is split to trainset-validset-testset. if False, the dataset is split to trainset-testset.
test_step (int): the epoch number of training after which conducts the evaluation on test.
best_folds_accuracy (list|None): when running k-fold cross validation, this keeps the accuracy of folds that already run.
- evaluate(eval_set)[source]¶
evaluate model.
- Parameters
eval_set (str) – [valid | test], the dataset for evaluation.
- Returns
equation accuracy, value accuracy, seq2seq module accuracy, answer module accuracy, count of evaluated datas, formatted time string of evaluation time.
- Return type
tuple(float,float,float,float,int,str)
- class mwptoolkit.trainer.supervised_trainer.TSNTrainer(config, model, dataloader, evaluator)[source]¶
Bases:
AbstractTrainer
tsn trainer, used to implement training, testing, parameter searching for deep-learning model TSN.
example of instantiation:
>>> trainer = TSNTrainer(config, model, dataloader, evaluator)
for training:
>>> trainer.fit()
for testing:
>>> trainer.test()
for parameter searching:
>>> trainer.param_search()
- Parameters
config (config) – An instance object of Config, used to record parameter information.
model (Model) – An object of deep-learning model.
dataloader (Dataloader) – dataloader object.
evaluator (Evaluator) – evaluator object.
expected that config includes these parameters below:
learning_rate (float): learning rate of model
train_batch_size (int): the training batch size.
epoch_nums (int): number of epochs.
step_size (int): step_size of scheduler.
trained_model_path (str): a path of file which is used to save parameters of best model.
checkpoint_path (str): a path of file which is used save checkpoint of training progress.
output_path (str|None): a path of a json file which is used to save test output infomation fo model.
resume (bool): start training from last checkpoint.
validset_divide (bool): whether to split validset. if True, the dataset is split to trainset-validset-testset. if False, the dataset is split to trainset-testset.
test_step (int): the epoch number of training after which conducts the evaluation on test.
best_folds_accuracy (list|None): when running k-fold cross validation, this keeps the accuracy of folds that already run.
- evaluate_student(eval_set)[source]¶
evaluate student net.
- Parameters
eval_set (str) – [valid | test], the dataset for evaluation.
- Returns
equation accuracy, value accuracy, equation accuracy of student net 1, value accuracy of student net 1, equation accuracy of student net 2, value accuracy of student net 2, count of evaluated datas, formatted time string of evaluation time.
- Return type
tuple(float,float,float,float,float,float,int,str)
- class mwptoolkit.trainer.supervised_trainer.TreeLSTMTrainer(config, model, dataloader, evaluator)[source]¶
Bases:
AbstractTrainer
treelstm trainer, used to implement training, testing, parameter searching for deep-learning model TreeLSTM.
example of instantiation:
>>> trainer = TreeLSTMTrainer(config, model, dataloader, evaluator)
for training:
>>> trainer.fit()
for testing:
>>> trainer.test()
for parameter searching:
>>> trainer.param_search()
- Parameters
config (config) – An instance object of Config, used to record parameter information.
model (Model) – An object of deep-learning model.
dataloader (Dataloader) – dataloader object.
evaluator (Evaluator) – evaluator object.
expected that config includes these parameters below:
learning_rate (float): learning rate of model.
train_batch_size (int): the training batch size.
step_size (int): step_size of scheduler.
epoch_nums (int): number of epochs.
trained_model_path (str): a path of file which is used to save parameters of best model.
checkpoint_path (str): a path of file which is used save checkpoint of training progress.
output_path (str|None): a path of a json file which is used to save test output infomation fo model.
resume (bool): start training from last checkpoint.
validset_divide (bool): whether to split validset. if True, the dataset is split to trainset-validset-testset. if False, the dataset is split to trainset-testset.
test_step (int): the epoch number of training after which conducts the evaluation on test.
best_folds_accuracy (list|None): when running k-fold cross validation, this keeps the accuracy of folds that already run.