Creating custom loading script.
Browse files
README.md
CHANGED
|
@@ -6,19 +6,6 @@ language:
|
|
| 6 |
- pt
|
| 7 |
size_categories:
|
| 8 |
- 1M<n<10M
|
| 9 |
-
configs:
|
| 10 |
-
- config_name: quati_10M_passages
|
| 11 |
-
data_files: quati_10M_part_*.tsv
|
| 12 |
-
sep: "\t"
|
| 13 |
-
- config_name: quati_1M_passages
|
| 14 |
-
data_files: quati_1M.tsv
|
| 15 |
-
sep: "\t"
|
| 16 |
-
- config_name: topics
|
| 17 |
-
data_files: topics/*.tsv
|
| 18 |
-
sep: "\t"
|
| 19 |
-
- config_name: qrels
|
| 20 |
-
data_files: qrels/*
|
| 21 |
-
sep: " "
|
| 22 |
---
|
| 23 |
|
| 24 |
# Quati Information Retrieval Dataset
|
|
|
|
| 6 |
- pt
|
| 7 |
size_categories:
|
| 8 |
- 1M<n<10M
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
---
|
| 10 |
|
| 11 |
# Quati Information Retrieval Dataset
|
quati.py
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# coding=utf-8
|
| 2 |
+
# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
|
| 3 |
+
#
|
| 4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
+
# you may not use this file except in compliance with the License.
|
| 6 |
+
# You may obtain a copy of the License at
|
| 7 |
+
#
|
| 8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
+
#
|
| 10 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
+
# See the License for the specific language governing permissions and
|
| 14 |
+
# limitations under the License.
|
| 15 |
+
|
| 16 |
+
# Lint as: python3
|
| 17 |
+
"""Quati dataset."""
|
| 18 |
+
|
| 19 |
+
import datasets
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
_CITATION = """
|
| 23 |
+
place holder
|
| 24 |
+
"""
|
| 25 |
+
|
| 26 |
+
_URL = "https://github.com/unicamp-dl/quati"
|
| 27 |
+
|
| 28 |
+
_DESCRIPTION = """
|
| 29 |
+
Quati ― Portuguese Native Information Retrieval dataset.
|
| 30 |
+
"""
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
QUATI_10M_DATASET_PARTS=["part_00", "part_01", "part_02", "part_03", "part_04"]
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
_URLS = {
|
| 39 |
+
"quati_1M_passages": "https://huggingface.co/datasets/unicamp-dl/quati/resolve/main/quati_1M_passages.tsv",
|
| 40 |
+
"quati_10M_passages_part_00": "https://huggingface.co/datasets/unicamp-dl/quati/resolve/main/quati_10M_part_00.tsv",
|
| 41 |
+
"quati_10M_passages_part_01": "https://huggingface.co/datasets/unicamp-dl/quati/resolve/main/quati_10M_part_01.tsv",
|
| 42 |
+
"quati_10M_passages_part_02": "https://huggingface.co/datasets/unicamp-dl/quati/resolve/main/quati_10M_part_02.tsv",
|
| 43 |
+
"quati_10M_passages_part_03": "https://huggingface.co/datasets/unicamp-dl/quati/resolve/main/quati_10M_part_03.tsv",
|
| 44 |
+
"quati_10M_passages_part_04": "https://huggingface.co/datasets/unicamp-dl/quati/resolve/main/quati_10M_part_04.tsv",
|
| 45 |
+
"quati_1M_qrels": "https://huggingface.co/datasets/unicamp-dl/quati/resolve/main/qrels/quati_1M_qrels.txt",
|
| 46 |
+
"quati_10M_qrels": "https://huggingface.co/datasets/unicamp-dl/quati/resolve/main/qrels/quati_10M_qrels.txt",
|
| 47 |
+
"quati_test_topics": "https://huggingface.co/datasets/unicamp-dl/quati/resolve/main/topics/quati_test_topics.txt",
|
| 48 |
+
"quati_all_topics": "https://huggingface.co/datasets/unicamp-dl/quati/resolve/main/topics/quati_all_topics.txt"
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
def generate_examples_passages(filepath):
|
| 54 |
+
|
| 55 |
+
with open(filepath, encoding="utf-8") as input_file:
|
| 56 |
+
for (idx, line) in enumerate(input_file):
|
| 57 |
+
|
| 58 |
+
passage_id, passage = line.rstrip().split("\t")
|
| 59 |
+
|
| 60 |
+
features = {"passage_id": passage_id,
|
| 61 |
+
"passage": passage}
|
| 62 |
+
|
| 63 |
+
yield idx, features
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
def generate_examples_qrels(filepath):
|
| 68 |
+
|
| 69 |
+
with open(filepath, encoding="utf-8") as input_file:
|
| 70 |
+
for (idx, line) in enumerate(input_file):
|
| 71 |
+
query_id, _, passage_id, score = line.rstrip().split(" ")
|
| 72 |
+
|
| 73 |
+
features = {"query_id": int(query_id),
|
| 74 |
+
"passage_id": passage_id,
|
| 75 |
+
"score": int(score)}
|
| 76 |
+
|
| 77 |
+
yield idx, features
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
def generate_examples_topics(filepath):
|
| 81 |
+
|
| 82 |
+
with open(filepath, encoding="utf-8") as input_file:
|
| 83 |
+
for (idx, line) in enumerate(input_file):
|
| 84 |
+
query_id, query = line.rstrip().split("\t")
|
| 85 |
+
|
| 86 |
+
features = {"query_id": int(query_id),
|
| 87 |
+
"query": query}
|
| 88 |
+
|
| 89 |
+
yield idx, features
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
class Quati(datasets.GeneratorBasedBuilder):
|
| 94 |
+
|
| 95 |
+
BUILDER_CONFIGS = (
|
| 96 |
+
[
|
| 97 |
+
datasets.BuilderConfig(
|
| 98 |
+
name="quati_10M_passages",
|
| 99 |
+
description="Portugues Brazilian passages, composing the complete Quati 10M dataset.",
|
| 100 |
+
version=datasets.Version("1.0.0"),
|
| 101 |
+
),
|
| 102 |
+
|
| 103 |
+
datasets.BuilderConfig(
|
| 104 |
+
name="quati_1M_passages",
|
| 105 |
+
description="Portugues Brazilian passages, composing the Quati 1M dataset.",
|
| 106 |
+
version=datasets.Version("1.0.0"),
|
| 107 |
+
),
|
| 108 |
+
|
| 109 |
+
datasets.BuilderConfig(
|
| 110 |
+
name="quati_10M_qrels",
|
| 111 |
+
description="Qrels for the annotated passages from the Quati 10M dataset.",
|
| 112 |
+
version=datasets.Version("1.0.0"),
|
| 113 |
+
),
|
| 114 |
+
|
| 115 |
+
datasets.BuilderConfig(
|
| 116 |
+
name="quati_1M_qrels",
|
| 117 |
+
description="Qrels for the annotated passages from the Quati 1M dataset.",
|
| 118 |
+
version=datasets.Version("1.0.0"),
|
| 119 |
+
),
|
| 120 |
+
|
| 121 |
+
datasets.BuilderConfig(
|
| 122 |
+
name="quati_test_topics",
|
| 123 |
+
description="50 test topics, corresponding to Quati dataset qrels.",
|
| 124 |
+
version=datasets.Version("1.0.0"),
|
| 125 |
+
),
|
| 126 |
+
|
| 127 |
+
datasets.BuilderConfig(
|
| 128 |
+
name="quati_all_topics",
|
| 129 |
+
description="All 200 topics created for the Quati dataset, including the 50 ones corresponding to Quati dataset qrels.",
|
| 130 |
+
version=datasets.Version("1.0.0"),
|
| 131 |
+
)
|
| 132 |
+
]
|
| 133 |
+
+ [
|
| 134 |
+
datasets.BuilderConfig(
|
| 135 |
+
name="quati_10M_passages_{}".format(which_part),
|
| 136 |
+
description="Portugues Brazilian passages, composing the Quati 10M dataset {}.".format(which_part),
|
| 137 |
+
version=datasets.Version("1.0.0"),
|
| 138 |
+
)
|
| 139 |
+
for which_part in QUATI_10M_DATASET_PARTS
|
| 140 |
+
]
|
| 141 |
+
)
|
| 142 |
+
|
| 143 |
+
DEFAULT_CONFIG_NAME = "quati_1M_passages"
|
| 144 |
+
|
| 145 |
+
|
| 146 |
+
def _info(self):
|
| 147 |
+
name = self.config.name
|
| 148 |
+
if "passages" in name:
|
| 149 |
+
features = {
|
| 150 |
+
"passage_id": datasets.Value("string"),
|
| 151 |
+
"passage": datasets.Value("string"),
|
| 152 |
+
}
|
| 153 |
+
elif name.endswith("qrels"):
|
| 154 |
+
features = {
|
| 155 |
+
"query_id": datasets.Value("int32"),
|
| 156 |
+
"passage_id": datasets.Value("string"),
|
| 157 |
+
"score": datasets.Value("int32"),
|
| 158 |
+
}
|
| 159 |
+
else:
|
| 160 |
+
features = {
|
| 161 |
+
"query_id": datasets.Value("int32"),
|
| 162 |
+
"query": datasets.Value("string"),
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
return datasets.DatasetInfo(
|
| 166 |
+
description=f"{_DESCRIPTION}\n{self.config.description}",
|
| 167 |
+
features=datasets.Features(features),
|
| 168 |
+
supervised_keys=None,
|
| 169 |
+
homepage=_URL,
|
| 170 |
+
citation=_CITATION,
|
| 171 |
+
)
|
| 172 |
+
|
| 173 |
+
|
| 174 |
+
def _split_generators(self, dl_manager):
|
| 175 |
+
"""Returns SplitGenerators."""
|
| 176 |
+
|
| 177 |
+
if self.config.name == "quati_10M_passages":
|
| 178 |
+
|
| 179 |
+
urls = {which_part: _URLS["quati_10M_passages_{}".format(which_part)] for which_part in QUATI_10M_DATASET_PARTS}
|
| 180 |
+
|
| 181 |
+
dl_path = dl_manager.download_and_extract(urls)
|
| 182 |
+
|
| 183 |
+
return [datasets.SplitGenerator(name="quati_10M_passages_{}".format(which_part), gen_kwargs={"filepath": dl_path[which_part]}) for which_part in QUATI_10M_DATASET_PARTS]
|
| 184 |
+
|
| 185 |
+
else:
|
| 186 |
+
url = _URLS[self.config.name]
|
| 187 |
+
dl_path = dl_manager.download_and_extract(url)
|
| 188 |
+
|
| 189 |
+
return (datasets.SplitGenerator(name=self.config.name, gen_kwargs={"filepath": dl_path}),)
|
| 190 |
+
|
| 191 |
+
|
| 192 |
+
def _generate_examples(self, filepath, args=None):
|
| 193 |
+
"""Yields examples."""
|
| 194 |
+
|
| 195 |
+
if "passages" in self.config.name:
|
| 196 |
+
return generate_examples_passages(filepath)
|
| 197 |
+
|
| 198 |
+
if self.config.name.endswith("qrels"):
|
| 199 |
+
return generate_examples_qrels(filepath)
|
| 200 |
+
|
| 201 |
+
else:
|
| 202 |
+
return generate_examples_topics(filepath)
|