modules/model.py
def train(self, dataset, k=20, n_epochs=20, save_dir='./models', save=True, model_name='GRU4REC'):
        """
        Train the GRU4REC model on a pandas dataframe for several training epochs,
        and store the intermediate models to the user-specified directory.

        Args:
            n_epochs (int): the number of training epochs to run
            save_dir (str): the path to save the intermediate trained models
            model_name (str): name of the model
        """
        print(f'Training {model_name}...')
        for epoch in range(n_epochs):
            if self.compression_scheduler:
                self.compression_scheduler.on_epoch_begin(epoch)
            results = self.run_epoch(dataset, k=k, training=True, compression_scheduler=self.compression_scheduler, epoch=epoch)
            results = [f'{k}:{v:.3f}' for k, v in results.items()]
            print(f'epoch:{epoch+1:2d}/{"/".join(results)}')
            
            t, total = distiller.weights_sparsity_tbl_summary(self.gru, return_total_sparsity=True)
            print("\nParameters:\n" + str(t))
            print('Total sparsity: {:0.2f}\n'.format(total))
            
            if self.compression_scheduler:
                self.compression_scheduler.on_epoch_end(epoch)
            
            # Store the intermediate model
            if save:
                save_dir = Path(save_dir)
                if not save_dir.exists(): save_dir.mkdir()
                model_fname = f'{model_name}_{self.loss_type}_{self.optimizer_type}_{self.lr}_epoch{epoch+1:d}'
                torch.save(self.gru.state_dict(), save_dir/model_fname)

        Train the GRU4REC model on a pandas dataframe for several training epochs,
        and store the intermediate models to the user-specified directory.

        Args:
            n_epochs (int): the number of training epochs to run
            save_dir (str): the path to save the intermediate trained models
            model_name (str): name of the model
        
Train the GRU4REC model on a pandas dataframe for several training epochs,
and store the intermediate models to the user-specified directory.
Train the GRU4REC model on a pandas dataframe for several training epochs and store the intermediate models to the user - specified directory .
def train(self, dataset, k=20, n_epochs=20, save_dir='./models', save=True, model_name='GRU4REC'):
        print(f'Training {model_name}...')
        for epoch in range(n_epochs):
            if self.compression_scheduler:
                self.compression_scheduler.on_epoch_begin(epoch)
            results = self.run_epoch(dataset, k=k, training=True, compression_scheduler=self.compression_scheduler, epoch=epoch)
            results = [f'{k}:{v:.3f}' for k, v in results.items()]
            print(f'epoch:{epoch+1:2d}/{"/".join(results)}')
            t, total = distiller.weights_sparsity_tbl_summary(self.gru, return_total_sparsity=True)
            print("\nParameters:\n" + str(t))
            print('Total sparsity: {:0.2f}\n'.format(total))
            if self.compression_scheduler:
                self.compression_scheduler.on_epoch_end(epoch)
            if save:
                save_dir = Path(save_dir)
                if not save_dir.exists(): save_dir.mkdir()
                model_fname = f'{model_name}_{self.loss_type}_{self.optimizer_type}_{self.lr}_epoch{epoch+1:d}'
                torch.save(self.gru.state_dict(), save_dir/model_fname)
def train ( self , dataset , k = 20 , n_epochs = 20 , save_dir = './models' , save = True , model_name = 'GRU4REC' ) : print ( f'Training {model_name}...' ) for epoch in range ( n_epochs ) : if self . compression_scheduler : self . compression_scheduler . on_epoch_begin ( epoch ) results = self . run_epoch ( dataset , k = k , training = True , compression_scheduler = self . compression_scheduler , epoch = epoch ) results = [ f'{k}:{v:.3f}' for k , v in results . items ( ) ] print ( f'epoch:{epoch+1:2d}/{"/".join(results)}' ) t , total = distiller . weights_sparsity_tbl_summary ( self . gru , return_total_sparsity = True ) print ( "\nParameters:\n" + str ( t ) ) print ( 'Total sparsity: {:0.2f}\n' . format ( total ) ) if self . compression_scheduler : self . compression_scheduler . on_epoch_end ( epoch ) if save : save_dir = Path ( save_dir ) if not save_dir . exists ( ) : save_dir . mkdir ( ) model_fname = f'{model_name}_{self.loss_type}_{self.optimizer_type}_{self.lr}_epoch{epoch+1:d}' torch . save ( self . gru . state_dict ( ) , save_dir / model_fname )
Train the GRU4REC model on a pandas dataframe for several training epochs,
and store the intermediate models to the user-specified directory.
Train the GRU4REC model on a pandas dataframe for several training epochs and store the intermediate models to the user - specified directory .
"""
        Train the GRU4REC model on a pandas dataframe for several training epochs,
        and store the intermediate models to the user-specified directory.

        Args:
            n_epochs (int): the number of training epochs to run
            save_dir (str): the path to save the intermediate trained models
            model_name (str): name of the model
        """ # Store the intermediate model
self
dataset
k
n_epochs
the number of training epochs to run
the number of training epochs to run
save_dir
the path to save the intermediate trained models
the path to save the intermediate trained models
save
model_name
name of the model
name of the model