import json import datasets import os _CITATION = """\ """ _LICENSE = """\ """ _DESCRIPTION = """\ SemEval 2022 Task 8: Multilingual News Article Similarity """ _LANGUAGES_TRAIN = { "en": "en", "de": "de", "es": "es", "pl": "pl", "tr": "tr", "fr": "fr", "ar": "ar", "de-en": "de-en", } _LANGUAGES_TEST = { "en": "en", "de": "de", "es": "es", "pl": "pl", "tr": "tr", "ar": "ar", "ru": "ru", "zh": "zh", "fr": "fr", "de-en": "de-en", "es-en": "es-en", "it": "it", "pl-en": "pl-en", "zh-en": "zh-en", "es-it": "es-it", "de-fr": "de-fr", "de-pl": "de-pl", "fr-pl": "fr-pl", } _LANGUAGES = {**_LANGUAGES_TRAIN, **_LANGUAGES_TEST} _ALL_LANGUAGES = "all_languages" _HOMEPAGE_URL = "https://competitions.codalab.org/competitions/33835" _DOWNLOAD_URL = "{lang}/{split}.jsonl" _VERSION = "1.0.0" class STS22Task8Config(datasets.BuilderConfig): """BuilderConfig for STS22Task8Config.""" def __init__(self, languages=None, **kwargs): super(STS22Task8Config, self).__init__(version=datasets.Version(_VERSION, ""), **kwargs), self.languages = languages class STS22Task8(datasets.GeneratorBasedBuilder): """Multilingual News Article Similarity""" BUILDER_CONFIGS = [ STS22Task8Config( name=_ALL_LANGUAGES, languages=_LANGUAGES, description="Multilingual News Article Similarity", ) ] + [ STS22Task8Config( name=lang, languages=[lang], description=f"{_LANGUAGES[lang]} examples from a collection of multilingual news articles", ) for lang in _LANGUAGES ] BUILDER_CONFIG_CLASS = STS22Task8Config DEFAULT_CONFIG_NAME = _ALL_LANGUAGES def _info(self): return datasets.DatasetInfo( description=_DESCRIPTION, features=datasets.Features( { "id": datasets.Value("string"), "sentence1": datasets.Value("string"), "sentence2": datasets.Value("string"), "score": datasets.Value("float32"), }, ), supervised_keys=None, license=_LICENSE, homepage=_HOMEPAGE_URL, citation=_CITATION, ) def _split_generators(self, dl_manager): # train_urls = [_DOWNLOAD_URL.format(split="train", lang=lang) for lang in self.config.languages if lang in _LANGUAGES_TRAIN] test_urls = [ _DOWNLOAD_URL.format(split="test", lang=lang) for lang in self.config.languages if lang in _LANGUAGES_TEST ] # train_paths = dl_manager.download_and_extract(train_urls) test_paths = dl_manager.download_and_extract(test_urls) return [ # datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"file_paths": train_paths}), datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"file_paths": test_paths}), ] def _generate_examples(self, file_paths): row_count = 0 for file_path in file_paths: with open(file_path, "r", encoding="utf-8") as f: for line in f: yield row_count, json.loads(line) row_count += 1