Create stsb_multi_mt_extend.py
Browse files- stsb_multi_mt_extend.py +82 -0
stsb_multi_mt_extend.py
ADDED
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# coding=utf-8
|
2 |
+
|
3 |
+
"""STS Benchmark Multilingual dataset"""
|
4 |
+
|
5 |
+
import json
|
6 |
+
import os
|
7 |
+
import gzip
|
8 |
+
|
9 |
+
import datasets
|
10 |
+
|
11 |
+
logger = datasets.logging.get_logger(__name__)
|
12 |
+
|
13 |
+
_DESCRIPTION = """\
|
14 |
+
STS Benchmark Multilingual dataset by deepl and google (only ar)
|
15 |
+
"""
|
16 |
+
|
17 |
+
_LANGUAGES = ["de", "en", "es", "fr", "it", "nl", "pl", "pt", "ru", "zh"]
|
18 |
+
|
19 |
+
_NEW_LANGUAGES = ['ar', 'id']
|
20 |
+
|
21 |
+
|
22 |
+
class STSBMultilingual(datasets.GeneratorBasedBuilder):
|
23 |
+
"""STS Benchmark Multilingual"""
|
24 |
+
|
25 |
+
BUILDER_CONFIGS = [
|
26 |
+
datasets.BuilderConfig(
|
27 |
+
name=name,
|
28 |
+
version=datasets.Version("1.0.0"),
|
29 |
+
description=f"The STS Benchmark for {name} language{'' if name == 'en' else ' by deepl'}.",
|
30 |
+
)
|
31 |
+
for name in _LANGUAGES
|
32 |
+
] + [
|
33 |
+
datasets.BuilderConfig(
|
34 |
+
name='id',
|
35 |
+
version=datasets.Version("1.0.0"),
|
36 |
+
description=f"The STS Benchmark for id language by deepl.",
|
37 |
+
),
|
38 |
+
datasets.BuilderConfig(
|
39 |
+
name='ar',
|
40 |
+
version=datasets.Version("1.0.0"),
|
41 |
+
description=f"The STS Benchmark for id language by google translate.",
|
42 |
+
)
|
43 |
+
]
|
44 |
+
|
45 |
+
DEFAULT_CONFIG_NAME = 'en'
|
46 |
+
|
47 |
+
def _info(self):
|
48 |
+
return datasets.DatasetInfo(
|
49 |
+
description=_DESCRIPTION,
|
50 |
+
features=datasets.Features(
|
51 |
+
{
|
52 |
+
"sentence1": datasets.Value("string"),
|
53 |
+
"sentence2": datasets.Value("string"),
|
54 |
+
"score": datasets.Value("float32"),
|
55 |
+
},
|
56 |
+
),
|
57 |
+
supervised_keys=None,
|
58 |
+
homepage="https://github.com/PhilipMay/stsb-multi-mt",
|
59 |
+
)
|
60 |
+
|
61 |
+
def _split_generators(self, dl_manager):
|
62 |
+
if self.config.name == 'ar':
|
63 |
+
path_or_ds = dl_manager.download('test_ar_google.jsonl')
|
64 |
+
elif self.config.name == 'id':
|
65 |
+
path_or_ds = dl_manager.download('test_id_deepl.jsonl')
|
66 |
+
else:
|
67 |
+
path_or_ds = datasets.load_dataset("stsb_multi_mt", self.config.name, split="test")
|
68 |
+
return [
|
69 |
+
datasets.SplitGenerator(
|
70 |
+
name=datasets.Split.TEST, gen_kwargs={"path_or_ds": path_or_ds},
|
71 |
+
),
|
72 |
+
]
|
73 |
+
|
74 |
+
def _generate_examples(self, path_or_ds):
|
75 |
+
"""Yields examples."""
|
76 |
+
if isinstance(path_or_ds, datasets.Dataset):
|
77 |
+
for i, ins in enumerate(path_or_ds):
|
78 |
+
yield i, {'sentence1': ins['sentence1'], 'sentence2': ins['sentence2'], 'score': ins['similarity_score']}
|
79 |
+
else:
|
80 |
+
with open(text_path) as f:
|
81 |
+
for i, line in enumerate(f):
|
82 |
+
yield i, json.loads(line)
|