Пример #1
0
 def add_model_specific_args(parent_parser):
     p = HyperOptArgumentParser(parents=parent_parser, add_help=False, conflict_handler='resolve')
     p.add_argument('--dense_encoder', default=False, type=bool)
     p.add_argument('--code_size', default=512, type=int)
     p.add_argument('--out_channels', default=3, type=int)
     p.add_argument('--rec_decoder_convl', default=3, type=int)
     p.add_argument('--comp_decoder_convl', default=3, type=int)
     p.add_argument('--context_decoder_convl', default=3, type=int)
     if not parent_parser:  # Name clash with parent
         p.add_argument('--in_channels', default=3, type=int)
     return p
    def add_model_specific_args(parent_parser, root_dir):  # pragma: no cover
        """
        Parameters you define here will be available to your model through self.hparams
        :param parent_parser:
        :param root_dir:
        :return:
        """

        parser = HyperOptArgumentParser(
            strategy=parent_parser.strategy, parents=[parent_parser]
        )

        parser.add_argument("--beta", default=1, type=float)
        parser.add_argument("--bottleneck_size", default=10, type=int)
        parser.add_argument("--group_distance_scaling", default=1, type=float)
        parser.add_argument("--audio_size", default=80, type=int)
        parser.add_argument("--data_dim", default=140, type=int)
        parser.add_argument("--data_files", default="datafiles.json", type=str)
        parser.add_argument("--data_dir", default="/data_dir", type=str)
        parser.opt_list(
            "--batch_size",
            default=256 * 4,
            type=int,
            options=[32, 64, 128, 256],
            tunable=False,
            help="batch size will be divided over all gpus being used across all nodes",
        )
        parser.opt_list(
            "--learning_rate",
            default=0.001 * 8,
            type=float,
            options=[0.0001, 0.0005, 0.001],
            tunable=True,
        )
        return parser
Пример #3
0
                             default=10,
                             options=[20, 30, 40, 50],
                             type=int,
                             tunable=True)
parser.add_opt_argument_list('--embedding_dim',
                             default=320,
                             options=[100, 200, 320, 400],
                             type=int,
                             tunable=True)
parser.add_opt_argument_list('--max_seq_len',
                             default=50,
                             options=[50, 70, 90, 110],
                             type=int,
                             tunable=True)

parser.add_argument('--nb_epochs', default=5, type=int)
parser.add_argument('--optimizer_name', default='adam')
parser.add_argument('--eval_every_n_batches', default=200, type=int)
parser.add_argument('--train_mode', default='train')

parser.add_argument('--nb_grams', default=2, type=int)

parser.add_argument('--root_dir', default='/home/ankur/smart-reply')
parser.add_argument(
    '--dataset_train_path',
    default='/home/ankur/smart-reply/dataset/data/data/train.csv')
parser.add_argument(
    '--dataset_test_path',
    default='/home/ankur/smart-reply/dataset/data/data/test.csv')
parser.add_argument(
    '--dataset_val_path',
    ]
    checkpoint_path = experiment_folder + "/checkpoints/" + checkpoints[-1]
    model = BERTClassifier.load_from_metrics(weights_path=checkpoint_path,
                                             tags_csv=tags_csv_file)
    # Make sure model is in prediction mode
    model.eval()
    model.freeze()
    return model


if __name__ == "__main__":
    parser = HyperOptArgumentParser(description="Minimalist BERT Classifier",
                                    add_help=True)
    parser.add_argument(
        "--experiment",
        required=True,
        type=str,
        help="Path to the experiment folder.",
    )
    hparams = parser.parse_args()
    print("Loading model...")
    model = load_model_from_experiment(hparams.experiment)
    print(model)

    while 1:
        print(
            "Please write a movie review or quit to exit the interactive shell:"
        )
        # Get input sentence
        input_sentence = input("> ")
        if input_sentence == "q" or input_sentence == "quit":
            break
Пример #5
0
if __name__ == '__main__':

    # dirs
    root_dir = os.path.dirname(os.path.realpath(__file__))
    demo_log_dir = os.path.join(root_dir, 'pt_lightning_demo_logs')
    checkpoint_dir = os.path.join(demo_log_dir, 'model_weights')
    test_tube_dir = os.path.join(demo_log_dir, 'test_tube_data')

    # although we user hyperOptParser, we are using it only as argparse right now
    parent_parser = HyperOptArgumentParser(strategy='grid_search',
                                           add_help=False)

    # gpu args
    parent_parser.add_argument('--gpus',
                               type=str,
                               default='-1',
                               help='how many gpus to use in the node.'
                               ' value -1 uses all the gpus on the node')
    parent_parser.add_argument('--test_tube_save_path',
                               type=str,
                               default=test_tube_dir,
                               help='where to save logs')
    parent_parser.add_argument('--model_save_path',
                               type=str,
                               default=checkpoint_dir,
                               help='where to save model')
    parent_parser.add_argument('--experiment_name',
                               type=str,
                               default='pt_lightning_exp_a',
                               help='test tube exp name')
    def add_model_specific_args(parent_parser):
        parser = HyperOptArgumentParser(parents=[parent_parser])
        parser.add_argument('--num_freq_mask', default=2, type=int)
        parser.add_argument('--num_time_mask', default=2, type=int)
        parser.add_argument('--freq_mask_length', default=20, type=int)
        parser.add_argument('--time_mask_length', default=20, type=int)
        parser.add_argument('--feature_dim', default=480, type=int)
        parser.add_argument('--model_size', default=512, type=int)
        parser.add_argument('--feed_forward_size', default=2048, type=int)
        parser.add_argument('--hidden_size', default=64, type=int)
        parser.add_argument('--dropout', default=0.1, type=float)
        parser.add_argument('--num_head', default=8, type=int)
        parser.add_argument('--num_encoder_layer', default=12, type=int)
        parser.add_argument('--num_decoder_layer', default=6, type=int)
        parser.add_argument('--vocab_path',
                            default='testing_vocab.model',
                            type=str)
        parser.add_argument('--max_feature_length', default=1024, type=int)
        parser.add_argument('--max_token_length', default=70, type=int)
        parser.add_argument('--share_weight', default=True, type=bool)
        parser.add_argument('--loss_lambda', default=0.65, type=float)
        parser.add_argument('--smoothing', default=0.1, type=float)
        parser.add_argument('--use_low_rank', default=False, type=bool)

        parser.add_argument('--lr', default=5e-5, type=float)
        parser.add_argument('--warm_up_step', default=16000, type=int)
        parser.add_argument('--factor', default=1, type=int)
        parser.add_argument('--enable_spec_augment', default=True, type=bool)

        parser.add_argument('--train_batch_size', default=64, type=int)
        parser.add_argument('--train_loader_num_workers', default=32, type=int)
        parser.add_argument('--val_batch_size', default=64, type=int)
        parser.add_argument('--val_loader_num_workers', default=16, type=int)

        return parser
    # 5 START TRAINING
    # ------------------------
    trainer.fit(model)


