| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| """WMT21 Metrics Shared Task: Segment-Level Data""" |
|
|
| import datasets |
| import csv |
|
|
| _CITATION = """\ |
| @inproceedings{freitag-etal-2021-results, |
| title = {Results of the WMT21 Metrics Shared Task: Evaluating Metrics with Expert-based Human Evaluations on TED and News Domain}, |
| author = {Freitag, Markus and Rei, Ricardo and Mathur, Nitika and Lo, Chi-kiu and Stewart, Craig and Foster, George and Lavie, Alon and Bojar, Ondrej}", |
| booktitle = {Proceedings of the Sixth Conference on Machine Translation}, |
| month = {nov}, |
| year = {2021}, |
| address = {Online}, |
| publisher = {Association for Computational Linguistics}, |
| url = {https://aclanthology.org/2021.wmt-1.73}, |
| pages = {733--774} |
| } |
| """ |
|
|
| _DESCRIPTION = """\ |
| This shared task will examine automatic evaluation metrics for machine translation. We will |
| provide you with MT system outputs along with source text and the human reference translations. |
| We are looking for automatic metric scores for translations at the system-level, and segment-level. |
| We will calculate the system-level, and segment-level correlations of your scores with human judgements. |
| |
| We invite submissions of reference-free metrics in addition to reference-based metrics. |
| """ |
|
|
| _HOMEPAGE = "https://www.statmt.org/wmt21/metrics-task.html" |
|
|
| _LICENSE = "Unknown" |
|
|
|
|
| _LANGUAGE_PAIRS = [('bn', 'hi'), ('hi', 'bn'), ('xh', 'zu'), ('zu', 'xh'), ('cs', 'en'), ('de', 'en'), ('de', 'fr'), ('en', 'cs'), ('en', 'de'), ('en', 'ha'), |
| ('en', 'is'), ('en', 'ja'), ('en', 'ru'), ('en', 'zh'), ('fr', 'de'), ('ha', 'en'), ('is', 'en'), ('ja', 'en'), ('ru', 'en'), ('zh', 'en')] |
|
|
| _URL_BASE = "https://huggingface.co/datasets/muibk/wmt21_metrics_task/resolve/main/" |
| _URLs = {f"{src_lg}-{trg_lg}": f"{_URL_BASE}{src_lg}-{trg_lg}/train.csv" for src_lg, trg_lg in _LANGUAGE_PAIRS} |
|
|
|
|
| class WmtMetricsTaskConfig(datasets.BuilderConfig): |
| """BuilderConfig for WMT Metrics Shared Task.""" |
| def __init__(self, src_lg, tgt_lg, **kwargs): |
| super(WmtMetricsTaskConfig, self).__init__(**kwargs) |
| self.src_lg = src_lg |
| self.tgt_lg = tgt_lg |
|
|
|
|
| class Wmt21MetricsTask(datasets.GeneratorBasedBuilder): |
| """WMT Metrics Shared Task.""" |
|
|
| BUILDER_CONFIGS = [ |
| WmtMetricsTaskConfig( |
| name=f"{src_lg}-{tgt_lg}", |
| version=datasets.Version("1.1.0"), |
| description=f"WMT 2021 Metrics Task: {src_lg} - {tgt_lg}", |
| src_lg=src_lg, |
| tgt_lg=tgt_lg, |
| ) |
| for (src_lg, tgt_lg) in _LANGUAGE_PAIRS |
| ] |
| BUILDER_CONFIG_CLASS = WmtMetricsTaskConfig |
|
|
| def _info(self): |
| |
| features = datasets.Features( |
| { |
| |
| |
| 'translation': datasets.Translation(languages=(self.config.src_lg, self.config.tgt_lg)), |
| 'mt_system':datasets.Value("string"), |
| 'mqm':datasets.Value("float32"), |
| 'wmt-raw':datasets.Value("float32"), |
| 'wmt-z':datasets.Value("float32"), |
| 'pair':datasets.Value("string"), |
| 'dataset':datasets.Value("string"), |
| 'sent_id':datasets.Value("int32"), |
| 'doc_name':datasets.Value("string"), |
| 'doc_ref':datasets.Value("string"), |
| 'ref-A':datasets.Value("string"), |
| 'ref-B':datasets.Value("string"), |
| 'ref-C':datasets.Value("string"), |
| 'ref-D':datasets.Value("string") |
| } |
| ) |
|
|
| return datasets.DatasetInfo( |
| description=_DESCRIPTION, |
| features=features, |
| supervised_keys=None, |
| homepage=_HOMEPAGE, |
| license=_LICENSE, |
| citation=_CITATION, |
| ) |
|
|
| def _split_generators(self, dl_manager): |
| """Returns SplitGenerators.""" |
| pair = f"{self.config.src_lg}-{self.config.tgt_lg}" |
| url = _URLs[pair] |
| data_file = dl_manager.download_and_extract(url) |
|
|
| return [ |
| datasets.SplitGenerator( |
| name=datasets.Split.TRAIN, |
| gen_kwargs={ |
| "filepath": data_file, |
| "source_lg": self.config.src_lg, |
| "target_lg": self.config.tgt_lg, |
| } |
| ) |
| ] |
| |
| def _generate_examples(self, filepath, source_lg, target_lg): |
| with open(filepath, encoding="utf-8") as f: |
| reader = csv.DictReader(f, delimiter=";") |
| for id_, row in enumerate(reader): |
| row["translation"] = {source_lg : row["source"], target_lg: row["system_output"]} |
| for key in ["source", "system_output"]: |
| row.pop(key) |
| row = {k: None if not v else v for k, v in row.items()} |
| yield id_, row |
|
|
| |
| |
|
|