Exemplo n.º 1
0
            # [layer2, 2, -1, 'valid', (2, 1), 0.25, 'relu', 'none']
        ],
        full_connected_layer_units=[
            # (hidden1, 0.5, 'relu', 'batch_normalization'),
            # (hidden2, 0.5, 'relu', 'none'),
        ],
        embedding_dropout_rate=0.,
        nb_epoch=30,
        nb_batch=5,
        earlyStoping_patience=20,
        lr=1e-2,
    )
    onehot_cnn.print_model_descibe()

    print(onehot_cnn.fit(
        (train_X_feature, train_y),
        (test_X_feature, test_y)))
# onehot_cnn.accuracy((train_X_feature, train_y), transform_input=False)

y_pred, is_correct, accu, f1, test_loss = onehot_cnn.accuracy((test_X_feature, test_y))
result_file_path = 'result/onehot_%s_%d.csv' % (feature_type, rand_seed)
data_util.save_result(test_data, predict=y_pred, is_correct=is_correct, path=result_file_path)

logging.debug('=' * 20)
# ****************************************************************
# ------------- region end : 3、构建onehot编码 -------------
# ****************************************************************


logging.debug('=' * 20)
# ------------------------------------------------------------------------------
Exemplo n.º 2
0
                        [layer1, 2, -1, "valid", [-2, 1]],
                        #                        [100,3,*word_embedding_dim,'valid',[1,1]],
                        [layer1, 4, -1, "valid", [-2, 1]],
                        [layer1, 6, -1, "valid", [-2, 1]],
                    ],
                    conv2_filter_type=[[layer2, 3, -1, "valid", [-2, 1]]],
                    full_connected_layer_units=[hidden1, hidden2],
                    output_dropout_rate=0.5,
                    nb_epoch=30,
                    nb_batch=32,
                    earlyStoping_patience=30,
                    lr=1e-2,
                )
                onehot_cnn.print_model_descibe()

                onehot_cnn.fit((train_X_feature, train_y), (test_X_feature, test_y))
                onehot_cnn.accuracy((train_X_feature, train_y), transform_input=False)
                onehot_cnn.accuracy((test_X_feature, test_y), transform_input=False)

                # 五折
                print ("五折")
                counter = 0
                for dev_X, dev_y, val_X, val_y in data_util.get_k_fold_data(k=5, data=(train_X_feature, train_y)):
                    counter += 1

                    # quit()
                    #
                    print ("第%d个验证" % counter)
                    print ("-" * 80)

                    onehot_cnn = OnehotBowCNN(