Spaces:
Sleeping
Sleeping
DarrenChensformer
commited on
Commit
•
d5d2df0
1
Parent(s):
0a5ef0f
Allow for the inclusion of empty labels in calculations
Browse files- eval_keyphrase.py +7 -4
eval_keyphrase.py
CHANGED
@@ -102,15 +102,18 @@ class eval_keyphrase(evaluate.Metric):
|
|
102 |
|
103 |
return white_space_fix(remove_punc(lower(kp)))
|
104 |
|
105 |
-
def _compute(self, predictions, references):
|
106 |
"""Returns the scores"""
|
107 |
|
108 |
macro_metrics = {'precision': [], 'recall': [], 'f1': [], 'num_pred': [], 'num_gold': []}
|
109 |
|
110 |
for targets, preds in zip(references, predictions):
|
111 |
-
|
112 |
-
|
113 |
-
|
|
|
|
|
|
|
114 |
total_tgt_set = set(targets)
|
115 |
total_preds = set(preds)
|
116 |
if len(total_tgt_set) == 0: continue
|
|
|
102 |
|
103 |
return white_space_fix(remove_punc(lower(kp)))
|
104 |
|
105 |
+
def _compute(self, predictions, references, ignore_empty_label=True):
|
106 |
"""Returns the scores"""
|
107 |
|
108 |
macro_metrics = {'precision': [], 'recall': [], 'f1': [], 'num_pred': [], 'num_gold': []}
|
109 |
|
110 |
for targets, preds in zip(references, predictions):
|
111 |
+
if ignore_empty_label:
|
112 |
+
targets = [self._normalize_keyphrase(tmp_key).strip() for tmp_key in targets if len(self._normalize_keyphrase(tmp_key).strip()) != 0]
|
113 |
+
preds = [self._normalize_keyphrase(tmp_key).strip() for tmp_key in preds if len(self._normalize_keyphrase(tmp_key).strip()) != 0]
|
114 |
+
else:
|
115 |
+
targets = [self._normalize_keyphrase(tmp_key).strip() for tmp_key in targets]
|
116 |
+
preds = [self._normalize_keyphrase(tmp_key).strip() for tmp_key in preds]
|
117 |
total_tgt_set = set(targets)
|
118 |
total_preds = set(preds)
|
119 |
if len(total_tgt_set) == 0: continue
|