if __name__ == "__main__":
    # ------------------------
    # TRAINING ARGUMENTS
    # ------------------------
    # these are project-wide arguments
    parser = HyperOptArgumentParser(
        strategy="random_search",
        description="Minimalist BERT Classifier",
        add_help=True,
    )
    parser.add_argument("--seed", type=int, default=3, help="Training seed.")
    parser.add_argument(
        "--save_top_k",
        default=1,
        type=int,
        help=
        "The best k models according to the quantity monitored will be saved.",
    )
    # Early Stopping
    parser.add_argument("--monitor",
                        default="val_acc",
                        type=str,
                        help="Quantity to monitor.")
    parser.add_argument(
        "--metric_mode",
        default="max",
Пример #8
0
                                            weight_decay_rate=hparams.wd)
    print(hparams, flush=True)

    # start trainer
    auc = train(vars(hparams), num_workers, node_id, fold, kfold, debug, path)
    print(auc)

    # save Experiment
    exp.add_scalar('auc', auc)
    exp.save()


if __name__ == '__main__':
    # Set up our argparser and make the y_val tunable.
    parser = HyperOptArgumentParser(strategy='random_search')
    parser.add_argument('--test_tube_exp_name', default='tt_exp')
    parser.add_argument('--batch_size', default=80, type=int)
    parser.add_argument('--epochs', default=3, type=int)
    parser.add_argument('--gpus', default=2, type=int)
    parser.add_argument('--log_path', default=os.environ['SCRATCH'] + '/summer_school/hs_log')
    parser.opt_range('--lr', default=2e-4, type=float, tunable=True, low=1e-4, high=1e-3, nb_samples=100, log_base=10)
    parser.opt_range('--wd', default=1e-5, type=float, tunable=True, low=1e-7, high=1e-4, nb_samples=100, log_base=10)
    hyperparams = parser.parse_args()

    # Enable cluster training.
    cluster = SlurmCluster(
        hyperparam_optimizer=hyperparams,
        log_path=hyperparams.log_path,
        python_cmd='python3',
    )
