wino_x / wino_x.py
demelin
Updated the dataset card.
79a0451
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
""" Wino-X is a parallel dataset of German, French, and Russian Winograd schemas, aligned with their English
counterparts, used to examine whether neural machine translation models can perform coreference resolution that
requires commonsense knowledge, and whether multilingual language models are capable of commonsense reasoning across
multiple languages. """
import csv
import json
import os
import datasets
_CITATION = """\
@inproceedings{Emelin2021WinoXMW,
title={Wino-X: Multilingual Winograd Schemas for Commonsense Reasoning and Coreference Resolution},
author={Denis Emelin and Rico Sennrich},
booktitle={EMNLP},
year={2021}
}
"""
# You can copy an official description
_DESCRIPTION = """\
Wino-X is a parallel dataset of German, French, and Russian Winograd schemas, aligned with their English
counterparts, used to examine whether neural machine translation models can perform coreference resolution that
requires commonsense knowledge and whether multilingual language models are capable of commonsense reasoning across
multiple languages.
"""
_HOMEPAGE = "https://github.com/demelin/Wino-X"
_LICENSE = "MIT"
# The HuggingFace Datasets library doesn't host the datasets but only points to the original files.
# This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
_URLS = {
"mt_en_de": "https://huggingface.co/datasets/demelin/wino_x/resolve/main/data/mt/en_de_test.jsonl",
"mt_en_fr": "https://huggingface.co/datasets/demelin/wino_x/resolve/main/data/mt/en_fr_test.jsonl",
"mt_en_ru": "https://huggingface.co/datasets/demelin/wino_x/resolve/main/data/mt/en_ru_test.jsonl",
"lm_en_de": "https://huggingface.co/datasets/demelin/wino_x/resolve/main/data/lm/en_de_test.jsonl",
"lm_en_fr": "https://huggingface.co/datasets/demelin/wino_x/resolve/main/data/lm/en_fr_test.jsonl",
"lm_en_ru": "https://huggingface.co/datasets/demelin/wino_x/resolve/main/data/lm/en_ru_test.jsonl"
}
class WinoX(datasets.GeneratorBasedBuilder):
""" Wino-X is a dataset of German, French, and Russian Winograd schemas, aligned with their English counterparts """
VERSION = datasets.Version("1.1.0")
BUILDER_CONFIGS = [
datasets.BuilderConfig(name="mt_en_de", version=VERSION,
description="This is the EN-DE part of the Wino-X translation data."),
datasets.BuilderConfig(name="mt_en_fr", version=VERSION,
description="This is the EN-FR part of the Wino-X translation data."),
datasets.BuilderConfig(name="mt_en_ru", version=VERSION,
description="This is the EN-RU part of the Wino-X translation data."),
datasets.BuilderConfig(name="lm_en_de", version=VERSION,
description="This is the EN-DE part of the Wino-X language modeling data."),
datasets.BuilderConfig(name="lm_en_fr", version=VERSION,
description="This is the EN-FR part of the Wino-X language modeling data."),
datasets.BuilderConfig(name="lm_en_ru", version=VERSION,
description="This is the EN-RU part of the Wino-X language modeling data."),
]
def _info(self):
# MT example:
# {"qID": "3UDTAB6HH8D37OQL3O6F3GXEEOF09Z-1",
# "sentence": "The woman looked for a different vase for the bouquet because it was too small.",
# "translation1": "Die Frau suchte nach einer anderen Vase für den Blumenstrauß, weil sie zu klein war.",
# "translation2": "Die Frau suchte nach einer anderen Vase für den Blumenstrauß, weil er zu klein war.",
# "answer": 1,
# "pronoun1": "sie",
# "pronoun2": "er",
# "referent1_en": "vase",
# "referent2_en": "bouquet",
# "true_translation_referent_of_pronoun1_de": "Vase",
# "true_translation_referent_of_pronoun2_de": "Blumenstrauß",
# "false_translation_referent_of_pronoun1_de": "Vase",
# "false_translation_referent_of_pronoun2_de": "Blumenstrauß"}
tgt_lang = self.config.name.split('_')[-1]
if self.config.name.startswith('mt_'):
features = datasets.Features(
{
"qID": datasets.Value("string"),
"sentence": datasets.Value("string"),
"translation1": datasets.Value("string"),
"translation2": datasets.Value("string"),
"answer": datasets.Value("int64"),
"pronoun1": datasets.Value("string"),
"pronoun2": datasets.Value("string"),
"referent1_en": datasets.Value("string"),
"referent2_en": datasets.Value("string"),
"true_translation_referent_of_pronoun1_{}".format(tgt_lang): datasets.Value("string"),
"true_translation_referent_of_pronoun2_{}".format(tgt_lang): datasets.Value("string"),
"false_translation_referent_of_pronoun1_{}".format(tgt_lang): datasets.Value("string"),
"false_translation_referent_of_pronoun2_{}".format(tgt_lang): datasets.Value("string")
}
)
# LM example:
# {"qID": "3UDTAB6HH8D37OQL3O6F3GXEEOF09Z-1",
# "sentence": "The woman looked for a different vase for the bouquet because it was too small.",
# "context_en": "The woman looked for a different vase for the bouquet because _ was too small.",
# "context_de": "Die Frau suchte nach einer anderen Vase für den Blumenstrauß, weil _ zu klein war.",
# "option1_en": "the vase",
# "option2_en": "the bouquet",
# "option1_de": "die Vase",
# "option2_de": "der Blumenstrauß",
# "answer": 1,
# "context_referent_of_option1_de": "Vase",
# "context_referent_of_option2_de": "Blumenstrauß"}
else:
features = datasets.Features(
{
"qID": datasets.Value("string"),
"sentence": datasets.Value("string"),
"context_en": datasets.Value("string"),
"context_{}".format(tgt_lang): datasets.Value("string"),
"answer": datasets.Value("int64"),
"option1_en": datasets.Value("string"),
"option2_en": datasets.Value("string"),
"option1_{}".format(tgt_lang): datasets.Value("string"),
"option2_{}".format(tgt_lang): datasets.Value("string"),
"context_referent_of_option1_{}".format(tgt_lang): datasets.Value("string"),
"context_referent_of_option2_{}".format(tgt_lang): datasets.Value("string")
}
)
return datasets.DatasetInfo(
# This is the description that will appear on the datasets page.
description=_DESCRIPTION,
# This defines the different columns of the dataset and their types
features=features,
# Homepage of the dataset for documentation
homepage=_HOMEPAGE,
# License for the dataset if available
license=_LICENSE,
# Citation for the dataset
citation=_CITATION,
)
def _split_generators(self, dl_manager):
downloaded_files = dl_manager.download_and_extract(_URLS[self.config.name])
return [datasets.SplitGenerator(name=datasets.Split.TEST,
gen_kwargs={'filepath': downloaded_files, 'split': 'test'})]
# method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
def _generate_examples(self, filepath, split):
# The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
with open(filepath, encoding="utf-8") as f:
for key, row in enumerate(f):
data = json.loads(row)
yield key, data