|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"""These are different multilingual translations and the English original of the STSbenchmark dataset.""" |
|
|
|
|
|
import csv |
|
|
|
import datasets |
|
|
|
|
|
_CITATION = """\ |
|
@InProceedings{huggingface:dataset:stsb_multi_mt, |
|
title = {Machine translated multilingual STS benchmark dataset.}, |
|
author={Philip May}, |
|
year={2021}, |
|
url={https://github.com/PhilipMay/stsb-multi-mt} |
|
} |
|
""" |
|
|
|
_DESCRIPTION = """\ |
|
These are different multilingual translations and the English original of the STSbenchmark dataset. \ |
|
Translation has been done with deepl.com. |
|
""" |
|
|
|
_HOMEPAGE = "https://github.com/PhilipMay/stsb-multi-mt" |
|
|
|
_LICENSE = "custom license - see project page" |
|
|
|
_BASE_URL = "https://raw.githubusercontent.com/PhilipMay/stsb-multi-mt/main/data" |
|
|
|
|
|
class StsbMultiMt(datasets.GeneratorBasedBuilder): |
|
"""These are different multilingual translations and the English original of the STSbenchmark dataset. |
|
|
|
Translation has been done with deepl.com. |
|
""" |
|
|
|
VERSION = datasets.Version("1.0.0") |
|
|
|
BUILDER_CONFIGS = [ |
|
datasets.BuilderConfig( |
|
name="en", |
|
version=VERSION, |
|
description="This is the original English STS benchmark data set.", |
|
), |
|
datasets.BuilderConfig( |
|
name="de", |
|
version=VERSION, |
|
description="This is the German STS benchmark data set.", |
|
), |
|
datasets.BuilderConfig( |
|
name="es", |
|
version=VERSION, |
|
description="This is the Spanish STS benchmark data set.", |
|
), |
|
datasets.BuilderConfig( |
|
name="fr", |
|
version=VERSION, |
|
description="This is the French STS benchmark data set.", |
|
), |
|
datasets.BuilderConfig( |
|
name="it", |
|
version=VERSION, |
|
description="This is the Italian STS benchmark data set.", |
|
), |
|
|
|
|
|
datasets.BuilderConfig( |
|
name="nl", |
|
version=VERSION, |
|
description="This is the Dutch STS benchmark data set.", |
|
), |
|
datasets.BuilderConfig( |
|
name="pl", |
|
version=VERSION, |
|
description="This is the Polish STS benchmark data set.", |
|
), |
|
datasets.BuilderConfig( |
|
name="pt", |
|
version=VERSION, |
|
description="This is the Portuguese STS benchmark data set.", |
|
), |
|
datasets.BuilderConfig( |
|
name="ru", |
|
version=VERSION, |
|
description="This is the Russian STS benchmark data set.", |
|
), |
|
datasets.BuilderConfig( |
|
name="zh", |
|
version=VERSION, |
|
description="This is the Chinese (simplified) STS benchmark data set.", |
|
), |
|
] |
|
|
|
def _info(self): |
|
features = datasets.Features( |
|
{ |
|
"sentence1": datasets.Value("string"), |
|
"sentence2": datasets.Value("string"), |
|
"similarity_score": datasets.Value("float"), |
|
} |
|
) |
|
return datasets.DatasetInfo( |
|
|
|
description=_DESCRIPTION, |
|
|
|
features=features, |
|
|
|
|
|
|
|
supervised_keys=None, |
|
|
|
homepage=_HOMEPAGE, |
|
|
|
license=_LICENSE, |
|
|
|
citation=_CITATION, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
"""Returns SplitGenerators.""" |
|
urls_to_download = { |
|
"train": f"{_BASE_URL}/stsb-{self.config.name}-train.csv", |
|
"dev": f"{_BASE_URL}/stsb-{self.config.name}-dev.csv", |
|
"test": f"{_BASE_URL}/stsb-{self.config.name}-test.csv", |
|
} |
|
downloaded_files = dl_manager.download(urls_to_download) |
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, |
|
|
|
gen_kwargs={ |
|
"filepath": downloaded_files["train"], |
|
}, |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TEST, |
|
|
|
gen_kwargs={ |
|
"filepath": downloaded_files["test"], |
|
}, |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.NamedSplit("dev"), |
|
|
|
gen_kwargs={ |
|
"filepath": downloaded_files["dev"], |
|
}, |
|
), |
|
] |
|
|
|
def _generate_examples( |
|
self, |
|
filepath, |
|
): |
|
"""Yields examples as (key, example) tuples.""" |
|
|
|
|
|
with open(filepath, newline="", encoding="utf-8") as csvfile: |
|
csv_dict_reader = csv.DictReader( |
|
csvfile, |
|
fieldnames=["sentence1", "sentence2", "similarity_score"], |
|
dialect="excel", |
|
) |
|
for id_, row in enumerate(csv_dict_reader): |
|
|
|
assert "sentence1" in row |
|
assert isinstance(row["sentence1"], str) |
|
assert len(row["sentence1"].strip()) > 0 |
|
assert "sentence2" in row |
|
assert isinstance(row["sentence2"], str) |
|
assert len(row["sentence2"].strip()) > 0 |
|
assert "similarity_score" in row |
|
assert isinstance(row["similarity_score"], str) |
|
assert len(row["similarity_score"].strip()) > 0 |
|
|
|
|
|
row["similarity_score"] = float(row["similarity_score"]) |
|
|
|
|
|
assert row["similarity_score"] >= 0.0 |
|
assert row["similarity_score"] <= 5.0 |
|
|
|
yield id_, row |
|
|