Datasets:

Modalities:
Text
ArXiv:
Libraries:
Datasets
License:
xwinograd / xwinograd.py
Muennighoff's picture
Fix path
18cfc02
raw
history blame
2.37 kB
"""XWinograd"""
import json
import datasets
logger = datasets.logging.get_logger(__name__)
_CITATION = """\
@misc{tikhonov2021heads,
title={It's All in the Heads: Using Attention Heads as a Baseline for Cross-Lingual Transfer in Commonsense Reasoning},
author={Alexey Tikhonov and Max Ryabinin},
year={2021},
eprint={2106.12066},
archivePrefix={arXiv},
primaryClass={cs.CL}
}
"""
_DESCRIPTION = """\
A multilingual collection of Winograd Schemas in six languages \
that can be used for evaluation of cross-lingual commonsense reasoning capabilities.
"""
_LANG = ["en", "fr", "jp", "pt", "ru", "zh"]
_URL = "https://huggingface.co/datasets/Muennighoff/xwinograd/raw/main/test/{lang}.jsonl"
_VERSION = datasets.Version("1.1.0", "")
class XWinograd(datasets.GeneratorBasedBuilder):
"""XWinograd"""
BUILDER_CONFIGS = [
datasets.BuilderConfig(
name=lang,
description=f"XWinograd in {lang}",
version=_VERSION,
)
for lang in _LANG
]
def _info(self):
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=datasets.Features(
{
"sentence": datasets.Value("string"),
"option1": datasets.Value("string"),
"option2": datasets.Value("string"),
"answer": datasets.Value("string")
}
),
supervised_keys=None,
citation=_CITATION,
)
def _split_generators(self, dl_manager):
downloaded_files = dl_manager.download(_URL.format(lang=self.config.name))
return [
datasets.SplitGenerator(
name=datasets.Split.TEST,
gen_kwargs={'filepath': downloaded_files}
)
]
def _generate_examples(self, filepath):
"""This function returns the examples in the raw (text) form."""
logger.info("Generating examples from = %s", filepath)
with open(filepath, encoding="utf-8") as f:
for id_, row in enumerate(f):
data = json.loads(row)
yield id_, {
"sentence": data["sentence"],
"option1": data["option1"],
"option2": data["option2"],
"answer": data["answer"],
}