(self, task_name, model, hparams, train_iter, evaluator)
Parameters:
            task_name: Name of the task
            model: Model instance (derived from model.Model)
            hparams: Instance of HParams
            train_iter: An instance of torchtext.data.Iterator
            evaluator: Instance of evalutation.Evaluator that will
                        run metrics on the validation dataset
Parameters:
            task_name: Name of the task
            model: Model instance (derived from model.Model)
            hparams: Instance of HParams
            train_iter: An instance of torchtext.data.Iterator
            evaluator: Instance of evalutation.Evaluator that will
                        run metrics on the validation dataset
Parameters : task_name : Name of the task model : Model instance ( derived from model . Model ) hparams : Instance of HParams train_iter : An instance of torchtext . data . Iterator evaluator : Instance of evalutation . Evaluator that will run metrics on the validation dataset
def __init__(self, task_name, model, hparams, train_iter, evaluator):
        """
        Parameters:
            task_name: Name of the task
            model: Model instance (derived from model.Model)
            hparams: Instance of HParams
            train_iter: An instance of torchtext.data.Iterator
            evaluator: Instance of evalutation.Evaluator that will
                        run metrics on the validation dataset
        """

        self.task_name = task_name
        self.model = model
        self.hparams = hparams
        self.evaluator = evaluator

        self.train_iter = train_iter
        # Disable repetitions
        self.train_iter.repeat = False

        model_params = filter(lambda p: p.requires_grad, model.parameters())
        
        # TODO: Add support for other optimizers
        self.optimizer = optim.Adam(
                            model_params,
                            betas=(hparams.optimizer_adam_beta1, hparams.optimizer_adam_beta2), 
                            lr=hparams.learning_rate)

        self.opt_path = os.path.join(gen_model_dir(task_name, model.__class__), 
                                    OPTIMIZER_FILE)

        # If model is loaded from a checkpoint restore optimizer also
        if int(model.iterations) > 0:
            self.optimizer.load_state_dict(torch.load(self.opt_path))

        self.lr_scheduler_step = self.lr_scheduler_epoch = None

        # Set up learing rate decay scheme
        if hparams.learning_rate_decay is not None:
            if '_' not in hparams.learning_rate_decay:
                raise ValueError("Malformed learning_rate_decay")
            lrd_scheme, lrd_range = hparams.learning_rate_decay.split('_')

            if lrd_scheme not in lr_decay_map:
                raise ValueError("Unknown lr decay scheme {}".format(lrd_scheme))
            
            lrd_func = lr_decay_map[lrd_scheme]            
            lr_scheduler = optim.lr_scheduler.LambdaLR(
                                            self.optimizer, 
                                            lrd_func(hparams),
                                            last_epoch=int(self.model.iterations) or -1
                                        )
            # For each scheme, decay can happen every step or every epoch
            if lrd_range == 'epoch':
                self.lr_scheduler_epoch = lr_scheduler
            elif lrd_range == 'step':
                self.lr_scheduler_step = lr_scheduler
            else:
                raise ValueError("Unknown lr decay range {}".format(lrd_range))

        # Display number of parameters
        logger.info('Parameters: {}(trainable), {}(non-trainable)'.format(*compute_num_params(self.model)))
def __init__ ( self , task_name , model , hparams , train_iter , evaluator ) : self . task_name = task_name self . model = model self . hparams = hparams self . evaluator = evaluator self . train_iter = train_iter # Disable repetitions self . train_iter . repeat = False model_params = filter ( lambda p : p . requires_grad , model . parameters ( ) ) # TODO: Add support for other optimizers self . optimizer = optim . Adam ( model_params , betas = ( hparams . optimizer_adam_beta1 , hparams . optimizer_adam_beta2 ) , lr = hparams . learning_rate ) self . opt_path = os . path . join ( gen_model_dir ( task_name , model . __class__ ) , OPTIMIZER_FILE ) # If model is loaded from a checkpoint restore optimizer also if int ( model . iterations ) > 0 : self . optimizer . load_state_dict ( torch . load ( self . opt_path ) ) self . lr_scheduler_step = self . lr_scheduler_epoch = None # Set up learing rate decay scheme if hparams . learning_rate_decay is not None : if '_' not in hparams . learning_rate_decay : raise ValueError ( "Malformed learning_rate_decay" ) lrd_scheme , lrd_range = hparams . learning_rate_decay . split ( '_' ) if lrd_scheme not in lr_decay_map : raise ValueError ( "Unknown lr decay scheme {}" . format ( lrd_scheme ) ) lrd_func = lr_decay_map [ lrd_scheme ] lr_scheduler = optim . lr_scheduler . LambdaLR ( self . optimizer , lrd_func ( hparams ) , last_epoch = int ( self . model . iterations ) or - 1 ) # For each scheme, decay can happen every step or every epoch if lrd_range == 'epoch' : self . lr_scheduler_epoch = lr_scheduler elif lrd_range == 'step' : self . lr_scheduler_step = lr_scheduler else : raise ValueError ( "Unknown lr decay range {}" . format ( lrd_range ) ) # Display number of parameters logger . info ( 'Parameters: {}(trainable), {}(non-trainable)' . format ( * compute_num_params ( self . model ) ) )