Beispiel #1
0
    word_vecs_rand, word_vecs, word_cab, sentence_max_len, revs = X[0], X[
        1], X[2], X[3], X[4]

    print('load data finish. . .')
    # configuration tf
    filter_sizes = [3, 4, 5]
    filter_numbers = 100
    embedding_size = 300
    # use word2vec or not
    W = word_vecs_rand
    if args.wordvec_flag:
        W = word_vecs
        pass
    # pdb.set_trace()
    word_ids, W_list = process_data.getWordsVect(W)

    # use static train or not
    static_falg = args.static_flag
    # use shuffer the data or not
    shuffer_falg = args.shuffer_flag
    #交叉验证
    results = []
    for index in tqdm(range(10)):
        #打调试断点
        # pdb.set_trace()
        # train_x, train_y, test_x, test_y = process_data.get_train_test_data1(W,revs,index,sentence_max_len,default_values=0.0,vec_size=300)
        train_x, train_y, test_x, test_y = process_data.get_train_test_data2(
            word_ids, revs, index, sentence_max_len)
        # step3 create TextCNN model
        text_cnn = TextCNN(W_list, shuffer_falg, static_falg, filter_numbers,
Beispiel #2
0
    # 混淆矩阵
    print("Confusion Matrix...")
    cm = metrics.confusion_matrix(y_test_cls, y_pred_cls)
    print(cm)

    time_dif = get_time_dif(start_time)
    print("Time usage:", time_dif)


if __name__ == '__main__':
    if len(sys.argv) != 2 or sys.argv[1] not in ['train', 'test']:
        raise ValueError("""usage: python run_rnn.py [train / test]""")

    print('Configuring RNN model...')

    print('load data. . .')
    X = pickle.load(open(train_data, 'rb'))
    df, word_vecs, word_cab_num, sentence_max_len, class_num = X[0], X[1], X[2], X[3], X[4]

    config = TRNNConfig(sentence_max_len, class_num, word_cab_num)

    word_ids, W_list = process_data.getWordsVect(config, word_vecs)

    model = TextRNN(config, W_list, False) #默认不训练词向量


    if sys.argv[1] == 'train':
        train()
    else:
        test()