Upload mteb-fr-retrieval-syntec-s2p.py
Browse files- mteb-fr-retrieval-syntec-s2p.py +101 -0
mteb-fr-retrieval-syntec-s2p.py
ADDED
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
|
2 |
+
#
|
3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4 |
+
# you may not use this file except in compliance with the License.
|
5 |
+
# You may obtain a copy of the License at
|
6 |
+
#
|
7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8 |
+
#
|
9 |
+
# Unless required by applicable law or agreed to in writing, software
|
10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12 |
+
# See the License for the specific language governing permissions and
|
13 |
+
# limitations under the License.
|
14 |
+
"""Syntec: 100 questions for information retrieval"""
|
15 |
+
import json
|
16 |
+
import datasets
|
17 |
+
|
18 |
+
_DESCRIPTION = """\
|
19 |
+
This dataset is based on the Syntec collective bargaining agreement. Its purpose is information retrieval.
|
20 |
+
"""
|
21 |
+
|
22 |
+
_SPLITS = ["documents", "queries"]
|
23 |
+
_HOMEPAGE = "https://huggingface.co/datasets/lyon-nlp/mteb-fr-retrieval-syntec-s2p"
|
24 |
+
_LICENSE = "Creative Commons Attribution Non Commercial Share Alike 4.0 International"
|
25 |
+
_URLS = {
|
26 |
+
split: f"https://huggingface.co/datasets/lyon-nlp/mteb-fr-retrieval-syntec-s2p/resolve/main/{split}.json"\
|
27 |
+
for split in _SPLITS
|
28 |
+
}
|
29 |
+
|
30 |
+
class Syntec(datasets.GeneratorBasedBuilder):
|
31 |
+
"""Syntec: 100 questions for information retrieval"""
|
32 |
+
|
33 |
+
VERSION = datasets.Version("1.0.0")
|
34 |
+
BUILDER_CONFIGS = [
|
35 |
+
datasets.BuilderConfig(name="documents", version=VERSION, description="Corpus of articles from the Syntec collective bargaining agreement"),
|
36 |
+
datasets.BuilderConfig(name="queries", version=VERSION, description="Corpus of 100 manually annotated queries"),
|
37 |
+
]
|
38 |
+
|
39 |
+
# Avoid setting default config so that an error is raised asking the user
|
40 |
+
# to specify the piece of the dataset wanted
|
41 |
+
DEFAULT_CONFIG_NAME = "documents"
|
42 |
+
|
43 |
+
def _info(self):
|
44 |
+
if self.config.name == "documents":
|
45 |
+
features = {
|
46 |
+
"section": datasets.Value("string"),
|
47 |
+
"id": datasets.Value("string"),
|
48 |
+
"title": datasets.Value("string"),
|
49 |
+
"content": datasets.Value("string"),
|
50 |
+
"url": datasets.Value("string"),
|
51 |
+
}
|
52 |
+
elif self.config.name == "queries":
|
53 |
+
features = {
|
54 |
+
"Question": datasets.Value("string"),
|
55 |
+
"Article": datasets.Value("string"),
|
56 |
+
}
|
57 |
+
else:
|
58 |
+
raise ValueError(f"Please specify a valid config name : {_SPLITS}")
|
59 |
+
return datasets.DatasetInfo(
|
60 |
+
description=_DESCRIPTION,
|
61 |
+
features=datasets.Features(features),
|
62 |
+
supervised_keys=None,
|
63 |
+
homepage=_HOMEPAGE,
|
64 |
+
license=_LICENSE,
|
65 |
+
citation=_CITATION,
|
66 |
+
)
|
67 |
+
|
68 |
+
def _split_generators(self, dl_manager):
|
69 |
+
if self.config.name == "documents":
|
70 |
+
dl_path = dl_manager.download_and_extract(_URLS["documents"])
|
71 |
+
return [datasets.SplitGenerator(name="documents", gen_kwargs={"filepath": dl_path})]
|
72 |
+
elif self.config.name == "queries":
|
73 |
+
dl_paths = dl_manager.download_and_extract(_URLS["queries"])
|
74 |
+
return [datasets.SplitGenerator(name="queries", gen_kwargs={"filepath": dl_paths})]
|
75 |
+
else:
|
76 |
+
raise ValueError(f"Please specify a valid config name : {_SPLITS}")
|
77 |
+
|
78 |
+
|
79 |
+
def _generate_examples(self, filepath):
|
80 |
+
if self.config.name in ["documents", "queries"]:
|
81 |
+
with open(filepath, encoding="utf-8") as f:
|
82 |
+
data = json.load(f)
|
83 |
+
for key, row in enumerate(data):
|
84 |
+
if self.config.name == "documents":
|
85 |
+
features = {
|
86 |
+
"section": row["section"],
|
87 |
+
"id": row["id"],
|
88 |
+
"title": row["title"],
|
89 |
+
"content": row["content"],
|
90 |
+
"url": row["url"]
|
91 |
+
}
|
92 |
+
elif self.config.name == "queries":
|
93 |
+
features = {
|
94 |
+
"Question": row["Question"],
|
95 |
+
"Article": row["Article"],
|
96 |
+
}
|
97 |
+
else:
|
98 |
+
raise ValueError(f"Please specify a valid config name : {_SPLITS}")
|
99 |
+
yield key, features
|
100 |
+
else:
|
101 |
+
raise ValueError(f"Please specify a valid config name : {_SPLITS}")
|