Datasets:
Commit
•
3d4f993
1
Parent(s):
4e1141e
Create sts22-crosslingual-sts.py
Browse files- sts22-crosslingual-sts.py +117 -0
sts22-crosslingual-sts.py
ADDED
@@ -0,0 +1,117 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
import datasets
|
3 |
+
import os
|
4 |
+
|
5 |
+
_CITATION = """\
|
6 |
+
"""
|
7 |
+
|
8 |
+
_LICENSE = """\
|
9 |
+
"""
|
10 |
+
|
11 |
+
_DESCRIPTION = """\
|
12 |
+
SemEval 2022 Task 8: Multilingual News Article Similarity
|
13 |
+
"""
|
14 |
+
|
15 |
+
_LANGUAGES_TRAIN = {
|
16 |
+
"en": "en",
|
17 |
+
"de": "de",
|
18 |
+
"es": "es",
|
19 |
+
"pl": "pl",
|
20 |
+
"tr": "tr",
|
21 |
+
"fr": "fr",
|
22 |
+
"ar": "ar",
|
23 |
+
"de-en": "de-en",
|
24 |
+
}
|
25 |
+
_LANGUAGES_TEST = {
|
26 |
+
"en": "en",
|
27 |
+
"de": "de",
|
28 |
+
"es": "es",
|
29 |
+
"pl": "pl",
|
30 |
+
"tr": "tr",
|
31 |
+
"ar": "ar",
|
32 |
+
"ru": "ru",
|
33 |
+
"zh": "zh",
|
34 |
+
"fr": "fr",
|
35 |
+
"de-en": "de-en",
|
36 |
+
"es-en": "es-en",
|
37 |
+
"it": "it",
|
38 |
+
"pl-en": "pl-en",
|
39 |
+
"zh-en": "zh-en",
|
40 |
+
"es-it": "es-it",
|
41 |
+
"de-fr": "de-fr",
|
42 |
+
"de-pl": "de-pl",
|
43 |
+
"fr-pl": "fr-pl",
|
44 |
+
}
|
45 |
+
_LANGUAGES = {**_LANGUAGES_TRAIN, **_LANGUAGES_TEST}
|
46 |
+
|
47 |
+
_ALL_LANGUAGES = "all_languages"
|
48 |
+
_HOMEPAGE_URL = "https://competitions.codalab.org/competitions/33835"
|
49 |
+
_DOWNLOAD_URL = "{lang}/{split}.jsonl"
|
50 |
+
_VERSION = "1.0.0"
|
51 |
+
|
52 |
+
|
53 |
+
class STS22Task8Config(datasets.BuilderConfig):
|
54 |
+
"""BuilderConfig for STS22Task8Config."""
|
55 |
+
|
56 |
+
def __init__(self, languages=None, **kwargs):
|
57 |
+
super(STS22Task8Config, self).__init__(version=datasets.Version(_VERSION, ""), **kwargs),
|
58 |
+
self.languages = languages
|
59 |
+
|
60 |
+
|
61 |
+
class AmazonReviewsMulti(datasets.GeneratorBasedBuilder):
|
62 |
+
|
63 |
+
"""Multilingual News Article Similarity"""
|
64 |
+
|
65 |
+
BUILDER_CONFIGS = [
|
66 |
+
STS22Task8Config(
|
67 |
+
name=_ALL_LANGUAGES,
|
68 |
+
languages=_LANGUAGES,
|
69 |
+
description="Multilingual News Article Similarity",
|
70 |
+
)
|
71 |
+
] + [
|
72 |
+
STS22Task8Config(
|
73 |
+
name=lang,
|
74 |
+
languages=[lang],
|
75 |
+
description=f"{_LANGUAGES[lang]} examples from a collection of multilingual news articles",
|
76 |
+
)
|
77 |
+
for lang in _LANGUAGES
|
78 |
+
]
|
79 |
+
BUILDER_CONFIG_CLASS = STS22Task8Config
|
80 |
+
DEFAULT_CONFIG_NAME = _ALL_LANGUAGES
|
81 |
+
|
82 |
+
def _info(self):
|
83 |
+
return datasets.DatasetInfo(
|
84 |
+
description=_DESCRIPTION,
|
85 |
+
features=datasets.Features(
|
86 |
+
{
|
87 |
+
"id": datasets.Value("string"),
|
88 |
+
"sentence1": datasets.Value("string"),
|
89 |
+
"sentence2": datasets.Value("string"),
|
90 |
+
"score": datasets.Value("float32"),
|
91 |
+
},
|
92 |
+
),
|
93 |
+
supervised_keys=None,
|
94 |
+
license=_LICENSE,
|
95 |
+
homepage=_HOMEPAGE_URL,
|
96 |
+
citation=_CITATION,
|
97 |
+
)
|
98 |
+
|
99 |
+
def _split_generators(self, dl_manager):
|
100 |
+
train_urls = [_DOWNLOAD_URL.format(split="train", lang=lang) for lang in self.config.languages if lang in _LANGUAGES_TRAIN]
|
101 |
+
test_urls = [_DOWNLOAD_URL.format(split="test", lang=lang) for lang in self.config.languages if lang in _LANGUAGES_TEST]
|
102 |
+
|
103 |
+
train_paths = dl_manager.download_and_extract(train_urls)
|
104 |
+
test_paths = dl_manager.download_and_extract(test_urls)
|
105 |
+
|
106 |
+
return [
|
107 |
+
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"file_paths": train_paths}),
|
108 |
+
datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"file_paths": test_paths}),
|
109 |
+
]
|
110 |
+
|
111 |
+
def _generate_examples(self, file_paths):
|
112 |
+
row_count = 0
|
113 |
+
for file_path in file_paths:
|
114 |
+
with open(file_path, "r", encoding="utf-8") as f:
|
115 |
+
for line in f:
|
116 |
+
yield row_count, json.loads(line)
|
117 |
+
row_count += 1
|