tune.py
def tune_rnn_with_gridsearch():
        """Grid search to identify best hyperparameters for RNN."""
        rnn_model_values = []
        n_epoch_list = [200, 400, 600, 800, 1000]                               # 5
        batch_size_list = [16, 32, 64, 128, 256]                                # 5
        learning_rate_list = [.001, .005, .0001, .0005]                         # 4
        dropout_rate_list = [0.2, 0.5, 0.7]                                     # 3

        for n_epoch in n_epoch_list:
            for batch_size in batch_size_list:
                for learning_rate in learning_rate_list:
                    for dropout_rate in dropout_rate_list:
                        for n_hidden in [8, 16, 32]:                # RNN ONLY
                            for num_fc_1 in [10, 20, 30, 40]:       # RNN ONLY
                                for n_layers in [1, 2, 3]:          # RNN ONLY
                                    RNN = TrainModel(RNNModel, n_epoch, batch_size, learning_rate, dropout_rate)
                                    RNN.model.n_hidden = n_hidden
                                    RNN.model.num_fc_1 = num_fc_1
                                    RNN.model.n_layers = n_layers

                                    RNN.model.build_model()
                                    RNN.calculate_helpers()
                                    acc = RNN.train_model()
                                    RNN.reset_model()

                                    rnn_model_values.append([acc, n_epoch, batch_size, learning_rate, dropout_rate, n_hidden, num_fc_1, n_layers])

            best_rnn_run = max(rnn_model_values, key=lambda x: x[0])
            logger.info('Best RNN run: {}'.format(best_rnn_run))
            logger.info('All RNN runs: {}'.format(rnn_model_values))
Grid search to identify best hyperparameters for RNN.
Grid search to identify best hyperparameters for RNN.
Grid search to identify best hyperparameters for RNN .
def tune_rnn_with_gridsearch():
        rnn_model_values = []
        n_epoch_list = [200, 400, 600, 800, 1000]                               
        batch_size_list = [16, 32, 64, 128, 256]                                
        learning_rate_list = [.001, .005, .0001, .0005]                         
        dropout_rate_list = [0.2, 0.5, 0.7]                                     
        for n_epoch in n_epoch_list:
            for batch_size in batch_size_list:
                for learning_rate in learning_rate_list:
                    for dropout_rate in dropout_rate_list:
                        for n_hidden in [8, 16, 32]:                
                            for num_fc_1 in [10, 20, 30, 40]:       
                                for n_layers in [1, 2, 3]:          
                                    RNN = TrainModel(RNNModel, n_epoch, batch_size, learning_rate, dropout_rate)
                                    RNN.model.n_hidden = n_hidden
                                    RNN.model.num_fc_1 = num_fc_1
                                    RNN.model.n_layers = n_layers
                                    RNN.model.build_model()
                                    RNN.calculate_helpers()
                                    acc = RNN.train_model()
                                    RNN.reset_model()
                                    rnn_model_values.append([acc, n_epoch, batch_size, learning_rate, dropout_rate, n_hidden, num_fc_1, n_layers])
            best_rnn_run = max(rnn_model_values, key=lambda x: x[0])
            logger.info('Best RNN run: {}'.format(best_rnn_run))
            logger.info('All RNN runs: {}'.format(rnn_model_values))
def tune_rnn_with_gridsearch ( ) : rnn_model_values = [ ] n_epoch_list = [ 200 , 400 , 600 , 800 , 1000 ] batch_size_list = [ 16 , 32 , 64 , 128 , 256 ] learning_rate_list = [ .001 , .005 , .0001 , .0005 ] dropout_rate_list = [ 0.2 , 0.5 , 0.7 ] for n_epoch in n_epoch_list : for batch_size in batch_size_list : for learning_rate in learning_rate_list : for dropout_rate in dropout_rate_list : for n_hidden in [ 8 , 16 , 32 ] : for num_fc_1 in [ 10 , 20 , 30 , 40 ] : for n_layers in [ 1 , 2 , 3 ] : RNN = TrainModel ( RNNModel , n_epoch , batch_size , learning_rate , dropout_rate ) RNN . model . n_hidden = n_hidden RNN . model . num_fc_1 = num_fc_1 RNN . model . n_layers = n_layers RNN . model . build_model ( ) RNN . calculate_helpers ( ) acc = RNN . train_model ( ) RNN . reset_model ( ) rnn_model_values . append ( [ acc , n_epoch , batch_size , learning_rate , dropout_rate , n_hidden , num_fc_1 , n_layers ] ) best_rnn_run = max ( rnn_model_values , key = lambda x : x [ 0 ] ) logger . info ( 'Best RNN run: {}' . format ( best_rnn_run ) ) logger . info ( 'All RNN runs: {}' . format ( rnn_model_values ) )
Grid search to identify best hyperparameters for RNN.
Grid search to identify best hyperparameters for RNN .
"""Grid search to identify best hyperparameters for RNN.""" # 5 # 5 # 4 # 3 # RNN ONLY # RNN ONLY # RNN ONLY