|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"""PAWS-X, a multilingual version of PAWS for six languages.""" |
|
|
|
|
|
import json |
|
|
|
import datasets |
|
|
|
|
|
_CITATION = """\ |
|
@InProceedings{pawsx2019emnlp, |
|
title = {{PAWS-X: A Cross-lingual Adversarial Dataset for Paraphrase Identification}}, |
|
author = {Yang, Yinfei and Zhang, Yuan and Tar, Chris and Baldridge, Jason}, |
|
booktitle = {Proc. of EMNLP}, |
|
year = {2019} |
|
} |
|
""" |
|
|
|
_DESCRIPTION = """\ |
|
Norwegian PAWS-X, Bokmaal and Nynorsk machine-translated versions of PAWS-X. |
|
|
|
PAWS-X, a multilingual version of PAWS (Paraphrase Adversaries from Word Scrambling) for six languages. |
|
|
|
This dataset contains 23,659 human translated PAWS evaluation pairs and 296,406 machine |
|
translated training pairs in six typologically distinct languages: French, Spanish, German, |
|
Chinese, Japanese, and Korean. English language is available by default. All translated |
|
pairs are sourced from examples in PAWS-Wiki. |
|
|
|
For further details, see the accompanying paper: PAWS-X: A Cross-lingual Adversarial Dataset |
|
for Paraphrase Identification (https://arxiv.org/abs/1908.11828) |
|
|
|
NOTE: There might be some missing or wrong labels in the dataset and we have replaced them with -1. |
|
""" |
|
|
|
_HOMEPAGE = "https://github.com/google-research-datasets/paws/tree/master/pawsx" |
|
|
|
|
|
_LICENSE = 'The dataset may be freely used for any purpose, although acknowledgement of Google LLC ("Google") as the data source would be appreciated. The dataset is provided "AS IS" without any warranty, express or implied. Google disclaims all liability for any damages, direct or indirect, resulting from the use of the dataset.' |
|
|
|
|
|
|
|
|
|
_DATA_OPTIONS = [ |
|
"nb", |
|
"nn", |
|
] |
|
|
|
_DATA_URL = "https://huggingface.co/datasets/NbAiLab/norwegian-paws-x/resolve/main/norwegian-x-final.tar.gz" |
|
|
|
|
|
class NorwegianPAWSXConfig(datasets.BuilderConfig): |
|
"""BuilderConfig for NorwegianPAWSX.""" |
|
|
|
def __init__(self, **kwargs): |
|
"""Constructs a NorwegianPAWSXConfig. |
|
Args: |
|
**kwargs: keyword arguments forwarded to super. |
|
""" |
|
super(NorwegianPAWSXConfig, self).__init__(version=datasets.Version("1.1.0", ""), **kwargs), |
|
|
|
|
|
class NorwegianPAWSX(datasets.GeneratorBasedBuilder): |
|
"""Norwegian PAWS-X, Bokmaal and Nynorsk machine-translated versions of PAWS-X.""" |
|
|
|
VERSION = datasets.Version("1.1.0") |
|
|
|
BUILDER_CONFIGS = [ |
|
NorwegianPAWSXConfig( |
|
name=config_name, |
|
description=(f"This config contains samples in {config_name}."), |
|
) |
|
for config_name in _DATA_OPTIONS |
|
] |
|
|
|
def _info(self): |
|
features = datasets.Features( |
|
{ |
|
"id": datasets.Value("int32"), |
|
"sentence1": datasets.Value("string"), |
|
"sentence2": datasets.Value("string"), |
|
"label": datasets.features.ClassLabel(names=["0", "1"]), |
|
} |
|
) |
|
return datasets.DatasetInfo( |
|
|
|
description=_DESCRIPTION, |
|
|
|
features=features, |
|
|
|
|
|
|
|
supervised_keys=None, |
|
|
|
homepage=_HOMEPAGE, |
|
|
|
license=_LICENSE, |
|
|
|
citation=_CITATION, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
"""Returns SplitGenerators.""" |
|
|
|
archive = dl_manager.download(_DATA_URL) |
|
|
|
_TEST_FILE_NAME = f"x-final/{self.config.name}/translated_test_2k.json" |
|
_VAL_FILE_NAME = f"x-final/{self.config.name}/translated_dev_2k.json" |
|
_TRAIN_FILE_NAME = f"x-final/{self.config.name}/translated_train.json" |
|
|
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, |
|
|
|
gen_kwargs={ |
|
"filepath": _TRAIN_FILE_NAME, |
|
"files": dl_manager.iter_archive(archive), |
|
}, |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TEST, |
|
|
|
gen_kwargs={ |
|
"filepath": _TEST_FILE_NAME, |
|
"files": dl_manager.iter_archive(archive), |
|
}, |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.VALIDATION, |
|
|
|
gen_kwargs={ |
|
"filepath": _VAL_FILE_NAME, |
|
"files": dl_manager.iter_archive(archive), |
|
}, |
|
), |
|
] |
|
|
|
def _generate_examples(self, filepath, files): |
|
"""Yields examples.""" |
|
|
|
for path, f in files: |
|
if path == filepath: |
|
lines = (line.decode("utf-8") for line in f) |
|
for id_, data in enumerate(lines): |
|
row = json.loads(data) |
|
yield id_, { |
|
"id": row["id"], |
|
"sentence1": row["sentence1"], |
|
"sentence2": row["sentence2"], |
|
"label": row["label"], |
|
} |
|
break |
|
|