Beispiel #1
0
def main():
    # get hyperparameters from input args
    opt = ArgParser().get_options()

    # deterministic seed across numpy, torch and cuda
    # store as variable due to garbage collecting
    seeder = Seeder(opt.seed)
    seeder.activate()

    # data from ./zoo.py
    opt.model_class = models[opt.model_name]
    opt.initializer = initializers[opt.initializer]
    opt.optimizer = optimizers[opt.optimizer]
    # data from ./config.yml
    opt.dataset_file = config['datasets'][opt.dataset]
    opt.model_inputs = config['model_inputs'][opt.model_name]

    # run on gpu if available
    device = opt.device
    if device is None:
        device = 'cuda' if torch.cuda.is_available() else 'cpu'
    opt.device = torch.device(device)

    runner = ModelRunner(opt)
    runner.run()
        print 'Time : %d seconds' % (t2 - t1)

        # build the model
        print 'build the model...'
        t1 = time.time()
        runner = ModelRunner(train_data,
                             vad_data,
                             None,
                             X_sppmi,
                             X_neg_sppmi,
                             Y_sppmi,
                             None,
                             save_dir=save_dir)
        U, V, ndcg100 = runner.run("rme",
                                   n_jobs=1,
                                   lam=lam,
                                   lam_emb=lam_emb,
                                   n_components=n_components,
                                   ret_params_only=1)
        t2 = time.time()
        print 'Time : %d seconds' % (t2 - t1)
        print '*************************************ITER %d ******************************************' % iter
        print 'NDCG@100 at this iter:', ndcg100
        #
        if best_ndcg100 < ndcg100:
            best_iter = iter
            best_ndcg100 = ndcg100
        else:
            early_stopping = True
        iter += 1
        #########################################################
    print 'Max NDCG@100: %f , at iter: %d' % (best_ndcg100, best_iter)