Exemplo n.º 1
0
    def _accuracy(self, ys, ts):
        ys = permutate_list(ys, argsort_list_descent(ys), inv=False)
        ts = permutate_list(ts, argsort_list_descent(ts), inv=False)

        # print("打印预测值")
        # for g in ys:
        #     print(g.data)
        # print("打印标签")
        # for h in ts:
        #     print(h.data)

        correct = 0
        total = 0
        exact = 0
        for _y, _t in zip(ys, ts):
            y = _y.data
            t = _t.data
            _correct = (y == t).sum()
            _total = t.size
            if _correct == _total:
                exact += 1
            correct += _correct
            total += _total
        accuracy = correct / total
        self._eval = {
            'accuracy': accuracy,
            'correct': correct,
            'total': total,
            'exact': exact
        }
        print("correct:%d" % correct)
        print("total:%d" % total)
        print("exact:%d" % exact)
        return accuracy
Exemplo n.º 2
0
 def _accuracy(self, ys, ts):
     ys = permutate_list(ys, argsort_list_descent(ys), inv=False)
     ts = permutate_list(ts, argsort_list_descent(ts), inv=False)
     correct = 0
     total = 0
     exact = 0
     for _y, _t in zip(ys, ts):
         y = _y.data
         t = _t.data
         _correct = (y == t).sum()
         _total = t.size
         if _correct == _total:
             exact += 1
         correct += _correct
         total += _total
     accuracy = correct / total
     self._eval = {'accuracy': accuracy, 'correct': correct, 'total': total, 'exact': exact}
     return accuracy
Exemplo n.º 3
0
 def _accuracy(self, ys, ts):
     ys = permutate_list(ys, argsort_list_descent(ys), inv=False)
     ts = permutate_list(ts, argsort_list_descent(ts), inv=False)
     correct = 0
     total = 0
     exact = 0
     for _y, _t in zip(ys, ts):
         y = _y.data
         t = _t.data
         _correct = (y == t).sum()
         _total = t.size
         if _correct == _total:
             exact += 1
         correct += _correct
         total += _total
     accuracy = correct / total
     self._eval = {'accuracy': accuracy, 'correct': correct, 'total': total, 'exact': exact}
     return accuracy
Exemplo n.º 4
0
 def argmax(self, xs):
     xs = permutate_list(xs, argsort_list_descent(xs), inv=False)
     xs = F.transpose_sequence(xs)
     score, path = super(CRF, self).argmax(xs)
     path = F.transpose_sequence(path)
     return score, path
Exemplo n.º 5
0
 def __call__(self, xs, ys):
     xs = permutate_list(xs, argsort_list_descent(xs), inv=False)
     xs = F.transpose_sequence(xs)
     ys = permutate_list(ys, argsort_list_descent(ys), inv=False)
     ys = F.transpose_sequence(ys)
     return super(CRF, self).__call__(xs, ys)
Exemplo n.º 6
0
 def argmax(self, xs):
     xs = permutate_list(xs, argsort_list_descent(xs), inv=False)
     xs = F.transpose_sequence(xs)
     score, path = super(CRF, self).argmax(xs)
     path = F.transpose_sequence(path)
     return score, path
Exemplo n.º 7
0
 def __call__(self, xs, ys):
     xs = permutate_list(xs, argsort_list_descent(xs), inv=False)
     xs = F.transpose_sequence(xs)
     ys = permutate_list(ys, argsort_list_descent(ys), inv=False)
     ys = F.transpose_sequence(ys)
     return super(CRF, self).__call__(xs, ys)