Exemple #1
0
def main(argv):
    options, remainder = getopt.getopt(argv, "o:v", ["train_file="])

    # Parse the arguments
    for opt, arg in options:
        if opt == "--train_file":
            train_file = arg

    # Featurize the train_file:
    global templated_data
    global y_list
    templated_data, y_list = featurize_file(train_file)

    # Initialize the sparse weights vector:
    global w_vec
    w_vec = np.zeros((1, n_features))
    # w_vec[0,13] = 1
    # w_vec[0,18] = 1
    # w_vec[0,7] = 1
    # w_vec[0,11] = 1
    # w_vec[0,100]=45

    # Train:
    # train(templated_data, hashed_feature_matrix)
    train(1, templated_data)
Exemple #2
0
def main(argv):
    options, remainder = getopt.getopt(argv, 'o:v', ['train_file=',])

    # Parse the arguments
    for opt, arg in options:
        if opt == '--train_file':
            train_file = arg
            # print train_file

    # Featurize the train_file:
    # templated_data, hashed_feature_matrix = featurize_file(train_file)
    global templated_data
    global y_list
    templated_data, y_list = featurize_file(train_file)
    # print templated_data
    # print y_list
    # exit()

    # Initialize the sparse weights vector:
    global w_vec

    # w_vec = lil_matrix((1,n_features))
    # w_vec = np.ones((1,n_features))
    # w_vec = np.full((1,n_features),0.1)
    w_vec = np.zeros((1,n_features))
    # w_vec[0,13] = 1
    # w_vec[0,18] = 1
    # w_vec[0,7] = 1
    # w_vec[0,11] = 1
    # print w_vec
    # w_vec[0,100]=45
    # w_vec = sparse.csr_matrix(w_vec)
    # exit()

    # Debug:
    # Sentence 0, token 1's features
    # print templated_data[0][1]['F']
    # print templated_data[0][1]
    # Sentence 0, token 1's hashed features
    # print hashed_feature_matrix
    # exit()

    # Train:
    # train(templated_data, hashed_feature_matrix)
    train(templated_data)
    exit()

    # Train using the SGD:
    SGD(5, templated_data)