예제 #1
0
파일: run.py 프로젝트: benbo/botc
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
예제 #2
0
파일: run.py 프로젝트: katyasyc/ARKcat
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
예제 #3
0
파일: run.py 프로젝트: anukat2015/ARKcat
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
예제 #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
예제 #5
0
파일: run.py 프로젝트: codeaudit/ARKcat
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