maksymdolgikh commited on
Commit
b88fb80
1 Parent(s): c6f936b

beta=1 behaviour fix

Browse files
Files changed (1) hide show
  1. seqeval_with_fbeta.py +9 -15
seqeval_with_fbeta.py CHANGED
@@ -96,8 +96,8 @@ Examples:
96
  >>> seqeval = evaluate.load("seqeval")
97
  >>> results = seqeval.compute(predictions=predictions, references=references, beta=1.0)
98
  >>> print(list(results.keys()))
99
- ['MISC', 'PER', 'overall_precision', 'overall_recall', 'overall_f1', 'overall_accuracy']
100
- >>> print(results["overall_f1"])
101
  0.5
102
  >>> print(results["PER"]["f1"])
103
  1.0
@@ -126,7 +126,7 @@ class Seqeval_With_Beta(evaluate.Metric):
126
  self,
127
  predictions,
128
  references,
129
- beta: float = 1.0,
130
  suffix: bool = False,
131
  scheme: Optional[str] = None,
132
  mode: Optional[str] = None,
@@ -152,13 +152,12 @@ class Seqeval_With_Beta(evaluate.Metric):
152
  report.pop("macro avg")
153
  report.pop("weighted avg")
154
 
155
- if beta != 1.0:
156
- beta2 = beta ** 2
157
- for k, v in report.items():
158
- denom = beta2 * v["precision"] + v["recall"]
159
- if denom == 0:
160
- denom += 1
161
- v[f"f{beta}-score"] = (1 + beta2) * v["precision"] * v["recall"] / denom
162
 
163
  overall_score = report.pop("micro avg")
164
 
@@ -172,11 +171,6 @@ class Seqeval_With_Beta(evaluate.Metric):
172
  }
173
  for type_name, score in report.items()
174
  }
175
- # scores["overall_precision"] = overall_score["precision"]
176
- # scores["overall_recall"] = overall_score["recall"]
177
- # scores["overall_f1"] = overall_score["f1-score"]
178
- # scores[f"overall_f{beta}"] = overall_score[f"f{beta}-score"]
179
- # scores["overall_accuracy"] = accuracy_score(y_true=references, y_pred=predictions)
180
 
181
  scores["overall"] = {
182
  "precision": overall_score["precision"],
 
96
  >>> seqeval = evaluate.load("seqeval")
97
  >>> results = seqeval.compute(predictions=predictions, references=references, beta=1.0)
98
  >>> print(list(results.keys()))
99
+ ['MISC', 'PER', 'overall']
100
+ >>> print(results["overall"]["f1"])
101
  0.5
102
  >>> print(results["PER"]["f1"])
103
  1.0
 
126
  self,
127
  predictions,
128
  references,
129
+ beta: float = 1,
130
  suffix: bool = False,
131
  scheme: Optional[str] = None,
132
  mode: Optional[str] = None,
 
152
  report.pop("macro avg")
153
  report.pop("weighted avg")
154
 
155
+ beta2 = beta ** 2
156
+ for k, v in report.items():
157
+ denom = beta2 * v["precision"] + v["recall"]
158
+ if denom == 0:
159
+ denom += 1
160
+ v[f"f{beta}-score"] = (1 + beta2) * v["precision"] * v["recall"] / denom
 
161
 
162
  overall_score = report.pop("micro avg")
163
 
 
171
  }
172
  for type_name, score in report.items()
173
  }
 
 
 
 
 
174
 
175
  scores["overall"] = {
176
  "precision": overall_score["precision"],