Esempio n. 1
0
    def add_get_scores(self, truths, preds, save=False):

        preds = [label_path(self.id2type[x]) for x in preds]

        def vec2type(v):
            s = []
            for i in range(len(v)):
                if v[i]:
                    s.extend(label_path(self.id2type[i]))
            return set(s)

        # words_all = list(zip(*truths))[0] #Added
        truth_label = list(zip(*truths))[-1]
        labels_test = [vec2type(x) for x in truth_label]  # ADDed
        # labels_words = [vec2type(x) for x in words_all] # ADDed

        acc = strict(labels_test, preds)
        _, _, macro = loose_macro(labels_test, preds)
        _, _, micro = loose_micro(labels_test, preds)

        if save:
            outfile = open(
                os.path.join(config.OUTPUT_DIR,
                             self.__str__() + ".tsv"), "w")
            for x, y in zip(preds, labels_test):
                t1 = "|".join(list(x))
                t2 = "|".join(list(y))
                outfile.write(t1 + "\t" + t2 + "\n")
            outfile.close()

        return acc, macro, micro
Esempio n. 2
0
    def get_scores(self, preds, save=False):
        preds = [label_path(self.id2type[x]) for x in preds]

        def vec2type(v):
            s = []
            for i in range(len(v)):
                if v[i]:
                    s.extend(label_path(self.id2type[i]))
            return set(s)

        labels_test = [vec2type(x) for x in self.labels_test]
        if save:
            labels_test = [vec2type(x) for x in self.labels]
        acc = strict(labels_test, preds)
        _, _, macro = loose_macro(labels_test, preds)
        _, _, micro = loose_micro(labels_test, preds)

        if save:
            outfile = open(
                os.path.join(config.OUTPUT_DIR,
                             self.__str__() + ".tsv"), "w")
            for x, y in zip(preds, labels_test):
                t1 = "|".join(list(x))
                t2 = "|".join(list(y))
                outfile.write(t1 + "\t" + t2 + "\n")
            outfile.close()

        return acc, macro, micro
Esempio n. 3
0
    def get_scores(self, preds, target='fullset'):
        preds = [label_path(self.id2type[x]) for x in preds]

        #print(self.test_set[0])
        def vec2type(v):
            s = []
            for i in range(len(v)):
                if v[i]:
                    s.extend(label_path(self.id2type[i]))
            return set(s)

        print('eval on ', target)
        if target == 'fullset':
            labels_test = [
                vec2type(x) for x in self.labels
            ]  # path will caculate the father node for strict acc
        else:
            labels_test = [vec2type(x) for x in self.labels_valid]
        words = [self.embedding.i2w(k[0]) for k in self.full_test_set]
        mentions = [self.embedding.i2w(k[2]) for k in self.full_test_set]
        acc = strict(labels_test,
                     preds,
                     oridata=(words, mentions),
                     modelname=self.savename)
        _, _, macro = loose_macro(labels_test, preds)
        _, _, micro = loose_micro(labels_test, preds)
        return acc, macro, micro
Esempio n. 4
0
 def vec2type(v):
     s = []
     for i in range(len(v)):
         if v[i]:
             s.extend(label_path(self.id2type[i]))
     return set(s)