logging.debug('-' * 20)
        print '-' * 20
        logging.debug('4. 预测')
        print '4. 预测'
    # -------------- code start : 开始 -------------

    y_predict = map(rand_embedding_cnn.predict,test_X_feature)
    test_data[u'Y_PRED'] = [index_to_label[item] for item in y_predict]
    data_util.save_data(test_data,path=result_file_path)

    quit()
    rand_embedding_cnn.predict(feature_encoder.transform_sentence('你好吗'))

    print index_to_label[rand_embedding_cnn.predict(feature_encoder.transform_sentence('你好吗'))]

    y_pred, is_correct, accu,f1 = rand_embedding_cnn.accuracy((test_X_feature, test_y))
    logging.debug('F1(macro)为:%f'%(np.average(f1[:-1])))
    print 'F1(macro)为:%f'%(np.average(f1[:-1]))
    test_data[u'IS_CORRECT'] = is_correct
    test_data[u'PREDICT'] = [index_to_label[item] for item in y_pred]
    # data_util.save_data(test_data,'tmp.tmp')
    # quit()
    data_util.save_data(test_data,
                        path=result_file_path)


    # -------------- region start : 生成深度特征编码 -------------
    if verbose > 1 :
        logging.debug('-' * 20)
        print('-' * 20)
        logging.debug('生成深度特征编码')
Exemplo n.º 2
0
        print '-' * 20
    # -------------- region end : 3. 初始化CNN模型并训练 ---------------

    # -------------- region start : 4. 预测 -------------
    if verbose > 1:
        logging.debug('-' * 20)
        print '-' * 20
        logging.debug('4. 预测')
        print '4. 预测'
    # -------------- code start : 开始 -------------



    print index_to_label[rand_embedding_cnn.predict(feature_encoder.transform_sentence('你好吗'))]

    y_pred, is_correct, accu,f1 = rand_embedding_cnn.accuracy((map(feature_encoder.transform_sentence, test_X), test_y))
    logging.debug('F1(macro)为:%f'%(np.average(f1[:-1])))
    print 'F1(macro)为:%f'%(np.average(f1[:-1]))
    test_data[u'IS_CORRECT'] = is_correct
    test_data[u'PREDICT'] = [index_to_label[item] for item in y_pred]
    # data_util.save_data(test_data,'tmp.tmp')
    # quit()
    result_file_path = ''.join(config['result_file_path'])

    data_util.save_data(test_data,
                        path=result_file_path)

    # -------------- code start : 结束 -------------
    if verbose > 1:
        logging.debug('-' * 20)
        print '-' * 20
Exemplo n.º 3
0
                word_embedding_dim=config["word_embedding_dim"],
                input_length=sentence_padding_length,
                num_labels=len(label_to_index),
                l1_conv_filter_type=config["l1_conv_filter_type"],
                l2_conv_filter_type=config["l2_conv_filter_type"],
                full_connected_layer_units=config["full_connected_layer_units"],
                embedding_dropout_rate=config["embedding_dropout_rate"],
                output_dropout_rate=config["output_dropout_rate"],
                nb_epoch=int(config["cnn_nb_epoch"]),
                earlyStoping_patience=config["earlyStoping_patience"],
                lr=config["lr"],
                batch_size=config["batch_size"],
            )

            rand_embedding_cnn.fit((dev_X, dev_y), (val_X, val_y))
            y_pred, is_correct, accu, f1 = rand_embedding_cnn.accuracy((val_X, val_y))

            # print 'F1(macro)为:%f' % (np.average(f1))

            # train
            rand_embedding_cnn.accuracy((train_X_feature, train_y))
    else:
        # 从保存的pickle中加载模型
        rand_embedding_cnn.model_from_pickle(model_file_path)

    logging.debug("CNN-static模型已经编译完毕...")
    print "CNN-static模型已经编译完毕..."


end_time = timeit.default_timer()
print "end! Running time:%ds!" % (end_time - start_time)
Exemplo n.º 4
0
        print '-' * 20
        logging.debug('4. 预测')
        print '4. 预测'
    # -------------- code start : 开始 -------------

    y_predict = map(rand_embedding_cnn.predict, test_X_feature)
    test_data[u'Y_PRED'] = [index_to_label[item] for item in y_predict]
    data_util.save_data(test_data, path=result_file_path)

    quit()
    rand_embedding_cnn.predict(feature_encoder.transform_sentence('你好吗'))

    print index_to_label[rand_embedding_cnn.predict(
        feature_encoder.transform_sentence('你好吗'))]

    y_pred, is_correct, accu, f1 = rand_embedding_cnn.accuracy(
        (test_X_feature, test_y))
    logging.debug('F1(macro)为:%f' % (np.average(f1[:-1])))
    print 'F1(macro)为:%f' % (np.average(f1[:-1]))
    test_data[u'IS_CORRECT'] = is_correct
    test_data[u'PREDICT'] = [index_to_label[item] for item in y_pred]
    # data_util.save_data(test_data,'tmp.tmp')
    # quit()
    data_util.save_data(test_data, path=result_file_path)

    # -------------- region start : 生成深度特征编码 -------------
    if verbose > 1:
        logging.debug('-' * 20)
        print('-' * 20)
        logging.debug('生成深度特征编码')
        print('生成深度特征编码')
    # -------------- code start : 开始 -------------