Esempio n. 1
0
def load_classifier(auto_parse=False, fname=None):
    if auto_parse:
        ac = load_imported_data_for_antecedent(fname=fname)
    else:
        ac = AntecedentClassifier(0, 14, 15, 19, 20, 24)
        ac.load_imported_data(fname=(AUTO_PARSE_NPY_DATA if auto_parse else GOLD_PARSE_FULL_NPY_DATA))
    return ac
Esempio n. 2
0
def load_classifier(auto_parse=False, fname=None):
    if auto_parse:
        ac = load_imported_data_for_antecedent(fname=fname)
    else:
        ac = AntecedentClassifier(0, 14, 15, 19, 20, 24)
        ac.load_imported_data(fname=(
            AUTO_PARSE_NPY_DATA if auto_parse else GOLD_PARSE_FULL_NPY_DATA))
    return ac
Esempio n. 3
0
def load_imported_data_for_antecedent(fname=AUTO_PARSE_NPY_DATA):
    ac = AntecedentClassifier(0, 14, 15, 19, 20, 24)

    print 'Loading NPY data from this file:',fname

    data = np.load(fname)

    ac.sentences = data[0]
    ac.train_triggers = data[1]
    ac.val_triggers = data[2]
    ac.test_triggers = data[3]

    for i,sentwords in enumerate(data[4]):
        ac.sentences[i].words = sentwords

    return ac
Esempio n. 4
0
def load_imported_data_for_antecedent(fname=AUTO_PARSE_NPY_DATA):
    ac = AntecedentClassifier(0, 14, 15, 19, 20, 24)

    print 'Loading NPY data from this file:', fname

    data = np.load(fname)

    ac.sentences = data[0]
    ac.train_triggers = data[1]
    ac.val_triggers = data[2]
    ac.test_triggers = data[3]

    for i, sentwords in enumerate(data[4]):
        ac.sentences[i].words = sentwords

    return ac
Esempio n. 5
0
            c, lr, k = float(splitt[1][1:]), float(splitt[2][2:]), float(
                splitt[3][1:])
            combos.add((c, lr, k))
    return combos


if __name__ == '__main__':
    grid = build_grid([[0.001, 0.005, 0.01, 0.05, 0.1, 0.5, 1.0],
                       [0.001, 0.005, 0.01, 0.05, 0.1, 0.5, 1.0],
                       [int(argv[1])]])
    completed = completed_combos()

    print 'How much we need versus how much we did: %d, %d' % (len(grid),
                                                               len(completed))

    a = AntecedentClassifier(0, 14, 15, 19, 20, 24)
    a.initialize(['VP', wc.is_adjective, wc.is_verb],
                 seed=9001,
                 save=False,
                 load=True,
                 update=False)

    for combo in grid:
        if combo not in completed:
            print "Current Params: ", combo
            a.C = combo[0]
            a.learn_rate = lambda x: combo[1]
            name = 'NEWFEATURES_c%s_lr%s_k%s_' % (combo[0], combo[1], combo[2])

            a.fit(epochs=100, k=combo[2])
            a.make_graphs(name)
Esempio n. 6
0
    return ac


if __name__ == '__main__':
    mrg = 'mrg' in argv
    save_file = GOLD_PARSE_FULL_NPY_DATA if mrg else AUTO_PARSE_ALL_ANTS_NPY
    results_save = 'final_results_ALL_TYPES_ALL_ANTS_WITH_LIU_c%s_lr%s.txt' % (
        str(C), str(LR))

    if 'gen2' in argv:
        AUTO_PARSE_ALL_ANTS_NPY = AUTO_PARSE_ALL_ANTS_NPY[:-4] + '_antgen2.npy'
        results_save = results_save[:-4] + '_antgen2.txt'

    if 'build' in argv:
        ac = AntecedentClassifier(0, 14, 15, 19, 20, 24)
        ac.import_data(get_mrg=mrg)
        # save_imported_data_for_antecedent(ac, fname=save_file)
        # exit(0)

        ac = load_imported_data_for_antecedent(fname=save_file)
        ac.generate_possible_ants(
            ['VP', wc.is_predicative, wc.is_adjective, wc.is_verb],
            filter=True)
        ac.debug_ant_selection()
        # save_imported_data_for_antecedent(ac, fname=save_file)
        # exit(0)

        ac.build_feature_vectors()
        ac.normalize()
        save_imported_data_for_antecedent(ac, fname=save_file)
Esempio n. 7
0
    for i,sentwords in enumerate(data[4]):
        ac.sentences[i].words = sentwords

    return ac

if __name__ == '__main__':
    mrg = 'mrg' in argv
    save_file = GOLD_PARSE_FULL_NPY_DATA if mrg else AUTO_PARSE_ALL_ANTS_NPY
    results_save = 'final_results_ALL_TYPES_ALL_ANTS_WITH_LIU_c%s_lr%s.txt' %(str(C), str(LR))

    if 'gen2' in argv:
        AUTO_PARSE_ALL_ANTS_NPY = AUTO_PARSE_ALL_ANTS_NPY[:-4]+'_antgen2.npy'
        results_save = results_save[:-4]+'_antgen2.txt'

    if 'build' in argv:
        ac = AntecedentClassifier(0,14,15,19,20,24)
        ac.import_data(get_mrg=mrg)
        # save_imported_data_for_antecedent(ac, fname=save_file)
        # exit(0)

        ac = load_imported_data_for_antecedent(fname=save_file)
        ac.generate_possible_ants(['VP', wc.is_predicative, wc.is_adjective, wc.is_verb], filter=True)
        ac.debug_ant_selection()
        # save_imported_data_for_antecedent(ac, fname=save_file)
        # exit(0)

        ac.build_feature_vectors()
        ac.normalize()
        save_imported_data_for_antecedent(ac, fname=save_file)

    if 'types' in argv:
Esempio n. 8
0
            splitt = fname.split('_')
            c, lr, k = float(splitt[1][1:]), float(splitt[2][2:]), float(splitt[3][1:])
            combos.add((c,lr,k))
    return combos

if __name__ == '__main__':
    grid = build_grid(
         [[0.001, 0.005, 0.01, 0.05, 0.1, 0.5, 1.0],
          [0.001, 0.005, 0.01, 0.05, 0.1, 0.5, 1.0],
          [int(argv[1])]]
    )
    completed = completed_combos() 

    print 'How much we need versus how much we did: %d, %d'%(len(grid),len(completed))

    a = AntecedentClassifier(0,14, 15,19, 20,24)
    a.initialize(['VP', wc.is_adjective, wc.is_verb], seed=9001, save=False, load=True, update=False)

    for combo in grid:
        if combo not in completed:
            print "Current Params: ",combo
            a.C = combo[0]
            a.learn_rate = lambda x: combo[1]
            name = 'NEWFEATURES_c%s_lr%s_k%s_'%(combo[0], combo[1], combo[2])

            a.fit(epochs=100, k=combo[2])
            a.make_graphs(name)
            a.log_results(name)
            np.save('saved_weights/'+name, np.array(a.W_avg))

            a.reset()