lvwerra HF staff commited on
Commit
81b9155
1 Parent(s): 06965ee

Update Space (evaluate main: c447fc8e)

Browse files
Files changed (2) hide show
  1. requirements.txt +1 -1
  2. rouge.py +9 -36
requirements.txt CHANGED
@@ -1,4 +1,4 @@
1
- git+https://github.com/huggingface/evaluate@e4a2724377909fe2aeb4357e3971e5a569673b39
2
  absl-py
3
  nltk
4
  rouge_score>=0.1.2
 
1
+ git+https://github.com/huggingface/evaluate@c447fc8eda9c62af501bfdc6988919571050d950
2
  absl-py
3
  nltk
4
  rouge_score>=0.1.2
rouge.py CHANGED
@@ -14,9 +14,6 @@
14
  """ ROUGE metric from Google Research github repo. """
15
 
16
  # The dependencies in https://github.com/google-research/google-research/blob/master/rouge/requirements.txt
17
- from dataclasses import dataclass
18
- from typing import Callable, List, Optional
19
-
20
  import absl # Here to have a nice missing dependency error message early on
21
  import datasets
22
  import nltk # Here to have a nice missing dependency error message early on
@@ -93,29 +90,13 @@ class Tokenizer:
93
  return self.tokenizer_func(text)
94
 
95
 
96
- @dataclass
97
- class RougeConfig(evaluate.info.Config):
98
-
99
- name: str = "default"
100
-
101
- rouge_types: Optional[List[str]] = None
102
- use_aggregator: bool = True
103
- use_stemmer: bool = False
104
- tokenizer: Optional[Callable] = None
105
-
106
-
107
  @evaluate.utils.file_utils.add_start_docstrings(_DESCRIPTION, _KWARGS_DESCRIPTION)
108
  class Rouge(evaluate.Metric):
109
-
110
- CONFIG_CLASS = RougeConfig
111
- ALLOWED_CONFIG_NAMES = ["default"]
112
-
113
- def _info(self, config):
114
  return evaluate.MetricInfo(
115
  description=_DESCRIPTION,
116
  citation=_CITATION,
117
  inputs_description=_KWARGS_DESCRIPTION,
118
- config=config,
119
  features=[
120
  datasets.Features(
121
  {
@@ -138,26 +119,18 @@ class Rouge(evaluate.Metric):
138
  )
139
 
140
  def _compute(
141
- self,
142
- predictions,
143
- references,
144
  ):
145
- if self.config.rouge_types is None:
146
  rouge_types = ["rouge1", "rouge2", "rougeL", "rougeLsum"]
147
- else:
148
- rouge_types = self.config.rouge_types
149
 
150
  multi_ref = isinstance(references[0], list)
151
 
152
- if self.config.tokenizer is not None:
153
- tokenizer = Tokenizer(self.config.tokenizer)
154
- else:
155
- tokenizer = self.config.tokenizer
156
 
157
- scorer = rouge_scorer.RougeScorer(
158
- rouge_types=rouge_types, use_stemmer=self.config.use_stemmer, tokenizer=tokenizer
159
- )
160
- if self.config.use_aggregator:
161
  aggregator = scoring.BootstrapAggregator()
162
  else:
163
  scores = []
@@ -167,12 +140,12 @@ class Rouge(evaluate.Metric):
167
  score = scorer.score_multi(ref, pred)
168
  else:
169
  score = scorer.score(ref, pred)
170
- if self.config.use_aggregator:
171
  aggregator.add_scores(score)
172
  else:
173
  scores.append(score)
174
 
175
- if self.config.use_aggregator:
176
  result = aggregator.aggregate()
177
  for key in result:
178
  result[key] = result[key].mid.fmeasure
 
14
  """ ROUGE metric from Google Research github repo. """
15
 
16
  # The dependencies in https://github.com/google-research/google-research/blob/master/rouge/requirements.txt
 
 
 
17
  import absl # Here to have a nice missing dependency error message early on
18
  import datasets
19
  import nltk # Here to have a nice missing dependency error message early on
 
90
  return self.tokenizer_func(text)
91
 
92
 
 
 
 
 
 
 
 
 
 
 
 
93
  @evaluate.utils.file_utils.add_start_docstrings(_DESCRIPTION, _KWARGS_DESCRIPTION)
94
  class Rouge(evaluate.Metric):
95
+ def _info(self):
 
 
 
 
96
  return evaluate.MetricInfo(
97
  description=_DESCRIPTION,
98
  citation=_CITATION,
99
  inputs_description=_KWARGS_DESCRIPTION,
 
100
  features=[
101
  datasets.Features(
102
  {
 
119
  )
120
 
121
  def _compute(
122
+ self, predictions, references, rouge_types=None, use_aggregator=True, use_stemmer=False, tokenizer=None
 
 
123
  ):
124
+ if rouge_types is None:
125
  rouge_types = ["rouge1", "rouge2", "rougeL", "rougeLsum"]
 
 
126
 
127
  multi_ref = isinstance(references[0], list)
128
 
129
+ if tokenizer is not None:
130
+ tokenizer = Tokenizer(tokenizer)
 
 
131
 
132
+ scorer = rouge_scorer.RougeScorer(rouge_types=rouge_types, use_stemmer=use_stemmer, tokenizer=tokenizer)
133
+ if use_aggregator:
 
 
134
  aggregator = scoring.BootstrapAggregator()
135
  else:
136
  scores = []
 
140
  score = scorer.score_multi(ref, pred)
141
  else:
142
  score = scorer.score(ref, pred)
143
+ if use_aggregator:
144
  aggregator.add_scores(score)
145
  else:
146
  scores.append(score)
147
 
148
+ if use_aggregator:
149
  result = aggregator.aggregate()
150
  for key in result:
151
  result[key] = result[key].mid.fmeasure