Spaces:
Running
Running
Update Space (evaluate main: c447fc8e)
Browse files- requirements.txt +1 -1
- ter.py +9 -23
requirements.txt
CHANGED
|
@@ -1,2 +1,2 @@
|
|
| 1 |
-
git+https://github.com/huggingface/evaluate@
|
| 2 |
sacrebleu
|
|
|
|
| 1 |
+
git+https://github.com/huggingface/evaluate@c447fc8eda9c62af501bfdc6988919571050d950
|
| 2 |
sacrebleu
|
ter.py
CHANGED
|
@@ -12,8 +12,6 @@
|
|
| 12 |
# See the License for the specific language governing permissions and
|
| 13 |
# limitations under the License.
|
| 14 |
""" TER metric as available in sacrebleu. """
|
| 15 |
-
from dataclasses import dataclass
|
| 16 |
-
|
| 17 |
import datasets
|
| 18 |
import sacrebleu as scb
|
| 19 |
from packaging import version
|
|
@@ -152,24 +150,9 @@ Examples:
|
|
| 152 |
"""
|
| 153 |
|
| 154 |
|
| 155 |
-
@dataclass
|
| 156 |
-
class TerConfig(evaluate.info.Config):
|
| 157 |
-
|
| 158 |
-
name: str = "default"
|
| 159 |
-
|
| 160 |
-
normalized: bool = False
|
| 161 |
-
ignore_punct: bool = False
|
| 162 |
-
support_zh_ja_chars: bool = False
|
| 163 |
-
case_sensitive: bool = False
|
| 164 |
-
|
| 165 |
-
|
| 166 |
@evaluate.utils.file_utils.add_start_docstrings(_DESCRIPTION, _KWARGS_DESCRIPTION)
|
| 167 |
class Ter(evaluate.Metric):
|
| 168 |
-
|
| 169 |
-
CONFIG_CLASS = TerConfig
|
| 170 |
-
ALLOWED_CONFIG_NAMES = ["default"]
|
| 171 |
-
|
| 172 |
-
def _info(self, config):
|
| 173 |
if version.parse(scb.__version__) < version.parse("1.4.12"):
|
| 174 |
raise ImportWarning(
|
| 175 |
"To use `sacrebleu`, the module `sacrebleu>=1.4.12` is required, and the current version of `sacrebleu` doesn't match this condition.\n"
|
|
@@ -180,7 +163,6 @@ class Ter(evaluate.Metric):
|
|
| 180 |
citation=_CITATION,
|
| 181 |
homepage="http://www.cs.umd.edu/~snover/tercom/",
|
| 182 |
inputs_description=_KWARGS_DESCRIPTION,
|
| 183 |
-
config=config,
|
| 184 |
features=[
|
| 185 |
datasets.Features(
|
| 186 |
{
|
|
@@ -205,6 +187,10 @@ class Ter(evaluate.Metric):
|
|
| 205 |
self,
|
| 206 |
predictions,
|
| 207 |
references,
|
|
|
|
|
|
|
|
|
|
|
|
|
| 208 |
):
|
| 209 |
# if only one reference is provided make sure we still use list of lists
|
| 210 |
if isinstance(references[0], str):
|
|
@@ -216,10 +202,10 @@ class Ter(evaluate.Metric):
|
|
| 216 |
transformed_references = [[refs[i] for refs in references] for i in range(references_per_prediction)]
|
| 217 |
|
| 218 |
sb_ter = TER(
|
| 219 |
-
normalized=
|
| 220 |
-
no_punct=
|
| 221 |
-
asian_support=
|
| 222 |
-
case_sensitive=
|
| 223 |
)
|
| 224 |
output = sb_ter.corpus_score(predictions, transformed_references)
|
| 225 |
|
|
|
|
| 12 |
# See the License for the specific language governing permissions and
|
| 13 |
# limitations under the License.
|
| 14 |
""" TER metric as available in sacrebleu. """
|
|
|
|
|
|
|
| 15 |
import datasets
|
| 16 |
import sacrebleu as scb
|
| 17 |
from packaging import version
|
|
|
|
| 150 |
"""
|
| 151 |
|
| 152 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
@evaluate.utils.file_utils.add_start_docstrings(_DESCRIPTION, _KWARGS_DESCRIPTION)
|
| 154 |
class Ter(evaluate.Metric):
|
| 155 |
+
def _info(self):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 156 |
if version.parse(scb.__version__) < version.parse("1.4.12"):
|
| 157 |
raise ImportWarning(
|
| 158 |
"To use `sacrebleu`, the module `sacrebleu>=1.4.12` is required, and the current version of `sacrebleu` doesn't match this condition.\n"
|
|
|
|
| 163 |
citation=_CITATION,
|
| 164 |
homepage="http://www.cs.umd.edu/~snover/tercom/",
|
| 165 |
inputs_description=_KWARGS_DESCRIPTION,
|
|
|
|
| 166 |
features=[
|
| 167 |
datasets.Features(
|
| 168 |
{
|
|
|
|
| 187 |
self,
|
| 188 |
predictions,
|
| 189 |
references,
|
| 190 |
+
normalized: bool = False,
|
| 191 |
+
ignore_punct: bool = False,
|
| 192 |
+
support_zh_ja_chars: bool = False,
|
| 193 |
+
case_sensitive: bool = False,
|
| 194 |
):
|
| 195 |
# if only one reference is provided make sure we still use list of lists
|
| 196 |
if isinstance(references[0], str):
|
|
|
|
| 202 |
transformed_references = [[refs[i] for refs in references] for i in range(references_per_prediction)]
|
| 203 |
|
| 204 |
sb_ter = TER(
|
| 205 |
+
normalized=normalized,
|
| 206 |
+
no_punct=ignore_punct,
|
| 207 |
+
asian_support=support_zh_ja_chars,
|
| 208 |
+
case_sensitive=case_sensitive,
|
| 209 |
)
|
| 210 |
output = sb_ter.corpus_score(predictions, transformed_references)
|
| 211 |
|