Martin Dočekal commited on
Commit
8f4e42e
·
1 Parent(s): aeb0f96

select option

Browse files
Files changed (1) hide show
  1. rouge_raw.py +9 -3
rouge_raw.py CHANGED
@@ -37,7 +37,7 @@ Module for raw ROUGE score calculation from:
37
  """
38
 
39
  import re
40
- from typing import Sequence
41
 
42
  import datasets
43
  import evaluate
@@ -175,6 +175,8 @@ ROCUE RAW metric for list of predictions and references.
175
  Args:
176
  predictions: list of predictions to evaluate. Each prediction should be a string with tokens separated by spaces.
177
  references: list of reference for each prediction. Each reference should be a string with tokens separated by spaces.
 
 
178
  Returns:
179
  rougeraw1_precision
180
  rougeraw1_recall
@@ -215,9 +217,9 @@ class RougeRaw(evaluate.Metric):
215
  ],
216
  )
217
 
218
- def _compute(self, predictions: Sequence[str], references: Sequence[str]):
219
  res = RougeRawOriginal().corpus(references, predictions)
220
- return {
221
  "rougeraw1_precision": res["1"].p,
222
  "rougeraw1_recall": res["1"].r,
223
  "rougeraw1_fmeasure": res["1"].f,
@@ -229,3 +231,7 @@ class RougeRaw(evaluate.Metric):
229
  "rougerawl_fmeasure": res["L"].f,
230
  }
231
 
 
 
 
 
 
37
  """
38
 
39
  import re
40
+ from typing import Sequence, Optional
41
 
42
  import datasets
43
  import evaluate
 
175
  Args:
176
  predictions: list of predictions to evaluate. Each prediction should be a string with tokens separated by spaces.
177
  references: list of reference for each prediction. Each reference should be a string with tokens separated by spaces.
178
+ select: (Optional) string. The name of the metric to return. One of: 'rougeraw1_precision', 'rougeraw1_recall', 'rougeraw1_fmeasure', 'rougeraw2_precision', 'rougeraw2_recall', 'rougeraw2_fmeasure', 'rougerawl_precision', 'rougerawl_recall', 'rougerawl_fmeasure'.
179
+ If None, all metrics are returned as a dictionary.
180
  Returns:
181
  rougeraw1_precision
182
  rougeraw1_recall
 
217
  ],
218
  )
219
 
220
+ def _compute(self, predictions: Sequence[str], references: Sequence[str], select: Optional[str] = None):
221
  res = RougeRawOriginal().corpus(references, predictions)
222
+ res = {
223
  "rougeraw1_precision": res["1"].p,
224
  "rougeraw1_recall": res["1"].r,
225
  "rougeraw1_fmeasure": res["1"].f,
 
231
  "rougerawl_fmeasure": res["L"].f,
232
  }
233
 
234
+ if select is not None:
235
+ return res[select]
236
+ return res
237
+