John Graham Reynolds commited on
Commit
dbc5be0
1 Parent(s): 217c111

update conditional

Browse files
Files changed (1) hide show
  1. app.py +20 -10
app.py CHANGED
@@ -15,26 +15,36 @@ Check out the original, longstanding issue [here](https://github.com/huggingface
15
  evaluation. I encountered this issue specifically while training [RoBERTa-base-DReiFT](https://huggingface.co/MarioBarbeque/RoBERTa-base-DReiFT) for multilabel \
16
  text classification of 805 labeled medical conditions based on drug reviews. \n
17
 
18
- This Space shows how one can instantiate these custom metrics each with their own unique methodology for averaging across labels, combine them into a single
19
- HF `evaluate.EvaluationModule` (or `Metric`), and compute them.</p>
20
  """
21
 
22
- article = "<p style='text-align: center'>Check out the [original repo](https://github.com/johngrahamreynolds/FixedMetricsForHF) housing this code, and a quickly \
23
- trained [multilabel text classification model](https://github.com/johngrahamreynolds/RoBERTa-base-DReiFT/tree/main) that makes use of it during evaluation.</p>"
24
 
25
- def evaluation(predictions, metrics) -> str:
26
 
27
- f1 = FixedF1(average=metrics.loc[metrics["Metric"] == "f1"]["Averaging Type"][0])
28
- precision = FixedPrecision(average=metrics.loc[metrics["Metric"] == "precision"]["Averaging Type"][0])
29
- recall = FixedRecall(average=metrics.loc[metrics["Metric"] == "recall"]["Averaging Type"][0])
30
- combined = evaluate.combine([f1, recall, precision])
 
 
 
 
 
 
 
 
 
 
31
 
32
  df = predictions.get_dataframe()
33
  predicted = df["Predicted Label"].to_list()
34
  references = df["Actual Label"].to_list()
35
 
36
  combined.add_batch(prediction=predicted, reference=references)
37
- outputs = combined.compute()
38
 
39
  return "Your metrics are as follows: \n" + outputs
40
 
 
15
  evaluation. I encountered this issue specifically while training [RoBERTa-base-DReiFT](https://huggingface.co/MarioBarbeque/RoBERTa-base-DReiFT) for multilabel \
16
  text classification of 805 labeled medical conditions based on drug reviews. \n
17
 
18
+ This Space shows how one can instantiate these custom `evaluate.Metric`s, each with their own unique methodology for averaging across labels, before `combine`-ing them into a
19
+ HF `evaluate.CombinedEvaluations` object. From here, we can easily compute each of the metrics simultaneously using `compute`.</p>
20
  """
21
 
22
+ article = """<p style='text-align: center'>Check out the [original repo](https://github.com/johngrahamreynolds/FixedMetricsForHF) housing this code, and a quickly \
23
+ trained [multilabel text classification model](https://github.com/johngrahamreynolds/RoBERTa-base-DReiFT/tree/main) that makes use of it during evaluation.</p>"""
24
 
25
+ def evaluation(predictions, metrics) -> str:
26
 
27
+ metric_set = set(metrics["Metric"].to_list())
28
+ combined_list = []
29
+
30
+ if "f1" in metric_set:
31
+ f1 = FixedF1(average=metrics.loc[metrics["Metric"] == "f1"]["Averaging Type"][0])
32
+ combined_list.append(f1)
33
+ if "precision" in metric_set:
34
+ precision = FixedPrecision(average=metrics.loc[metrics["Metric"] == "precision"]["Averaging Type"][0])
35
+ combined_list.append(precision)
36
+ if "recall" in metric_set:
37
+ recall = FixedRecall(average=metrics.loc[metrics["Metric"] == "recall"]["Averaging Type"][0])
38
+ combined_list.append(recall)
39
+
40
+ combined = evaluate.combine(combined_list)
41
 
42
  df = predictions.get_dataframe()
43
  predicted = df["Predicted Label"].to_list()
44
  references = df["Actual Label"].to_list()
45
 
46
  combined.add_batch(prediction=predicted, reference=references)
47
+ outputs = combined.compute()
48
 
49
  return "Your metrics are as follows: \n" + outputs
50