Пример #9
0
                     tunable=False,
                     low=0.,
                     high=.5,
                     help='dropout fraction',
                     default=0.)
    parser.opt_list('--batch_norm',
                    action='store_true',
                    dest='batch_norm',
                    tunable=False,
                    options=[True, False],
                    help='batch normalization',
                    default=False)

    parser.add_argument('--num_accumulate',
                        action='store',
                        dest='num_accumulate',
                        type=int,
                        help='nunumber of batch accumulations',
                        default=1)
    parser.add_argument('--name',
                        action='store',
                        dest='name',
                        type=str,
                        help='experiment name',
                        default=1)
    parser.add_argument('--version',
                        action='store',
                        dest='version',
                        type=int,
                        help='version number',
                        default=None)
    parser.add_argument('--gpu',
def cnn_encoder_decoder_argparser():
    # TODO: set min max size for vocab
    # TODO: specify optimizer
    # TODO: set max length of sentences

    # parser = argparse.ArgumentParser(description='Run Tests')
    parser = HyperOptArgumentParser(description='Run Tests',
                                    strategy='grid_search')

    parser.add_argument('--name',
                        help="experiment name",
                        default="rnn_encoder_decoder")
    parser.add_argument('--test',
                        help="Run test instead of training/validation",
                        action="store_true")
    parser.add_argument("--njobs",
                        help="Number of jobs to use when loading data",
                        type=int,
                        default=1)
    parser.add_argument("--epoch",
                        help="Number of epoch to run",
                        type=int,
                        default=10000)
    parser.add_argument("--batch_size",
                        help="Batch size",
                        type=int,
                        default=32)
    parser.add_argument("--hidden_size",
                        help="Hidden size",
                        type=int,
                        default=256)
    parser.add_argument("--embedding_size",
                        help="Embedding size",
                        type=int,
                        default=256)
    parser.add_argument("--print_every",
                        help="How frequently print result",
                        type=int,
                        default=100)
    parser.add_argument("--lr",
                        help="Learning Rate",
                        type=float,
                        default=1e-03)
    parser.add_argument("--dropout",
                        help="Dropout Rate",
                        type=float,
                        default=0)
    parser.add_argument(
        '--bidirectional',
        help="Use bidirectional RNN in encoder",
        action="store_true")  # don't set this true in this model
    parser.add_argument('--cpu',
                        help="Use cpu instead of gpu",
                        action="store_true")
    parser.add_argument("--data",
                        help="Directory where data is stored",
                        default='../data/iwslt-zh-en/')
    parser.add_argument("--rnn_type",
                        help="Which rnn to use (rnn, lstm, gru)",
                        default='gru')
    parser.add_argument("--kernel_size",
                        help="Kernel size of cnn layers in encoder",
                        type=int,
                        default=3)
    parser.add_argument("--num_encoder_layers",
                        help="Number of cnn layers in encoder",
                        type=int,
                        default=1)
    parser.add_argument("--num_decoder_layers",
                        help="Number of rnn layers in encoder",
                        type=int,
                        default=1)
    parser.add_argument("--early_stopping",
                        help="Stop if validation does not improve",
                        type=int,
                        default=10)
    parser.add_argument('--l2_penalty',
                        help="L2 pelnalty coefficient in optimizer",
                        type=float,
                        default=0)  #1e-06
    parser.add_argument('--clip',
                        help="clip coefficient in optimizer",
                        type=float,
                        default=1)
    parser.add_argument('--teacher_forcing',
                        help="probability of performing teacher forcing",
                        type=float,
                        default=0.5)
    parser.add_argument("--max_sentence_length",
                        help="maximum sentence length",
                        type=int,
                        default=50)
    parser.add_argument('--split_chinese_into_characters',
                        help="Split chinese into characters",
                        action="store_true")
    parser.add_argument(
        "--min_freq",
        help="Vocabulary needs to be present at least this amount of time",
        type=int,
        default=3)
    parser.add_argument("--max_vocab_size",
                        help="At most n vocaburaries are kept in the model",
                        type=int,
                        default=100000)
    parser.add_argument("--source_lang",
                        help="Source language (vi, zh)",
                        default="zh")
    parser.add_argument("--logs_path",
                        help="Path to save training logs",
                        type=str,
                        default="../training_logs/")
    parser.add_argument("--model_weights_path",
                        help="Path to save best model weights",
                        type=str,
                        default="../model_weights/")
    parser.add_argument('--save_all_epoch',
                        help="save all epoch",
                        action="store_true")
    parser.add_argument('--relu',
                        help="use relu in decoder after embedding",
                        action="store_true")
    parser.add_argument('--attention',
                        help="use luong attention decoder",
                        action="store_true")
    parser.add_argument("--attn_model",
                        help="dot, general, or concat",
                        default='general')
    parser.add_argument("--preprocess_version",
                        help="Version of preprocessing",
                        type=int,
                        default=2)
    parser.add_argument(
        '--freeze_all_words',
        help="freeze word embedding and use character embedding from ELMo",
        action="store_true")
    parser.add_argument("--encoder_word_embedding",
                        help="Word embedding weights file",
                        default=None)
    parser.add_argument("--decoder_word_embedding",
                        help="Word embedding weights file",
                        default=None)
    return parser
Пример #11
0
    def add_model_specific_args(parent_parser):
        from test_tube import HyperOptArgumentParser
        parser = HyperOptArgumentParser(parents=[parent_parser],
                                        add_help=False)
        parser.add_argument('--base_encoder', type=str, default='resnet18')
        parser.add_argument('--emb_dim', type=int, default=128)
        parser.add_argument('--num_workers', type=int, default=8)
        parser.add_argument('--num_negatives', type=int, default=65536)
        parser.add_argument('--encoder_momentum', type=float, default=0.999)
        parser.add_argument('--softmax_temperature', type=float, default=0.07)
        parser.add_argument('--optimizer', type=str, default='SGD')
        parser.add_argument('--optimizer-parameters',
                            type=json.loads,
                            default=json.dumps({
                                "lr": 0.03,
                                "momentum": 0.9,
                                "weight_decay": 1.0e-4
                            }))
        # parser.add_argument('--learning_rate', type=float, default=0.03)
        # parser.add_argument('--momentum', type=float, default=0.9)
        # parser.add_argument('--weight_decay', type=float, default=1e-4)
        parser.add_argument('--data_dir', type=str, default='./')
        parser.add_argument('--dataset',
                            type=str,
                            default='cifar10',
                            help='cifar10, stl10, imagenet2012')
        parser.add_argument('--batch_size', type=int, default=256)
        parser.add_argument('--use_mlp', action='store_true')
        parser.add_argument('--meta_root',
                            default='.',
                            type=str,
                            help='path to meta.bin for imagenet')

        return parser
Пример #12
0
    def add_model_specific_args(parent_parser, root_dir):
        parser = HyperOptArgumentParser(strategy=parent_parser.strategy,
                                        parents=[parent_parser])

        parser.set_defaults(nb_hopt_trials=1000)
        parser.set_defaults(min_nb_epochs=1000)
        parser.set_defaults(max_nb_epochs=1100)
        parser.set_defaults(early_stop_metric='val_nce')
        parser.set_defaults(model_save_monitor_value='val_nce')
        parser.set_defaults(model_save_monitor_mode='min')
        parser.set_defaults(early_stop_mode='min')

        # CIFAR 10
        dataset_name = 'CIFAR10'
        image_height = 32
        nb_classes = 10
        patch_size = 8
        patch_overlap = 4

        # dataset options
        parser.opt_list('--nb_classes',
                        default=nb_classes,
                        type=int,
                        options=[10],
                        tunable=False)
        parser.opt_list('--patch_size',
                        default=patch_size,
                        type=int,
                        options=[10],
                        tunable=False)
        parser.opt_list('--patch_overlap',
                        default=patch_overlap,
                        type=int,
                        options=[10],
                        tunable=False)

        # network params
        parser.add_argument('--image_height', type=int, default=image_height)

        # trainin params
        parser.add_argument('--dataset_name', type=str, default=dataset_name)
        parser.add_argument('--batch_size',
                            type=int,
                            default=200,
                            help='input batch size (default: 200)')
        parser.opt_list(
            '--learning_rate',
            type=float,
            default=0.0002,
            options=[
                2e-4 * (1 / 64),
                2e-4 * (1 / 32),
                2e-4 * (1 / 16),
                2e-4 * (1 / 8),
                2e-4 * (1 / 4),
                2e-4 * (1 / 2),
                2e-4 * (1 / 4),
                2e-4,
                2e-4 * 4,  #2e-4*4,
                2e-4 * 8,
            ],
            tunable=False)

        # data
        parser.opt_list('--cifar10_root',
                        default=f'{root_dir}/fisherman/datasets',
                        type=str,
                        tunable=False)
        return parser
Пример #13
0
    def add_model_specific_args(parent_parser, root_dir):  # pragma: no cover
        """
        Parameters you define here will be available to your model through self.hparams
        :param parent_parser:
        :param root_dir:
        :return:
        """
        parser = HyperOptArgumentParser(strategy=parent_parser.strategy,
                                        parents=[parent_parser])

        parser.add_argument('--log_dir', default='logs', type=str)
        parser.add_argument('--checkpoint_dir',
                            default='checkpoints',
                            type=str)

        # data
        parser.add_argument('--training_set_path',
                            default='data/training',
                            type=str)
        parser.add_argument('--validation_set_path',
                            default='data/validation',
                            type=str)
        parser.add_argument('--test_task_set_path',
                            default='data/test_task',
                            type=str)
        parser.add_argument('--unique_steps', default=8., type=float)
        parser.add_argument('--sampling_rate', default=44100, type=float)
        parser.add_argument('--dummy_datasets', default=False, type=bool)

        # preprocessing
        parser.add_argument('--cqt_fmin', default=30., type=float)
        parser.add_argument('--cqt_n_bins', default=292, type=int)
        parser.add_argument('--cqt_bins_per_octave', default=32, type=int)
        parser.add_argument('--cqt_hop_length', default=256, type=int)
        parser.add_argument('--cqt_filter_scale', default=0.5, type=float)
        parser.add_argument('--scalogram_output_power', default=1., type=float)
        parser.add_argument('--scalogram_pooling',
                            nargs='+',
                            default=(1, 2),
                            type=int)
        parser.add_argument('--phase', default=True, type=bool)
        parser.add_argument('--audio_noise', default=0., type=float)

        # training
        parser.opt_list('--optimizer_name',
                        default='adam',
                        type=str,
                        options=['adam'],
                        tunable=False)
        parser.opt_list('--learning_rate',
                        default=0.0001,
                        type=float,
                        options=[0.0001, 0.0005, 0.001],
                        tunable=True)
        parser.add_argument('--batch_size', default=32, type=int)
        parser.add_argument('--score_over_all_timesteps',
                            default=True,
                            type=bool)
        parser.add_argument('--visible_steps', default=60, type=int)
        parser.add_argument('--prediction_steps', default=16, type=int)
        parser.add_argument('--wasserstein_penalty', default=0., type=float)
        parser.add_argument('--detach_targets', default=False, type=bool)
        parser.add_argument('--file_batch_size', default=1, type=int)
        parser.add_argument('--use_all_GPUs', default=True, type=bool)
        parser.add_argument('--warmup_steps', default=0, type=int)
        parser.add_argument('--annealing_steps', default=1e6, type=int)

        # encoder
        parser.add_argument('--enc_channels',
                            nargs='+',
                            default=(1, 32, 32, 64, 64, 128, 128, 256, 512),
                            type=int)
        parser.add_argument('--enc_kernel_1_w',
                            nargs='+',
                            default=(1, 3, 1, 3, 1, 3, 1, 3),
                            type=int)
        parser.add_argument('--enc_kernel_1_h',
                            nargs='+',
                            default=(65, 3, 33, 3, 16, 3, 9, 3),
                            type=int)
        parser.add_argument('--enc_kernel_2_w',
                            nargs='+',
                            default=(3, 3, 3, 3, 3, 3, 3, 3),
                            type=int)
        parser.add_argument('--enc_kernel_2_h',
                            nargs='+',
                            default=(3, 3, 3, 3, 3, 3, 3, 3),
                            type=int)
        parser.add_argument('--enc_padding_1',
                            nargs='+',
                            default=(0, 1, 0, 1, 0, 1, 0, 0),
                            type=int)
        parser.add_argument('--enc_padding_2',
                            nargs='+',
                            default=(1, 1, 1, 1, 1, 1, 1, 0),
                            type=int)
        parser.add_argument('--enc_pooling_1',
                            nargs='+',
                            default=(1, 1, 1, 1, 1, 1, 1, 1),
                            type=int)
        parser.add_argument('--enc_pooling_2',
                            nargs='+',
                            default=(1, 1, 1, 1, 1, 1, 1, 1),
                            type=int)
        parser.add_argument('--enc_stride_1',
                            nargs='+',
                            default=(1, 1, 1, 1, 1, 1, 1, 1),
                            type=int)
        parser.add_argument('--enc_stride_2',
                            nargs='+',
                            default=(2, 1, 2, 1, 2, 1, 1, 1),
                            type=int)
        parser.add_argument('--enc_batch_norm', default=True, type=bool)
        parser.add_argument('--enc_batch_norm_affine',
                            default=False,
                            type=bool)
        parser.add_argument('--enc_dropout', default=0.2, type=float)
        parser.add_argument('--enc_residual', default=True, type=bool)
        parser.add_argument('--enc_bias', default=True, type=bool)

        # ar model
        parser.add_argument('--ar_channels',
                            nargs='+',
                            default=(512, 512, 512, 512, 512, 256, 256, 256,
                                     256, 256),
                            type=int)
        parser.add_argument('--ar_kernel_sizes',
                            nargs='+',
                            default=(5, 4, 1, 3, 3, 1, 3, 1, 5),
                            type=int)
        parser.add_argument('--ar_pooling',
                            nargs='+',
                            default=(1, 1, 2, 1, 1, 2, 1, 1, 1),
                            type=int)
        parser.add_argument('--ar_stride',
                            nargs='+',
                            default=(1, 1, 1, 1, 1, 1, 1, 1, 1),
                            type=int)
        parser.add_argument('--ar_self_attention',
                            nargs='+',
                            default=(False, True, False, False, True, False,
                                     True, False, False),
                            type=bool)
        parser.add_argument('--ar_batch_norm', default=True, type=bool)
        parser.add_argument('--ar_batch_norm_affine', default=False, type=bool)
        parser.add_argument('--ar_dropout', default=0.2, type=float)
        parser.add_argument('--ar_residual', default=True, type=bool)
        parser.add_argument('--ar_bias', default=True, type=bool)

        return parser
Пример #14
0
        torch.FloatTensor(content['wordEmbeddings']).to(device)
    }

    print('Training div: {} BLength {} {}'.format(
        train_div, p2r_data['bridge_length'],
        len(p2r_data['bridge_ids'].tolist())))
    return p2r_data


