MCPcopy Create free account
hub / github.com/baidu/DDParser / Metric

Class Metric

ddparser/parser/data_struct/metric.py:28–78  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

26
27
28class Metric(object):
29 def __init__(self, eps=1e-8):
30 super(Metric, self).__init__()
31
32 self.eps = eps
33 self.total = 0.0
34 self.correct_arcs = 0.0
35 self.correct_rels = 0.0
36
37 def __repr__(self):
38 """repr"""
39 return "UAS: {:6.2%} LAS: {:6.2%}".format(self.uas, self.las)
40
41 def __call__(self, arc_preds, rel_preds, arc_golds, rel_golds, mask):
42 """call"""
43 arc_mask = nn.masked_select(arc_preds == arc_golds, mask)
44 rel_mask = layers.logical_and(nn.masked_select(rel_preds == rel_golds, mask), arc_mask)
45 self.total += len(arc_mask)
46 self.correct_arcs += np.sum(arc_mask.numpy()).item()
47 self.correct_rels += np.sum(rel_mask.numpy()).item()
48
49 @property
50 def score(self):
51 """score"""
52 return self.las
53
54 @property
55 def uas(self):
56 """uas"""
57 return self.correct_arcs / (self.total + self.eps)
58
59 @property
60 def las(self):
61 """las"""
62 return self.correct_rels / (self.total + self.eps)
63
64 def __lt__(self, other):
65 """lt"""
66 return self.score < other
67
68 def __le__(self, other):
69 """le"""
70 return self.score <= other
71
72 def __ge__(self, other):
73 """ge"""
74 return self.score >= other
75
76 def __gt__(self, other):
77 """gt"""
78 return self.score > other

Callers 2

trainFunction · 0.90
epoch_evaluateFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected