Exemplo n.º 1
0
def main(_):
    for i in [0]:
        for j in [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]:
            # for j in [1, 2, 3, 4, 5]:
            # for j in [6, 7, 8, 9, 10]:
            print('hhhe_ebdt{}_index{}.txt'.format(i, j))
            #sys.stdout = open('ebdt'+str(i)+'_index'+str(j)+'.txt', 'w')
            # for each label
            y_true = []
            y_pred_p = []
            y_pred = []
            sum_time_cost = 0.

            for k in range(9):
                print('hhhe_ebdt{}_index{}_label{}.txt'.format(i, j, k))

                g = tf.Graph()
                with g.as_default():

                    obj = Bi_LSTM_Att_BC_model(
                        test_index=j,
                        embedding_type=i,
                        label_index=k,
                        scope='hhhe_ebdt{}_index{}_label{}.txt'.format(
                            i, j, k))
                    time_cost, cur_y_true, best_y_pred_p = obj.run()

                sum_time_cost += time_cost

                # print "cur_y_true[0] : "
                print cur_y_true[0]
                # print "best_y_pred_p[9] : "
                print best_y_pred_p[0]

                cur_y_true = np.argmax(cur_y_true, axis=1).reshape(-1, 1)
                best_y_pred = np.argmax(best_y_pred_p, axis=1).reshape(-1, 1)

                best_y_pred_p = best_y_pred_p[:, 1].reshape(-1, 1)

                if k == 0:
                    y_true = cur_y_true
                    y_pred = best_y_pred
                    y_pred_p = best_y_pred_p
                else:
                    y_true = np.concatenate((y_true, cur_y_true), axis=1)
                    y_pred = np.concatenate((y_pred, best_y_pred), axis=1)
                    y_pred_p = np.concatenate((y_pred_p, best_y_pred_p),
                                              axis=1)

            Emotion_eval(y_true, y_pred, y_pred_p)
            Emo_eval(y_true, y_pred)
            print y_true[0]
            print y_pred[0]
            print y_pred_p[0]

            # np.savetxt('For_calibrated_B'+str(j)+'_share2.txt', y_pred, fmt="%d", delimiter=",")

            print "Finish the {}th experiment!".format(j)
            print "sum of the time cost for each binary classifier: {}".format(
                sum_time_cost)
Exemplo n.º 2
0
 def new_test():
     feed_dict = {
         self.x: ev_x,
         self.doc_len: ev_doc_len,
         self.keep_prob: 1.0,
     }
     y_true = ev_y
     y_pred_p = sess.run(prob, feed_dict=feed_dict)
     y_pred = calibrated_label_ranking(y_pred_p, For_calibrated_B)
     Emotion_eval(y_true, y_pred, y_pred_p)
Exemplo n.º 3
0
 def new_test():
     feed_dict = {
         self.x: te_x,
         self.doc_len: te_doc_len,
         self.keep_prob: 1.0,
     }
     y_true = te_y
     y_pred_p = sess.run(prob, feed_dict=feed_dict)
     # y_pred = calibrated_label_ranking(y_pred_p, For_calibrated_B)
     y_pred = np.ceil(y_pred_p - 1.0 / 9)
     Emotion_eval(y_true, y_pred, y_pred_p)
Exemplo n.º 4
0
 def new_test():
     feed_dict = {
         self.x: te_x,
         self.doc_len: te_doc_len,
         self.keep_prob: 1.0,
     }
     y_true = np.ceil(te_y)
     y_pred_p = sess.run(prob, feed_dict=feed_dict)
     #修改 : 采用calibrated label ranking 算法
     # y_pred = np.ceil(y_pred_p-1.0/8)
     y_pred  = calibrated_label_ranking(y_pred_p)
     Emotion_eval(y_true, y_pred, y_pred_p)
Exemplo n.º 5
0
            def new_test():
                feed_dict = {
                    self.x: te_x,
                    self.doc_len: te_doc_len,
                    self.keep_prob: 1.0,
                }
                y_true = te_y[:, 1 : : 2]

                y_pred_p = sess.run(prob, feed_dict=feed_dict)[:, 1 : : 2]

                y_pred = np.ceil(y_pred_p-1.0/2)

                ''' test '''

                # print('y_true[0] : {}'.format(y_true[0]))
                # print('y_pred_p[0] : {}'.format(y_pred_p[0]))
                # print('y_pred[0] : {}'.format(y_pred[0]))

                Emotion_eval(y_true, y_pred, y_pred_p)