if __name__ == '__main__':

    # use default args given by lightning
    root_dir = os.path.dirname(
        os.path.realpath(sys.modules['__main__'].__file__))
    parent_parser = HyperOptArgumentParser(strategy='grid_search',
                                           add_help=False)
    parent_parser.add_argument('--root_dir', default=root_dir, type=str)
    parent_parser.add_argument('--exp_name',
                               default='p2r_experiment',
                               type=str)

    # allow model to overwrite or extend args
    parser = P2rSystem.add_model_specific_args(parent_parser, root_dir)
    hparams = parser.parse_args()

    p2r_data = loadData(hparams.data_root, hparams.train_div)

    # train model
    # for trial_hparams in hparams.trials(2):
    main(hparams, p2r_data)
Пример #15
0
def get_args():
    parser = HyperOptArgumentParser()
    parser.add_argument('--work_dir', metavar='DIR', default="./work_dir", type=str, help='path to save output')
    parser.add_argument('--name', type=str)
    parser.add_argument('--gpus', type=str, default='7', help='how many gpus')
    parser.add_argument('--dist_bd', type=str, default='dp',  choices=('dp', 'ddp', 'ddp2'),
                               help='supports three options dp, ddp, ddp2')
    parser.add_argument('--use_16bit', dest='use_16bit', action='store_true',
                               help='if true uses 16 bit precision')
    parser.add_argument('--eval', '--evaluate', dest='evaluate', action='store_true',
                               help='evaluate model on validation set')
    parser.add_argument('--seed', default=1, type=int)
    parser.add_argument('--load_mem', action='store_true')
    parser.add_argument('--track_grad_norm', action='store_true')

    parser = CGCNModel.add_model_specific_args(parser)
    return parser.parse_args()
Пример #16
0
    parser = HyperOptArgumentParser(usage=usage_str, description=description_str, formatter_class=argparse.ArgumentDefaultsHelpFormatter, strategy='random_search')

    parser.opt_range('--step', type=float, dest='step', default=.001, help='step size/learning rate', tunable=True, nb_samples=100, low=.0001, high=.001)
    parser.opt_range('--l2lam_init', action='store', type=float, dest='l2lam_init', default=.001, tunable=False, low=.0001, high=100, help='initial l2 regularization')
    parser.opt_list('--solver', action='store', dest='solver', type=str, tunable=False, options=['sgd', 'adam'], help='optimizer/solver ("adam", "sgd")', default="adam")
    parser.opt_range('--cg_max_iter', action='store', dest='cg_max_iter', type=int, tunable=False, low=1, high=20, help='max number of conjgrad iterations', default=10)
    parser.opt_range('--batch_size', action='store', dest='batch_size', type=int, tunable=False, low=1, high=20, help='batch size', default=2)
    parser.opt_range('--num_unrolls', action='store', dest='num_unrolls', type=int, tunable=False, low=1, high=10, nb_samples=4, help='number of unrolls', default=4)
    parser.opt_range('--num_admm', action='store', dest='num_admm', type=int, tunable=False, low=1, high=10, nb_samples=4, help='number of ADMM iterations', default=3)
    parser.opt_list('--network', action='store', dest='network', type=str, tunable=False, options=['ResNet', 'ResNet5Block'], help='which denoiser network to use', default='ResNet')
    parser.opt_list('--latent_channels', action='store', dest='latent_channels', type=int, tunable=False, options=[16, 32, 64, 128], help='number of latent channels', default=64)
    parser.opt_range('--num_blocks', action='store', dest='num_blocks', type=int, tunable=False, low=1, high=4, nb_samples=3, help='number of ResNetBlocks', default=3)
    parser.opt_range('--dropout', action='store', dest='dropout', type=float, tunable=False, low=0., high=.5, help='dropout fraction', default=0.)
    parser.opt_list('--batch_norm', action='store_true', dest='batch_norm', tunable=False, options=[True, False], help='batch normalization', default=False)

    parser.add_argument('--num_accumulate', action='store', dest='num_accumulate', type=int, help='nunumber of batch accumulations', default=1)
    parser.add_argument('--name', action='store', dest='name', type=str, help='experiment name', default=1)
    parser.add_argument('--version', action='store', dest='version', type=int, help='version number', default=None)
    parser.add_argument('--gpu', action='store', dest='gpu', type=str, help='gpu number(s)', default=None)
    parser.add_argument('--num_epochs', action='store', dest='num_epochs', type=int, help='number of epochs', default=20)
    parser.add_argument('--random_seed', action='store', dest='random_seed', type=int, help='random number seed for numpy', default=723)
    parser.add_argument('--recon', action='store', type=str, dest='recon', default='cgsense', help='reconstruction method')
    parser.add_argument('--data_file', action='store', dest='data_file', type=str, help='data.h5', default=None)
    parser.add_argument('--data_val_file', action='store', dest='data_val_file', type=str, help='data.h5', default=None)
    parser.add_argument('--num_data_sets', action='store', dest='num_data_sets', type=int, help='number of data sets to use', default=None)
    parser.add_argument('--num_workers', action='store', type=int,  dest='num_workers', help='number of workers', default=0)
    parser.add_argument('--shuffle', action='store_true', dest='shuffle', help='shuffle input data files each epoch', default=False)
    parser.add_argument('--clip_grads', action='store', type=float, dest='clip_grads', help='clip norm of gradient vector to val', default=0)
    parser.add_argument('--cg_eps', action='store', type=float, dest='cg_eps', help='conjgrad eps', default=1e-4)
    parser.add_argument('--stdev', action='store', type=float, dest='stdev', help='complex valued noise standard deviation', default=0.)
    parser.add_argument('--max_norm_constraint', action='store', type=float, dest='max_norm_constraint', help='norm constraint on weights', default=None)
