sts17-crosslingual-sts / sts17-crosslingual-sts.py
tomaarsen's picture
tomaarsen HF staff
Added utf-8 encoding to gszip open as STS17 has multilingual data (#2)
fda8ada verified
# coding=utf-8
"""MASSIVE: A 1M-Example Multilingual Natural Language Understanding Dataset with 51 Typologically-Diverse Languages"""
import json
import datasets
import os
import gzip
logger = datasets.logging.get_logger(__name__)
_DESCRIPTION = """\
STS17 Cross-lingual dataset
"""
_LANGUAGES = [
'ko-ko',
'ar-ar',
'en-ar',
'en-de',
'en-en',
'en-tr',
'es-en',
'es-es',
'fr-en',
'it-en',
'nl-en'
]
class STS17_CROSSLINGUAL(datasets.GeneratorBasedBuilder):
"""STS2017 Cross-lingual"""
BUILDER_CONFIGS = [
datasets.BuilderConfig(
name=name,
version=datasets.Version("1.0.0"),
description=f"The STS17 cross-lingual dataset for {name} language pair.",
)
for name in _LANGUAGES
]
DEFAULT_CONFIG_NAME = 'en-en'
def _info(self):
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=datasets.Features(
{
"sentence1": datasets.Value("string"),
"sentence2": datasets.Value("string"),
"score": datasets.Value("float32"),
},
),
supervised_keys=None,
homepage="http://ixa2.si.ehu.eus/stswiki/index.php/STSbenchmark",
)
def _split_generators(self, dl_manager):
url = f'{self.config.name}/test.jsonl.gz'
archive_path = dl_manager.download(url)
return [
datasets.SplitGenerator(
name=datasets.Split.TEST,
gen_kwargs={
"text_path": archive_path,
},
),
]
def _generate_examples(self, text_path):
"""Yields examples."""
with gzip.open(text_path,'rt',encoding='utf-8') as f:
for i, line in enumerate(f):
yield i, json.loads(line)