lvwerra HF staff commited on
Commit
b6b5d94
1 Parent(s): 821f592

Update Space (evaluate main: c447fc8e)

Browse files
Files changed (2) hide show
  1. google_bleu.py +11 -28
  2. requirements.txt +1 -1
google_bleu.py CHANGED
@@ -13,8 +13,7 @@
13
  # limitations under the License.
14
  """ Google BLEU (aka GLEU) metric. """
15
 
16
- from dataclasses import dataclass
17
- from typing import Callable, Dict, List, Optional
18
 
19
  import datasets
20
  from nltk.translate import gleu_score
@@ -125,28 +124,13 @@ Examples:
125
  """
126
 
127
 
128
- @dataclass
129
- class GoogleBleuConfig(evaluate.info.Config):
130
-
131
- name: str = "default"
132
-
133
- tokenizer: Optional[Callable] = None
134
- min_len: int = 1
135
- max_len: int = 4
136
-
137
-
138
  @evaluate.utils.file_utils.add_start_docstrings(_DESCRIPTION, _KWARGS_DESCRIPTION)
139
  class GoogleBleu(evaluate.Metric):
140
-
141
- CONFIG_CLASS = GoogleBleuConfig
142
- ALLOWED_CONFIG_NAMES = ["default"]
143
-
144
- def _info(self, config) -> MetricInfo:
145
  return evaluate.MetricInfo(
146
  description=_DESCRIPTION,
147
  citation=_CITATION,
148
  inputs_description=_KWARGS_DESCRIPTION,
149
- config=config,
150
  features=[
151
  datasets.Features(
152
  {
@@ -163,12 +147,14 @@ class GoogleBleu(evaluate.Metric):
163
  ],
164
  )
165
 
166
- def _compute(self, predictions, references):
167
-
168
- if self.config.tokenizer is None:
169
- tokenizer = Tokenizer13a()
170
- else:
171
- tokenizer = self.config.tokenizer
 
 
172
  # if only one reference is provided make sure we still use list of lists
173
  if isinstance(references[0], str):
174
  references = [[ref] for ref in references]
@@ -177,9 +163,6 @@ class GoogleBleu(evaluate.Metric):
177
  predictions = [tokenizer(p) for p in predictions]
178
  return {
179
  "google_bleu": gleu_score.corpus_gleu(
180
- list_of_references=references,
181
- hypotheses=predictions,
182
- min_len=self.config.min_len,
183
- max_len=self.config.max_len,
184
  )
185
  }
 
13
  # limitations under the License.
14
  """ Google BLEU (aka GLEU) metric. """
15
 
16
+ from typing import Dict, List
 
17
 
18
  import datasets
19
  from nltk.translate import gleu_score
 
124
  """
125
 
126
 
 
 
 
 
 
 
 
 
 
 
127
  @evaluate.utils.file_utils.add_start_docstrings(_DESCRIPTION, _KWARGS_DESCRIPTION)
128
  class GoogleBleu(evaluate.Metric):
129
+ def _info(self) -> MetricInfo:
 
 
 
 
130
  return evaluate.MetricInfo(
131
  description=_DESCRIPTION,
132
  citation=_CITATION,
133
  inputs_description=_KWARGS_DESCRIPTION,
 
134
  features=[
135
  datasets.Features(
136
  {
 
147
  ],
148
  )
149
 
150
+ def _compute(
151
+ self,
152
+ predictions: List[str],
153
+ references: List[List[str]],
154
+ tokenizer=Tokenizer13a(),
155
+ min_len: int = 1,
156
+ max_len: int = 4,
157
+ ) -> Dict[str, float]:
158
  # if only one reference is provided make sure we still use list of lists
159
  if isinstance(references[0], str):
160
  references = [[ref] for ref in references]
 
163
  predictions = [tokenizer(p) for p in predictions]
164
  return {
165
  "google_bleu": gleu_score.corpus_gleu(
166
+ list_of_references=references, hypotheses=predictions, min_len=min_len, max_len=max_len
 
 
 
167
  )
168
  }
requirements.txt CHANGED
@@ -1,2 +1,2 @@
1
- git+https://github.com/huggingface/evaluate@e4a2724377909fe2aeb4357e3971e5a569673b39
2
  nltk
 
1
+ git+https://github.com/huggingface/evaluate@c447fc8eda9c62af501bfdc6988919571050d950
2
  nltk