Пример #17
0
    # define tensorflow graph
    x = tf.placeholder(dtype=tf.int32, name='x')
    y = tf.placeholder(dtype=tf.int32, name='y')
    out = x * y

    sess = tf.Session()

    # Run the tf op
    for train_step in range(0, 100):
        output = sess.run(out, feed_dict={x: hparams.x_val, y: hparams.y_val})
        exp.log({'fake_err': output})

    # save exp when we're done
    exp.save()


# set up our argparser and make the y_val tunable
parser = HyperOptArgumentParser(strategy='random_search')
parser.add_argument('--path', default='some/path')
parser.opt_list('--y_val', default=12, options=[1, 2, 3, 4], tunable=True)
parser.opt_list('--x_val', default=12, options=[20, 12, 30, 45], tunable=True)
hyperparams = parser.parse_args()

# optimize on 4 gpus at the same time
# each gpu will get 1 experiment with a set of hyperparams
hyperparams.optimize_parallel_gpu(train,
                                  gpu_ids=['1', '0', '3', '2'],
                                  nb_trials=4,
                                  nb_workers=4)
Пример #18
0
if __name__ == '__main__':

    # use default args
    root_dir = os.path.dirname(os.path.realpath(__file__))
    demo_log_dir = os.path.join(root_dir, 'pt_lightning_demo_logs')

    checkpoint_dir = os.path.join(demo_log_dir, 'model_weights')
    test_tube_dir = os.path.join(demo_log_dir, 'test_tube_data')
    slurm_out_dir = os.path.join(demo_log_dir, 'slurm_scripts')

    parent_parser = HyperOptArgumentParser(strategy='grid_search', add_help=False)

    # cluster args not defined inside the model

    parent_parser.add_argument('--per_experiment_nb_gpus', type=int,
                               default=8, help='how many gpus to use in a node')
    parent_parser.add_argument('--nb_gpu_nodes', type=int, default=2,
                               help='how many nodes to use in a cluster')
    parent_parser.add_argument('--test_tube_save_path', type=str, default=test_tube_dir,
                               help='where to save logs')
    parent_parser.add_argument('--slurm_log_path', type=str, default=slurm_out_dir,
                               help='where to save slurm meta')
    parent_parser.add_argument('--model_save_path', type=str, default=checkpoint_dir,
                               help='where to save model')
    parent_parser.add_argument('--distributed_backend', type=str, default='ddp',
                               help='ddp or ddp2')
    parent_parser.add_argument('--experiment_name', type=str, default='pt_lightning_exp_a',
                               help='test tube exp name')
    parent_parser.add_argument('--num_hyperparam_trials', type=int, default=6,
                               help='how many grid search trials to run')
Пример #19
0
def _train(_hparams):
    model = CNN(_hparams)

    trainer = Trainer(
        logger=TestTubeLogger(save_dir=".",
                              name="logs_{}".format(_hparams.name)),
        gpus=_hparams.gpus,
        row_log_interval=10,
        log_save_interval=100,
        # fast_dev_run=True,
        # overfit_pct=0.01,
        early_stop_callback=EarlyStopping(patience=3),
    )
    trainer.fit(model)
    trainer.test()


if __name__ == '__main__':
    parser = HyperOptArgumentParser(strategy='grid_search', add_help=False)
    parser.add_argument('--gpus', type=str, default=None)
    parser.add_argument('--train', action='store_true')
    parser.add_argument('--name', default='CNN', type=str)
    parser = CNN.add_model_specific_args(parser)
    hparams = parser.parse_args()

    if not torch.cuda.is_available():
        hparams.gpus = None

    if hparams.train:
        _train(hparams)
    def add_model_specific_args(
            cls, parser: HyperOptArgumentParser) -> HyperOptArgumentParser:
        """ Parser for Estimator specific arguments/hyperparameters.
        :param parser: HyperOptArgumentParser obj

        Returns:
            - updated parser
        """
        parser.add_argument(
            "--encoder_model",
            default="bert-base-uncased",
            type=str,
            help="Encoder model to be used.",
        )
        parser.add_argument(
            "--encoder_learning_rate",
            default=1e-05,
            type=float,
            help="Encoder specific learning rate.",
        )
        parser.add_argument(
            "--learning_rate",
            default=3e-05,
            type=float,
            help="Classification head learning rate.",
        )
        parser.opt_list(
            "--nr_frozen_epochs",
            default=1,
            type=int,
            help="Number of epochs we want to keep the encoder model frozen.",
            tunable=True,
            options=[0, 1, 2, 3, 4, 5],
        )
        # Data Args:
        parser.add_argument(
            "--label_set",
            default="pos,neg",
            type=str,
            help="Classification labels set.",
        )
        parser.add_argument(
            "--train_csv",
            default="data/imdb_reviews_train.csv",
            type=str,
            help="Path to the file containing the train data.",
        )
        parser.add_argument(
            "--dev_csv",
            default="data/imdb_reviews_test.csv",
            type=str,
            help="Path to the file containing the dev data.",
        )
        parser.add_argument(
            "--test_csv",
            default="data/imdb_reviews_test.csv",
            type=str,
            help="Path to the file containing the dev data.",
        )
        parser.add_argument(
            "--loader_workers",
            default=8,
            type=int,
            help="How many subprocesses to use for data loading. 0 means that \
                the data will be loaded in the main process.",
        )
        return parser
Пример #21
0
    # run hopt
    # creates and submits jobs to slurm
    cluster.optimize_parallel_cluster_gpu(
        main,
        nb_trials=24,
        job_name='grid_test'
    )

