lvwerra HF staff commited on
Commit
8fae68a
1 Parent(s): 30cab14

Update Space (evaluate main: c447fc8e)

Browse files
Files changed (2) hide show
  1. exact_match.py +11 -25
  2. requirements.txt +1 -1
exact_match.py CHANGED
@@ -14,8 +14,6 @@
14
  """Exact Match metric."""
15
  import re
16
  import string
17
- from dataclasses import dataclass
18
- from typing import Optional
19
 
20
  import datasets
21
  import numpy as np
@@ -85,29 +83,13 @@ _CITATION = """
85
  """
86
 
87
 
88
- @dataclass
89
- class ExactMatchConfig(evaluate.info.Config):
90
-
91
- name: str = "default"
92
-
93
- regexes_to_ignore: Optional[str] = None
94
- ignore_case: bool = False
95
- ignore_punctuation: bool = False
96
- ignore_numbers: bool = False
97
-
98
-
99
  @evaluate.utils.file_utils.add_start_docstrings(_DESCRIPTION, _KWARGS_DESCRIPTION)
100
- class ExactMatchConfig(evaluate.Metric):
101
-
102
- CONFIG_CLASS = ExactMatchConfig
103
- ALLOWED_CONFIG_NAMES = ["default"]
104
-
105
- def _info(self, config):
106
  return evaluate.MetricInfo(
107
  description=_DESCRIPTION,
108
  citation=_CITATION,
109
  inputs_description=_KWARGS_DESCRIPTION,
110
- config=config,
111
  features=datasets.Features(
112
  {
113
  "predictions": datasets.Value("string", id="sequence"),
@@ -121,26 +103,30 @@ class ExactMatchConfig(evaluate.Metric):
121
  self,
122
  predictions,
123
  references,
 
 
 
 
124
  ):
125
 
126
- if self.config.regexes_to_ignore is not None:
127
- for s in self.config.regexes_to_ignore:
128
  predictions = np.array([re.sub(s, "", x) for x in predictions])
129
  references = np.array([re.sub(s, "", x) for x in references])
130
  else:
131
  predictions = np.asarray(predictions)
132
  references = np.asarray(references)
133
 
134
- if self.config.ignore_case:
135
  predictions = np.char.lower(predictions)
136
  references = np.char.lower(references)
137
 
138
- if self.config.ignore_punctuation:
139
  repl_table = string.punctuation.maketrans("", "", string.punctuation)
140
  predictions = np.char.translate(predictions, table=repl_table)
141
  references = np.char.translate(references, table=repl_table)
142
 
143
- if self.config.ignore_numbers:
144
  repl_table = string.digits.maketrans("", "", string.digits)
145
  predictions = np.char.translate(predictions, table=repl_table)
146
  references = np.char.translate(references, table=repl_table)
14
  """Exact Match metric."""
15
  import re
16
  import string
 
 
17
 
18
  import datasets
19
  import numpy as np
83
  """
84
 
85
 
 
 
 
 
 
 
 
 
 
 
 
86
  @evaluate.utils.file_utils.add_start_docstrings(_DESCRIPTION, _KWARGS_DESCRIPTION)
87
+ class ExactMatch(evaluate.Metric):
88
+ def _info(self):
 
 
 
 
89
  return evaluate.MetricInfo(
90
  description=_DESCRIPTION,
91
  citation=_CITATION,
92
  inputs_description=_KWARGS_DESCRIPTION,
 
93
  features=datasets.Features(
94
  {
95
  "predictions": datasets.Value("string", id="sequence"),
103
  self,
104
  predictions,
105
  references,
106
+ regexes_to_ignore=None,
107
+ ignore_case=False,
108
+ ignore_punctuation=False,
109
+ ignore_numbers=False,
110
  ):
111
 
112
+ if regexes_to_ignore is not None:
113
+ for s in regexes_to_ignore:
114
  predictions = np.array([re.sub(s, "", x) for x in predictions])
115
  references = np.array([re.sub(s, "", x) for x in references])
116
  else:
117
  predictions = np.asarray(predictions)
118
  references = np.asarray(references)
119
 
120
+ if ignore_case:
121
  predictions = np.char.lower(predictions)
122
  references = np.char.lower(references)
123
 
124
+ if ignore_punctuation:
125
  repl_table = string.punctuation.maketrans("", "", string.punctuation)
126
  predictions = np.char.translate(predictions, table=repl_table)
127
  references = np.char.translate(references, table=repl_table)
128
 
129
+ if ignore_numbers:
130
  repl_table = string.digits.maketrans("", "", string.digits)
131
  predictions = np.char.translate(predictions, table=repl_table)
132
  references = np.char.translate(references, table=repl_table)
requirements.txt CHANGED
@@ -1 +1 @@
1
- git+https://github.com/huggingface/evaluate@e4a2724377909fe2aeb4357e3971e5a569673b39
1
+ git+https://github.com/huggingface/evaluate@c447fc8eda9c62af501bfdc6988919571050d950