wadood commited on
Commit
5e1b642
1 Parent(s): 8f56f21

added weighted token level metric

Browse files
Files changed (1) hide show
  1. evaluation_metrics.py +21 -0
evaluation_metrics.py CHANGED
@@ -83,9 +83,30 @@ class TokenMacroMetric(EvaluationMetric):
83
  )
84
 
85
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
  EVALUATION_METRICS = [
87
  PartialSpanOverlapMetric(),
88
  ExactSpanOverlapMetric(),
89
  TokenMicroMetric(),
90
  TokenMacroMetric(),
 
91
  ]
 
83
  )
84
 
85
 
86
+ class TokenWeightedMetric(EvaluationMetric):
87
+ def __init__(self) -> None:
88
+ super().__init__()
89
+
90
+ self.name = "Token Based Evaluation with Weighted Average"
91
+ self.description = ""
92
+
93
+ @staticmethod
94
+ def get_evaluation_metric(gt_ner_span, pred_ner_span, text, tags) -> float:
95
+ return round(
96
+ classification_report(
97
+ get_token_output_labels(gt_ner_span, text),
98
+ get_token_output_labels(pred_ner_span, text),
99
+ labels=tags,
100
+ output_dict=True,
101
+ )["weighted avg"]["f1-score"],
102
+ 2,
103
+ )
104
+
105
+
106
  EVALUATION_METRICS = [
107
  PartialSpanOverlapMetric(),
108
  ExactSpanOverlapMetric(),
109
  TokenMicroMetric(),
110
  TokenMacroMetric(),
111
+ TokenWeightedMetric(),
112
  ]