if __name__ ==  '__main__':

    # subclass of argparse
    parser = HyperOptArgumentParser(strategy='grid_search')

    #  params we don't want to search over. will use the default value
    parser.add_argument('--slurm_log_path', default=os.getcwd(), type=str, help='Save experiments here')
    parser.add_argument('--vocab_size', default=3432, type=int)
    parser.add_argument('--embed_size', default=150, type=int)
    parser.add_argument('--hidden_size', default=250, type=int)
    parser.add_argument('--num_workers', default=4, type=int)
    parser.add_argument('--num_layers', default=2, type=int)
    parser.add_argument('--batch_size', default=32, type=int)

    # params we want to search over

    #parser.opt_list('--embed_size', default=100, type=int, tunable=True, options=[150, 200, 250, 300])
    #arser.opt_list('--hidden_size', default=100, type=int, tunable=True, options=[100, 200, 300])
    #parser.opt_list('--num_layers', default=1, type=int, tunable=True, options=[1, 2])
    #parser.opt_list('--batch_size', default=32, type=int, tunable=True, options=[32, 64, 128])
    #parser.opt_list('--num_workers', default=15, type=int, tunable=True, options=[15])
Пример #22
0
    def add_model_specific_args(parent_parser, root_dir):  # pragma: no cover
        parser = HyperOptArgumentParser(strategy=parent_parser.strategy,
                                        parents=[parent_parser])

        parser.set_defaults(device=torch.device(
            'cuda' if torch.cuda.is_available() else 'cpu'))

        # network params
        parser.opt_list('--gcn_mid_dim',
                        default=256,
                        type=int,
                        options=[128, 256, 512, 1024],
                        tunable=True)
        parser.opt_list('--gcn_output_dim',
                        default=256,
                        type=int,
                        options=[128, 256, 512, 1024],
                        tunable=True)
        parser.opt_list('--txtcnn_drop_prob',
                        default=0.0,
                        options=[0.0, 0.1, 0.2],
                        type=float,
                        tunable=True)
        parser.opt_list('--gcn_drop_prob',
                        default=0.5,
                        options=[0.2, 0.5],
                        type=float,
                        tunable=True)
        parser.opt_list('--warploss_margin',
                        default=0.4,
                        type=float,
                        tunable=True)
        parser.opt_list('--freeze_embeddings',
                        default=True,
                        options=[True, False],
                        type=lambda x: (str(x).lower() == 'true'),
                        tunable=True)

        parser.opt_list('--txtcnn_pfilter_num1',
                        default=64,
                        options=[16, 32, 64, 128],
                        type=int,
                        tunable=True)
        parser.opt_list('--txtcnn_pfilter_num2',
                        default=64,
                        options=[16, 32, 64, 128],
                        type=int,
                        tunable=True)
        parser.opt_list('--txtcnn_pfilter_num3',
                        default=64,
                        options=[16, 32, 64, 128],
                        type=int,
                        tunable=True)
        parser.opt_list('--txtcnn_pfilter_num4',
                        default=64,
                        options=[16, 32, 64, 128],
                        type=int,
                        tunable=True)
        parser.opt_list('--txtcnn_rfilter_num1',
                        default=64,
                        options=[16, 32, 64, 128],
                        type=int,
                        tunable=True)
        parser.opt_list('--txtcnn_rfilter_num2',
                        default=32,
                        options=[16, 32, 64, 128],
                        type=int,
                        tunable=True)

        # data
        parser.add_argument('--data_root',
                            default=os.path.join(root_dir, 'data'),
                            type=str)
        parser.add_argument('--top_t', default=6, type=int)
        parser.add_argument('--total_onehop', default=20, type=int)
        parser.add_argument('--total', default=50, type=int)
        parser.add_argument('--shuffle',
                            default=True,
                            type=lambda x: (str(x).lower() == 'true'))
        parser.add_argument('--train_div', default=1.0, type=float)

        # training params (opt)
        parser.opt_list('--batch_size',
                        default=64,
                        options=[32, 64, 128, 256],
                        type=int,
                        tunable=False)
        parser.opt_list('--max_nb_epochs',
                        default=8,
                        options=[256, 512, 1024],
                        type=int,
                        tunable=False)
        parser.opt_list('--learning_rate',
                        default=0.0005,
                        options=[0.0001, 0.0005, 0.001],
                        type=float,
                        tunable=True)
        parser.opt_list('--weight_decay',
                        default=0.001,
                        options=[0.0001, 0.0005, 0.001],
                        type=float,
                        tunable=True)
        parser.add_argument('--model_save_path',
                            default=os.path.join(root_dir, 'experiment'),
                            type=str)
        return parser
    # Pretend to train.
    x = torch.rand((1, hparams.x_val))
    for train_step in range(0, 100):
        y = torch.rand((hparams.x_val, 1))
        out = x.mm(y)
        exp.log({'fake_err': out.item()})

    # Save exp when .
    exp.save()


