Commit
·
11538ef
1
Parent(s):
8978a83
Create sacrebleu_manual.py
Browse files- sacrebleu_manual.py +69 -0
sacrebleu_manual.py
ADDED
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
NOTE: This file implements translation tasks using datasets from WMT conferences,
|
3 |
+
provided by sacrebleu. Traditionally they are evaluated with BLEU scores. TER
|
4 |
+
and CHRF are other options.
|
5 |
+
|
6 |
+
We defer citations and descriptions of the many translations tasks used
|
7 |
+
here to the SacreBLEU repo from which we've obtained the datasets:
|
8 |
+
https://github.com/mjpost/sacrebleu/blob/master/sacrebleu/dataset.py
|
9 |
+
|
10 |
+
Homepage: https://github.com/mjpost/sacrebleu/blob/master/sacrebleu/dataset.py
|
11 |
+
"""
|
12 |
+
import pycountry
|
13 |
+
from sacrebleu import sacrebleu
|
14 |
+
import datasets
|
15 |
+
|
16 |
+
|
17 |
+
_CITATION = """
|
18 |
+
@inproceedings{post-2018-call,
|
19 |
+
title = "A Call for Clarity in Reporting {BLEU} Scores",
|
20 |
+
author = "Post, Matt",
|
21 |
+
booktitle = "Proceedings of the Third Conference on Machine Translation: Research Papers",
|
22 |
+
month = oct,
|
23 |
+
year = "2018",
|
24 |
+
address = "Belgium, Brussels",
|
25 |
+
publisher = "Association for Computational Linguistics",
|
26 |
+
url = "https://www.aclweb.org/anthology/W18-6319",
|
27 |
+
pages = "186--191",
|
28 |
+
}
|
29 |
+
"""
|
30 |
+
|
31 |
+
|
32 |
+
class Sacrebleu(datasets.GeneratorBasedBuilder):
|
33 |
+
"""The Pile is a 825 GiB diverse, open source language modeling dataset."""
|
34 |
+
|
35 |
+
VERSION = datasets.Version("0.0.1")
|
36 |
+
|
37 |
+
BUILDER_CONFIGS = [
|
38 |
+
datasets.BuilderConfig(name=f"{name}/{langpair}", version=VERSION, description="")
|
39 |
+
for langpair in sacrebleu.get_langpairs_for_testset(name)
|
40 |
+
for name in sacrebleu.get_available_testsets()
|
41 |
+
]
|
42 |
+
|
43 |
+
def _info(self):
|
44 |
+
features = datasets.Features(
|
45 |
+
{
|
46 |
+
"translation": datasets.Value("dict"),
|
47 |
+
}
|
48 |
+
)
|
49 |
+
return datasets.DatasetInfo(
|
50 |
+
description=f"{_DESCRIPTION}\n{self.config.description}",
|
51 |
+
features=features,
|
52 |
+
homepage="",
|
53 |
+
license="",
|
54 |
+
citation=_CITATION,
|
55 |
+
)
|
56 |
+
|
57 |
+
def _split_generators(self, dl_manager):
|
58 |
+
return [
|
59 |
+
datasets.SplitGenerator(
|
60 |
+
name=datasets.Split.TEST,
|
61 |
+
gen_kwargs={path: f"{self.config.name}.jsonl"},
|
62 |
+
)
|
63 |
+
]
|
64 |
+
|
65 |
+
# method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
|
66 |
+
def _generate_examples(self, path):
|
67 |
+
with open(path, encoding="utf-8") as f:
|
68 |
+
for key, row in enumerate(f):
|
69 |
+
yield key, json.loads(row)
|