Пример #1
0
def evaluate_test():
    test = pd.read_csv(Config.test_data_path, sep='\t')
    test_labels = test.label.values
    test_labels = to_categorical(test_labels)
    test_pro_cnn = pickle.load(open(Config.cache_dir + '/probe/cnn/test/2.pk', 'rb'))
    test_pro_rnn = pickle.load(open(Config.cache_dir + '/probe/rnn/test/2.pk', 'rb'))
    test_pro_rcnn = pickle.load(open(Config.cache_dir + '/probe/rcnn/test/1.pk', 'rb'))
    test_pro_deep_cnn = pickle.load(open(Config.cache_dir+'/probe/deep_cnn/test/0.pk', 'rb'))
    test_pro_word_rcnn_char_rnn = pickle.load(open(Config.cache_dir + '/probe/word_rcnn_char_rnn/test/2.pk', 'rb'))
    test_pro_word_rnn_char_rcnn = pickle.load(open(Config.cache_dir + '/probe/word_rnn_char_rcnn/test/2.pk', 'rb'))
    test_pro_word_char_cgru = pickle.load(open(Config.cache_dir + '/probe/word_char_cgru/test/1.pk', 'rb'))
    test_pro_word_rcnn_char_cgru = pickle.load(open(Config.cache_dir + '/probe/word_rcnn_char_cgru/test/1.pk', 'rb')) # best: 0
    test_pro_word_cgru_char_rnn = pickle.load(open(Config.cache_dir + '/probe/word_cgru_char_rnn/test/0.pk', 'rb'))
    test_pro_word_cgru_char_rcnn = pickle.load(open(Config.cache_dir + '/probe/word_cgru_char_rcnn/test/0.pk', 'rb'))
    test_pro_word_rnn_char_cgru = pickle.load(open(Config.cache_dir + '/probe/md/word_rnn_char_cgru/test/1.pk', 'rb'))
    test_pro_word_rnn_char_cnn = pickle.load(open(Config.cache_dir + '/probe/md/word_rnn_char_cnn/test/0.pk', 'rb'))

    test_pro = test_pro_cnn
    test_pro += test_pro_rnn
    test_pro += test_pro_rcnn
    test_pro += test_pro_deep_cnn
    test_pro += test_pro_word_rcnn_char_rnn
    test_pro += test_pro_word_rnn_char_rcnn
    test_pro += test_pro_word_char_cgru
    test_pro += test_pro_word_cgru_char_rcnn
    test_pro += test_pro_word_rcnn_char_cgru
    test_pro += test_pro_word_cgru_char_rnn
    test_pro += test_pro_word_rnn_char_cgru
    test_pro += test_pro_word_rnn_char_cnn

    pre, rec, f = score(test_pro, test_labels)
    print(pre)
    print(rec)
    print(f)
    print(np.mean(f))
Пример #2
0
sys.path.append("..")
import pandas as pd
import numpy as np
import pickle
import keras
import keras.backend as K

from init.config import Config
from my_utils.data_preprocess import to_categorical, word_char_cnn_train_batch_generator
from model.deepzoo import get_word_rnn_char_cgru
from my_utils.metrics import score

print("Load Train && Val")
train = pd.read_csv(Config.train_data_path, sep='\t')
val = pd.read_csv(Config.test_data_path, sep='\t')
val_label = to_categorical(val.label)

load_val = True
batch_size = 128
model_name = "word_rnn_char_cgru"
trainable_layer = ["word_embedding", "char_embedding"]
train_batch_generator = word_char_cnn_train_batch_generator

print("Load Val Data")

val_word_seq = pickle.load(
    open(Config.cache_dir + "/g_val_word_seq_%s.pkl" % Config.word_seq_maxlen,
         "rb"))
val_char_seq = pickle.load(
    open(Config.cache_dir + "/g_val_char_seq_%s.pkl" % Config.char_seq_maxlen,
         "rb"))
Пример #3
0

print("val")
val = pd.read_csv(Config.vali_data_path, sep='\t')
val_ids = val.id.values
val_content = val.content.values
val_word_seq = get_word_seq(val_content)
val_char_seq = get_char_seq(val_content)
val_seq = [val_word_seq, val_char_seq]
print("load ok")

print("test")
test = pd.read_csv(Config.test_data_path, sep='\t')
test_ids = test.id.values
test_labels = test.label.values
test_labels = to_categorical(test_labels)
test_content = test.content.values
test_word_seq = get_word_seq(test_content)
test_char_seq = get_char_seq(test_content)
test_seq = [test_word_seq, test_char_seq]
print("load ok")





def predict_probe(model_name, model_list, type, seq):
    save_path = Config.cache_dir + '/probe/%s_%s_'%(model_name, type)
    for i in range(len(model_list)):
        model_path = model_list[i]
        print(model_path)