if __name__ == '__main__':
    # Set up our argparser and make the y_val tunable.
    parser = HyperOptArgumentParser(strategy='random_search')
    parser.add_argument('--test_tube_exp_name', default='my_test')
    parser.add_argument('--log_path', default='/some/path/to/log')
    parser.opt_list('--y_val',
                    default=12,
                    options=[1, 2, 3, 4, 5, 6],
                    tunable=True)
    parser.opt_list('--x_val',
                    default=12,
                    options=[20, 12, 30, 45],
                    tunable=True)
    hyperparams = parser.parse_args()

    # Enable cluster training.
    cluster = SlurmCluster(hyperparam_optimizer=hyperparams,
                           log_path=hyperparams.log_path,
                           python_cmd='python3',
Пример #24
0
    def add_model_specific_args(parent_parser):
        parser = HyperOptArgumentParser(strategy=parent_parser.strategy,
                                        parents=[parent_parser],
                                        add_help=False)
        parser.opt_list('--q_drop',
                        default=0.35,
                        options=[0.25, 0.3, 0.35, 0.15, 0.4, 0.1],
                        type=float,
                        tunable=False)
        parser.add_argument('--q_hid_dim', default=1024, type=int)
        parser.add_argument('--padding_idx', type=int, default=0)

        parser.add_argument('--net_init', default='k_u')
        parser.opt_list('--iter_num',
                        default=3,
                        options=[1, 2, 3, 4, 5],
                        type=int)
        parser.add_argument('--g_init_method', default='full', type=str)

        parser.add_argument('--stem_in_dim', default=2048, type=int)
        parser.add_argument('--stem_out_dim', default=1024, type=int)
        parser.opt_list('--stem_norm',
                        default='custom',
                        options=['custom', 'layer', 'weight'],
                        type=str,
                        tunable=False)
        parser.opt_list('--stem_orders',
                        default='dlna',
                        options=['dlna', 'dnla'],
                        type=str,
                        tunable=False)
        parser.opt_list('--stem_drop',
                        default=0.35,
                        options=[0.3, 0.35, 0.4],
                        type=int)
        parser.opt_list('--stem_method',
                        default='linear',
                        options=['linear', 'film', 'double_linear'],
                        type=str)
        parser.add_argument('--stem_use_act', action='store_true')

        parser.opt_list('--e_f_norm',
                        default='weight',
                        options=['custom', 'layer', 'weight'],
                        type=str,
                        tunable=False)
        parser.opt_list('--e_f_orders',
                        default='dlna',
                        options=['dlna', 'dnla'],
                        type=str,
                        tunable=False)
        parser.opt_list('--e_f_drop',
                        default=0.35,
                        options=[0.3, 0.35, 0.4],
                        type=int)
        parser.add_argument('--e_dim', default=512, type=int)
        parser.opt_list('--e_f_method',
                        default='mul_film',
                        options=['mul_film', 'cat_film'],
                        type=str)
        parser.add_argument('--e_f_use_nGeo',
                            action='store_true',
                            default=True)

        parser.opt_list('--e_w_method',
                        default='linear_softmax_8',
                        options=['linear_softmax_10', 'linear_softmax_12'],
                        type=str)
        parser.opt_list('--e_w_norm',
                        default='weight',
                        options=['custom', 'layer', 'weight'],
                        type=str,
                        tunable=False)
        parser.opt_list('--e_w_orders',
                        default='dlna',
                        options=['dlna', 'dnla'],
                        type=str,
                        tunable=False)
        parser.opt_list('--e_w_drop',
                        default=0.35,
                        options=[0.3, 0.35, 0.4],
                        type=int)

        parser.opt_list('--e_p_method',
                        default='linear',
                        options=['linear', 'share'],
                        type=str)
        parser.opt_list('--e_p_norm',
                        default='weight',
                        options=['custom', 'layer', 'weight'],
                        type=str,
                        tunable=False)
        parser.opt_list('--e_p_orders',
                        default='dlna',
                        options=['dlna', 'dnla'],
                        type=str,
                        tunable=False)
        parser.opt_list('--e_p_drop',
                        default=0.35,
                        options=[0.3, 0.35, 0.4],
                        type=int)
        parser.opt_list('--e_p_act',
                        default='relu',
                        options=['relu', 'swish', 'elu'],
                        type=str,
                        tunable=False)

        parser.opt_list('--n_f_method',
                        default='film',
                        options=['linear', 'film'],
                        type=str)
        parser.opt_list('--n_f_drop',
                        default=0.35,
                        options=[0.3, 0.35, 0.4],
                        type=int)

        parser.opt_list('--n_geo_method',
                        default='cat',
                        options=['cat', 'sum', 'linear_cat'],
                        type=str)
        parser.add_argument('--n_geo_reuse', action='store_true', default=True)
        parser.add_argument('--n_geo_dim', default=64, type=int)
        parser.add_argument('--n_geo_out_dim', default=64, type=int)
        parser.opt_list('--n_geo_norm',
                        default='weight',
                        options=['custom', 'layer', 'weight'],
                        type=str,
                        tunable=False)
        parser.opt_list('--n_geo_orders',
                        default='lna',
                        options=['lna', 'nla'],
                        type=str,
                        tunable=False)

        parser.opt_list('--e_geo_method',
                        default='linear',
                        options=['linear', 'cat'],
                        type=str)
        parser.add_argument('--e_geo_dim', default=128, type=int)
        parser.add_argument('--e_geo_out_dim', default=128, type=int)
        parser.add_argument('--e_geo_reuse', action='store_true', default=True)
        parser.add_argument('--e_geo_aug', action='store_true')
        parser.opt_list('--e_geo_norm',
                        default='weight',
                        options=['custom', 'layer', 'weight'],
                        type=str,
                        tunable=False)
        parser.opt_list('--e_geo_orders',
                        default='lna',
                        options=['lna', 'nla'],
                        type=str,
                        tunable=False)

        parser.opt_list('--cls_method',
                        default='linear',
                        options=['linear'],
                        type=str)
        parser.opt_list('--cls_norm',
                        default='weight',
                        options=['custom', 'layer', 'weight'],
                        type=str,
                        tunable=False)
        parser.opt_list('--cls_orders',
                        default='dlna',
                        options=['dlna', 'dnla'],
                        type=str,
                        tunable=False)
        parser.opt_list('--cls_drop',
                        default=0.35,
                        options=[0.3, 0.35, 0.4],
                        type=int)
        parser.opt_list('--cls_act',
                        default='relu',
                        options=['relu', 'swish'],
                        type=str,
                        tunable=False)

        parser.opt_list('--f_c_norm',
                        type=str,
                        default='weight',
                        options=['weight', 'custom', 'layer'])
        parser.opt_list('--f_c_drop',
                        default=0.,
                        options=[0.3, 0.35, 0.4],
                        type=int)
        parser.opt_list('--f_c_orders',
                        default='dln',
                        options=['dln', 'dnl'],
                        type=str,
                        tunable=False)
        parser.opt_list('--f_x_norm',
                        default='layer',
                        options=['custom', 'layer', 'weight'],
                        type=str,
                        tunable=False)
        parser.opt_list('--f_x_orders',
                        default='dln',
                        options=['dln', 'dnl'],
                        type=str,
                        tunable=False)
        parser.add_argument('--f_x_norm_affine', action='store_true')
        parser.opt_list('--f_act',
                        default='relu',
                        options=['relu', 'swish', 'elu'],
                        type=str,
                        tunable=False)

        parser.opt_list('--pool_method',
                        default='mix',
                        options=['mix', 'mean', 'max'],
                        type=str)
        parser.opt_list('--lr',
                        default=2.5e-4,
                        type=float,
                        options=[2.5e-4, 3.5e-4],
                        tunable=False)
        parser.opt_list('--sched_factor',
                        default=0.5,
                        type=float,
                        options=[0.1, 0.8, 0.6, 0.3],
                        tunable=False)

        parser.opt_list('--optimizer',
                        type=str,
                        default='adam',
                        options=['adam', 'sgd'])
        parser.opt_list('--sched',
                        type=str,
                        default='plat',
                        options=['plat', 'cyclic', 'sgdr'])
        parser.opt_list('--dataset',
                        default='vqa2_cp',
                        type=str,
                        options=['vaq2_cp', 'gqa_lcgn'])
        parser.add_argument('--epochs', default=12, type=int)
        parser.add_argument('--batch_size', default=64, type=int)
        parser.add_argument('--num_workers', default=5, type=int)
        parser.add_argument('--grad_clip', default=0., type=float)
        parser.add_argument('--weight_decay', default=0., type=float)
        parser.add_argument('--use_warmup', action='store_true')
        return parser
if __name__ == '__main__':

    # dirs
    root_dir = os.path.dirname(os.path.realpath(__file__))
    demo_log_dir = os.path.join(root_dir, 'pt_lightning_demo_logs')
    checkpoint_dir = os.path.join(demo_log_dir, 'model_weights')
    test_tube_dir = os.path.join(demo_log_dir, 'test_tube_data')

    # although we user hyperOptParser, we are using it only as argparse right now
    parent_parser = HyperOptArgumentParser(strategy='grid_search',
                                           add_help=False)

    # gpu args
    parent_parser.add_argument('--test_tube_save_path',
                               type=str,
                               default=test_tube_dir,
                               help='where to save logs')
    parent_parser.add_argument('--model_save_path',
                               type=str,
                               default=checkpoint_dir,
                               help='where to save model')
    parent_parser.add_argument('--experiment_name',
                               type=str,
                               default='pt_lightning_exp_a',
                               help='test tube exp name')

    # allow model to overwrite or extend args
    parser = LightningTemplateModel.add_model_specific_args(
        parent_parser, root_dir)
    hyperparams = parser.parse_args()
Пример #26
0
                             options=[20, 30, 40, 50],
                             type=int,
                             tunnable=True)
