lvwerra HF staff commited on
Commit
6130ccf
1 Parent(s): 4318f56

Update Space (evaluate main: e4a27243)

Browse files
Files changed (2) hide show
  1. comet.py +23 -4
  2. requirements.txt +1 -1
comet.py CHANGED
@@ -34,6 +34,9 @@ predictions['scores']
34
  ```
35
  """
36
 
 
 
 
37
  import comet # From: unbabel-comet
38
  import datasets
39
  import torch
@@ -106,15 +109,29 @@ Examples:
106
  """
107
 
108
 
 
 
 
 
 
 
 
 
 
109
  @evaluate.utils.file_utils.add_start_docstrings(_DESCRIPTION, _KWARGS_DESCRIPTION)
110
  class COMET(evaluate.Metric):
111
- def _info(self):
 
 
 
 
112
 
113
  return evaluate.MetricInfo(
114
  description=_DESCRIPTION,
115
  citation=_CITATION,
116
  homepage="https://unbabel.github.io/COMET/html/index.html",
117
  inputs_description=_KWARGS_DESCRIPTION,
 
118
  features=datasets.Features(
119
  {
120
  "sources": datasets.Value("string", id="sequence"),
@@ -136,10 +153,12 @@ class COMET(evaluate.Metric):
136
  else:
137
  self.scorer = comet.load_from_checkpoint(comet.download_model(self.config_name))
138
 
139
- def _compute(self, sources, predictions, references, gpus=None, progress_bar=False):
140
- if gpus is None:
141
  gpus = 1 if torch.cuda.is_available() else 0
 
 
142
  data = {"src": sources, "mt": predictions, "ref": references}
143
  data = [dict(zip(data, t)) for t in zip(*data.values())]
144
- scores, mean_score = self.scorer.predict(data, gpus=gpus, progress_bar=progress_bar)
145
  return {"mean_score": mean_score, "scores": scores}
 
34
  ```
35
  """
36
 
37
+ from dataclasses import dataclass
38
+ from typing import Optional
39
+
40
  import comet # From: unbabel-comet
41
  import datasets
42
  import torch
 
109
  """
110
 
111
 
112
+ @dataclass
113
+ class COMETConfig(evaluate.info.Config):
114
+
115
+ name: str = "default"
116
+
117
+ gpus: Optional[int] = None
118
+ progress_bar: bool = False
119
+
120
+
121
  @evaluate.utils.file_utils.add_start_docstrings(_DESCRIPTION, _KWARGS_DESCRIPTION)
122
  class COMET(evaluate.Metric):
123
+
124
+ CONFIG_CLASS = COMETConfig
125
+ ALLOWED_CONFIG_NAMES = None
126
+
127
+ def _info(self, config):
128
 
129
  return evaluate.MetricInfo(
130
  description=_DESCRIPTION,
131
  citation=_CITATION,
132
  homepage="https://unbabel.github.io/COMET/html/index.html",
133
  inputs_description=_KWARGS_DESCRIPTION,
134
+ config=config,
135
  features=datasets.Features(
136
  {
137
  "sources": datasets.Value("string", id="sequence"),
 
153
  else:
154
  self.scorer = comet.load_from_checkpoint(comet.download_model(self.config_name))
155
 
156
+ def _compute(self, sources, predictions, references):
157
+ if self.config.gpus is None:
158
  gpus = 1 if torch.cuda.is_available() else 0
159
+ else:
160
+ gpus = self.config.gpus
161
  data = {"src": sources, "mt": predictions, "ref": references}
162
  data = [dict(zip(data, t)) for t in zip(*data.values())]
163
+ scores, mean_score = self.scorer.predict(data, gpus=gpus, progress_bar=self.config.progress_bar)
164
  return {"mean_score": mean_score, "scores": scores}
requirements.txt CHANGED
@@ -1,3 +1,3 @@
1
- git+https://github.com/huggingface/evaluate@80448674f5447a9682afe051db243c4a13bfe4ff
2
  unbabel-comet
3
  torch
 
1
+ git+https://github.com/huggingface/evaluate@e4a2724377909fe2aeb4357e3971e5a569673b39
2
  unbabel-comet
3
  torch