Exemple #1
0
def call_experiment(args):
    kwargs = {}

    print args
    model = args['model']['model']
    kwargs['model_type'] = model
    if model == 'SVM':
        kwargs['regularizer'] = args['model']['regularizer_svm']
        kwargs['alpha'] = args['model']['C_svm']
    elif model == 'LR':
        kwargs['regularizer'] = args['model']['regularizer_lr']
        kwargs['alpha'] = args['model']['alpha_lr']

    feature_list = []
    unigrams = 'ngrams,n=1' + \
               ',binarize=' + args['features']['unigrams']['u_binarize'] + \
               ',min_doc_threshold=' + str(args['features']['unigrams']['u_min_doc_threshold'])
    feature_list.append(unigrams)
    if args['features']['bigrams']['use']:
        bigrams = 'ngrams,n=2' + \
                  ',binarize=' + args['features']['bigrams']['b_binarize'] + \
                  ',min_doc_threshold=' + str(args['features']['bigrams']['b_min_doc_threshold'])
        feature_list.append(bigrams)

    print feature_list
    result = classify_test.classify(data_filename, label_filename, feature_dir, feature_list, **kwargs)
    with codecs.open(log_filename, 'a') as output_file:
        output_file.write(str(datetime.datetime.now()) + '\t' + ' '.join(feature_list) + '\t' + ' '.join(kwargs) +
                          '\t' + str(-result['loss']) + '\n')

    return result
Exemple #2
0
def call_experiment(args):
    global trial_num
    trial_num = trial_num + 1
    print model_dir
    if line_num: #if reading from file
        print 'file'
        new_model_dir = model_dir
    else:
        new_model_dir = model_dir + str(trial_num) + '/'
        os.makedirs(new_model_dir)
    print new_model_dir
    feats_and_args = {}
    all_description = []
    for i in range(num_models):
        feature_list, description, kwargs = wrangle_params(args, str(i))
        all_description = all_description + description
        feats_and_args[i] = {'feats':feature_list, 'params':kwargs}


    result = classify_test.classify(train_data_filename, train_label_filename, dev_data_filename,
                                    dev_label_filename, train_feature_dir, dev_feature_dir,
                                    new_model_dir, word2vec_filename, feats_and_args, folds=num_folds)



    with codecs.open(log_filename, 'a') as output_file:
        output_file.write(str(datetime.datetime.now()) + '\t' + ' '.join(all_description) +
                          '\t' + str(-result['loss']) + '\n')
    save_model(result)

    print("\nFinished iteration " + str(trial_num) + ".\n\n\n")
    sys.stdout.flush()
    return result
Exemple #3
0
def call_experiment(args):
    global trial_num
    trial_num = trial_num + 1
    feature_list, description, kwargs = wrangle_params(args)
    result = classify_test.classify(train_data_filename, train_label_filename, dev_data_filename, 
                                    dev_label_filename, train_feature_dir, dev_feature_dir, 
                                    feature_list, **kwargs)
    with codecs.open(log_filename, 'a') as output_file:
        output_file.write(str(datetime.datetime.now()) + '\t' + ' '.join(feature_list) + '\t' + ' '.join(description) +
                          '\t' + str(-result['loss']) + '\n')
    save_model(result['model'], feature_list, kwargs, result)

    print("\nFinished iteration " + str(trial_num) + ".\n\n\n")
    return result
Exemple #4
0
def call_experiment(args):
    global trial_num
    trial_num = trial_num + 1
    feature_list, description, kwargs = wrangle_params(args)
    result = classify_test.classify(train_data_filename, train_label_filename,
                                    dev_data_filename, dev_label_filename,
                                    train_feature_dir, dev_feature_dir,
                                    feature_list, **kwargs)
    with codecs.open(log_filename, 'a') as output_file:
        output_file.write(
            str(datetime.datetime.now()) + '\t' + ' '.join(feature_list) +
            '\t' + ' '.join(description) + '\t' + str(-result['loss']) + '\n')
    save_model(result['model'], feature_list, kwargs)

    print("\nFinished iteration " + str(trial_num) + ".\n\n\n")
    return result
Exemple #5
0
def call_experiment(args):
    #in case we want to debug the BO algorithms
    #import pdb; pdb.set_trace()
    debug_mode = False
    if debug_mode:
        import random
        from hyperopt import STATUS_OK
        return {'loss': random.random(), 'status': STATUS_OK}

    global trial_num
    trial_num = trial_num + 1
    print model_dir
    if line_num:  #if reading from file
        print 'file'
        new_model_dir = model_dir
    else:
        new_model_dir = model_dir + str(trial_num) + '/'
        os.makedirs(new_model_dir)
    print new_model_dir
    feats_and_args = {}
    all_description = []
    for i in range(num_models):
        feature_list, description, kwargs = wrangle_params(args, str(i))
        all_description = all_description + description
        feats_and_args[i] = {'feats': feature_list, 'params': kwargs}

    result = classify_test.classify(train_data_filename,
                                    train_label_filename,
                                    dev_data_filename,
                                    dev_label_filename,
                                    train_feature_dir,
                                    dev_feature_dir,
                                    new_model_dir,
                                    word2vec_filename,
                                    feats_and_args,
                                    folds=num_folds)

    with codecs.open(log_filename, 'a') as output_file:
        output_file.write(
            str(datetime.datetime.now()) + '\t' + ' '.join(all_description) +
            '\t' + str(-result['loss']) + '\n')
    save_model(result)

    print("\nFinished iteration " + str(trial_num) + ".\n\n\n")
    sys.stdout.flush()
    return result