parser.add_opt_argument_list('--embedding_dim',
                             default=320,
                             options=[100, 200, 320, 400],
                             type=int,
                             tunnable=True)
parser.add_opt_argument_list('--max_seq_len',
                             default=50,
                             options=[50, 70, 90, 110],
                             type=int,
                             tunnable=True)

# training params
parser.add_argument('--nb_epochs', default=1000, type=int)
parser.add_argument('--optimizer_name', default='adam')
parser.add_argument('--eval_every_n_batches', default=200, type=int)
parser.add_argument('--save_every_n_batches', default=10000, type=int)
parser.add_argument('--train_mode', default='train')

# model params
parser.add_argument('--nb_grams', default=2, type=int)

# path params
parser.add_argument('--root_dir', default='./data')
parser.add_argument('--dataset_train_path', default='./data/train.csv')
parser.add_argument('--dataset_test_path', default='./data/test.csv')
parser.add_argument('--dataset_val_path', default='./data/val.csv')
parser.add_argument('--vocab_path', default='./data/vocabulary.txt')
    def add_model_specific_args(parent_parser):
        parser = HyperOptArgumentParser(parents=[parent_parser])
        parser.add_argument('--num_freq_mask', default=1, type=int)
        parser.add_argument('--num_time_mask', default=1, type=int)
        parser.add_argument('--freq_mask_length', default=10, type=int)
        parser.add_argument('--time_mask_length', default=20, type=int)
        parser.add_argument('--feature_dim', default=320, type=int)
        parser.add_argument('--model_size', default=512, type=int)
        parser.add_argument('--feed_forward_size', default=512, type=int)
        parser.add_argument('--hidden_size', default=64, type=int)
        parser.add_argument('--dropout', default=0.1, type=float)
        parser.add_argument('--num_head', default=4, type=int)
        parser.add_argument('--num_layer', default=4, type=int)
        parser.add_argument('--vocab_path',
                            default='testing_vocab.model',
                            type=str)
        parser.add_argument('--max_feature_length', default=1024, type=int)
        parser.add_argument('--max_token_length', default=50, type=int)

        parser.add_argument('--lr', default=3e-4, type=float)
        parser.add_argument('--enable_spec_augment', default=False, type=bool)

        parser.add_argument('--train_batch_size', default=16, type=int)
        parser.add_argument('--train_loader_num_workers', default=4, type=int)
        parser.add_argument('--val_batch_size', default=16, type=int)
        parser.add_argument('--val_loader_num_workers', default=4, type=int)

        return parser
Пример #28
0
    GPUs = ['0', '1', '2', '4']
    os.environ["CUDA_VISIBLE_DEVICES"] = GPUs[job_index_nb]
    main_trainer(trial_params)


if __name__ == '__main__':
    parser = HyperOptArgumentParser(strategy='random_search')
    parser.add_opt_argument_list('--time_steps', default=3, options=[3, 5, 7, 9, 11], type=int, help='number of sequential readings', tunnable=False)

    # model params
    parser.add_opt_argument_list('--gamma', default=0.00001, options=[0.00001], type=int, tunnable=False)
    parser.add_opt_argument_list('--kernel', default='rbf', options=['rbf'], type=str, tunnable=False)
    parser.add_opt_argument_list('--C', default=4, options=[4, 5, 6], type=int, tunnable=False)

    parser.add_argument('--nb_trials', default=200, type=int)

    # path vars
    parser.add_argument('--data_path', default='/Users/waf/Developer/temp_floor/floor/data/in_out_classifier_data/data')
    parser.add_argument('--model_save_path', default='/Users/waf/Developer/temp_floor/floor/logs/weights/svm')
    parser.add_argument('--tt_save_path', default='/Users/waf/Developer/temp_floor/floor/logs/training_logs/svm')
    parser.add_argument('--tt_name', default='svm_final_1')
    parser.add_argument('--tt_description', default='hyperopt')
    parser.add_argument('--debug', default=False, type=bool)
    parser.add_argument('--local', default=True, type=bool)
    parser.add_json_config_argument('--config', default='/Users/waf/Developer/temp_floor/floor/logs/run_configs/local.json')

    hyperparams = parser.parse_args()
    os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID"

    if hyperparams.local:
Пример #29
0
    feed_dict = {input_x: text_enc, input_y: labels_enc}
    out_value, out_score = sess.run([value, score], feed_dict=feed_dict)
    print('label: ', labels[out_value])
    print('score: ', out_score)


if __name__ == '__main__':
    parser = HyperOptArgumentParser(strategy='random_search')
    # path params
    parser.add_opt_argument_list('--lr_1', default=0.0001, options=[0.0001, 0.0002, 0.0004, 0.0008, 0.001, 0.002],
                                 type=float,
                                 tunnable=True)
    parser.add_opt_argument_list('--batch_size', default=10, options=[20, 30, 40, 50], type=int, tunnable=True)
    parser.add_opt_argument_list('--embedding_dim', default=320, options=[100, 200, 320, 400], type=int, tunnable=True)

    parser.add_argument('--root_dir', default='./data')
    parser.add_argument('--dataset_train_path', default='./data/train.csv')
    parser.add_argument('--dataset_test_path', default='./data/test.csv')
    parser.add_argument('--dataset_val_path', default='./data/val.csv')
    parser.add_argument('--vocab_path', default='./data/vocabulary.txt')
    parser.add_opt_argument_list('--max_seq_len', default=50, options=[50, 70, 90, 110], type=int, tunnable=True)

    parser.add_argument('--epoch', default=0)
    parser.add_argument('--step', default='FINAL')
    parser.add_argument('--model_save_dir', default='./experiments')
    parser.add_argument('--test_tube_dir', default='')

    # experiment params
    parser.add_argument('--exp_name', default='dual_conv_dense')
    hparams = parser.parse_args()
    test_main(hparams=hparams)
Пример #30
0
    checkpoint_path = experiment_folder + "/checkpoints/" + checkpoints[-1]
    model = BERTClassifier.load_from_metrics(weights_path=checkpoint_path,
                                             tags_csv=tags_csv_file)
    # Make sure model is in prediction mode
    model.eval()
    model.freeze()

    return model


if __name__ == "__main__":
    parser = HyperOptArgumentParser(description="Minimalist BERT Classifier",
                                    add_help=True)
    parser.add_argument(
        "--experiment",
        default=
        '../../data/experiments/lightning_logs/version_29-04-2020--22-14-10',
        type=str,
        help="Path to the experiment folder.")
    hparams = parser.parse_args()
    print("Loading model...")
    model = load_model_from_experiment(hparams.experiment)
    print(model)

    print("Please write a movie review or quit to exit the interactive shell:")
    # Get input sentence

    test_path = '../../data/output/test.csv'
    test = pd.read_csv(test_path, encoding='utf-8')

    labels = []
    for index in range(test.shape[0]):