lvwerra HF staff commited on
Commit
8d67ab5
1 Parent(s): 6cc71a7

Update Space (evaluate main: e4a27243)

Browse files
Files changed (2) hide show
  1. requirements.txt +1 -1
  2. seqeval.py +30 -13
requirements.txt CHANGED
@@ -1,2 +1,2 @@
1
- git+https://github.com/huggingface/evaluate@80448674f5447a9682afe051db243c4a13bfe4ff
2
  seqeval
 
1
+ git+https://github.com/huggingface/evaluate@e4a2724377909fe2aeb4357e3971e5a569673b39
2
  seqeval
seqeval.py CHANGED
@@ -14,6 +14,7 @@
14
  """ seqeval metric. """
15
 
16
  import importlib
 
17
  from typing import List, Optional, Union
18
 
19
  import datasets
@@ -99,14 +100,31 @@ Examples:
99
  """
100
 
101
 
 
 
 
 
 
 
 
 
 
 
 
 
102
  @evaluate.utils.file_utils.add_start_docstrings(_DESCRIPTION, _KWARGS_DESCRIPTION)
103
  class Seqeval(evaluate.Metric):
104
- def _info(self):
 
 
 
 
105
  return evaluate.MetricInfo(
106
  description=_DESCRIPTION,
107
  citation=_CITATION,
108
  homepage="https://github.com/chakki-works/seqeval",
109
  inputs_description=_KWARGS_DESCRIPTION,
 
110
  features=datasets.Features(
111
  {
112
  "predictions": datasets.Sequence(datasets.Value("string", id="label"), id="sequence"),
@@ -121,27 +139,26 @@ class Seqeval(evaluate.Metric):
121
  self,
122
  predictions,
123
  references,
124
- suffix: bool = False,
125
- scheme: Optional[str] = None,
126
- mode: Optional[str] = None,
127
- sample_weight: Optional[List[int]] = None,
128
- zero_division: Union[str, int] = "warn",
129
  ):
130
- if scheme is not None:
131
  try:
132
  scheme_module = importlib.import_module("seqeval.scheme")
133
- scheme = getattr(scheme_module, scheme)
134
  except AttributeError:
135
- raise ValueError(f"Scheme should be one of [IOB1, IOB2, IOE1, IOE2, IOBES, BILOU], got {scheme}")
 
 
 
 
136
  report = classification_report(
137
  y_true=references,
138
  y_pred=predictions,
139
- suffix=suffix,
140
  output_dict=True,
141
  scheme=scheme,
142
- mode=mode,
143
- sample_weight=sample_weight,
144
- zero_division=zero_division,
145
  )
146
  report.pop("macro avg")
147
  report.pop("weighted avg")
 
14
  """ seqeval metric. """
15
 
16
  import importlib
17
+ from dataclasses import dataclass
18
  from typing import List, Optional, Union
19
 
20
  import datasets
 
100
  """
101
 
102
 
103
+ @dataclass
104
+ class SeqevalConfig(evaluate.info.Config):
105
+
106
+ name: str = "default"
107
+
108
+ suffix: bool = False
109
+ scheme: Optional[str] = None
110
+ mode: Optional[str] = None
111
+ sample_weight: Optional[List[int]] = None
112
+ zero_division: Union[str, int] = "warn"
113
+
114
+
115
  @evaluate.utils.file_utils.add_start_docstrings(_DESCRIPTION, _KWARGS_DESCRIPTION)
116
  class Seqeval(evaluate.Metric):
117
+
118
+ CONFIG_CLASS = SeqevalConfig
119
+ ALLOWED_CONFIG_NAMES = ["default"]
120
+
121
+ def _info(self, config):
122
  return evaluate.MetricInfo(
123
  description=_DESCRIPTION,
124
  citation=_CITATION,
125
  homepage="https://github.com/chakki-works/seqeval",
126
  inputs_description=_KWARGS_DESCRIPTION,
127
+ config=config,
128
  features=datasets.Features(
129
  {
130
  "predictions": datasets.Sequence(datasets.Value("string", id="label"), id="sequence"),
 
139
  self,
140
  predictions,
141
  references,
 
 
 
 
 
142
  ):
143
+ if self.config.scheme is not None:
144
  try:
145
  scheme_module = importlib.import_module("seqeval.scheme")
146
+ scheme = getattr(scheme_module, self.config.scheme)
147
  except AttributeError:
148
+ raise ValueError(
149
+ f"Scheme should be one of [IOB1, IOB2, IOE1, IOE2, IOBES, BILOU], got {self.config.scheme}"
150
+ )
151
+ else:
152
+ scheme = self.config.scheme
153
  report = classification_report(
154
  y_true=references,
155
  y_pred=predictions,
156
+ suffix=self.config.suffix,
157
  output_dict=True,
158
  scheme=scheme,
159
+ mode=self.config.mode,
160
+ sample_weight=self.config.sample_weight,
161
+ zero_division=self.config.zero_division,
162
  )
163
  report.pop("macro avg")
164
  report.pop("weighted avg")