Datasets:
Tasks:
Text Classification
Formats:
parquet
Sub-tasks:
multi-label-classification
Languages:
English
Size:
100K - 1M
License:
Commit
•
aa266b8
1
Parent(s):
ef16cee
Delete loading script
Browse files- ohsumed.py +0 -225
ohsumed.py
DELETED
@@ -1,225 +0,0 @@
|
|
1 |
-
# coding=utf-8
|
2 |
-
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
|
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 |
-
"""OHSUMED: An Interactive Retrieval Evaluation and New Large Test Collection for Research."""
|
16 |
-
|
17 |
-
|
18 |
-
import datasets
|
19 |
-
|
20 |
-
|
21 |
-
# TODO: Add BibTeX citation
|
22 |
-
# Find for instance the citation on arxiv or on the dataset repo/website
|
23 |
-
_CITATION = """\
|
24 |
-
@InProceedings{10.1007/978-1-4471-2099-5_20,
|
25 |
-
author="Hersh, William
|
26 |
-
and Buckley, Chris
|
27 |
-
and Leone, T. J.
|
28 |
-
and Hickam, David",
|
29 |
-
editor="Croft, Bruce W.
|
30 |
-
and van Rijsbergen, C. J.",
|
31 |
-
title="OHSUMED: An Interactive Retrieval Evaluation and New Large Test Collection for Research",
|
32 |
-
booktitle="SIGIR '94",
|
33 |
-
year="1994",
|
34 |
-
publisher="Springer London",
|
35 |
-
address="London",
|
36 |
-
pages="192--201",
|
37 |
-
abstract="A series of information retrieval experiments was carried out with a computer installed in a medical practice setting for relatively inexperienced physician end-users. Using a commercial MEDLINE product based on the vector space model, these physicians searched just as effectively as more experienced searchers using Boolean searching. The results of this experiment were subsequently used to create a new large medical test collection, which was used in experiments with the SMART retrieval system to obtain baseline performance data as well as compare SMART with the other searchers.",
|
38 |
-
isbn="978-1-4471-2099-5"
|
39 |
-
}
|
40 |
-
"""
|
41 |
-
|
42 |
-
# TODO: Add description of the dataset here
|
43 |
-
# You can copy an official description
|
44 |
-
_DESCRIPTION = """\
|
45 |
-
The OHSUMED test collection is a set of 348,566 references from
|
46 |
-
MEDLINE, the on-line medical information database, consisting of
|
47 |
-
titles and/or abstracts from 270 medical journals over a five-year
|
48 |
-
period (1987-1991). The available fields are title, abstract, MeSH
|
49 |
-
indexing terms, author, source, and publication type.
|
50 |
-
"""
|
51 |
-
|
52 |
-
# TODO: Add a link to an official homepage for the dataset here
|
53 |
-
_HOMEPAGE = "http://davis.wpi.edu/xmdv/datasets/ohsumed.html"
|
54 |
-
|
55 |
-
# TODO: Add the licence for the dataset here if you can find it
|
56 |
-
_LICENSE = "CC BY-NC 4.0"
|
57 |
-
|
58 |
-
# TODO: Add link to the official dataset URLs here
|
59 |
-
# The HuggingFace dataset library don't host the datasets but only point to the original files
|
60 |
-
# This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
|
61 |
-
_URLs = {"ohsumed": "https://trec.nist.gov/data/filtering/t9.filtering.tar.gz"}
|
62 |
-
|
63 |
-
|
64 |
-
# TODO: Name of the dataset usually match the script name with CamelCase instead of snake_case
|
65 |
-
class Ohsumed(datasets.GeneratorBasedBuilder):
|
66 |
-
"""OHSUMED: An Interactive Retrieval Evaluation and New Large Test Collection for Research."""
|
67 |
-
|
68 |
-
VERSION = datasets.Version("1.1.0")
|
69 |
-
|
70 |
-
# This is an example of a dataset with multiple configurations.
|
71 |
-
# If you don't want/need to define several sub-sets in your dataset,
|
72 |
-
# just remove the BUILDER_CONFIG_CLASS and the BUILDER_CONFIGS attributes.
|
73 |
-
|
74 |
-
# If you need to make complex sub-parts in the datasets with configurable options
|
75 |
-
# You can create your own builder configuration class to store attribute, inheriting from datasets.BuilderConfig
|
76 |
-
# BUILDER_CONFIG_CLASS = MyBuilderConfig
|
77 |
-
|
78 |
-
# You will be able to load one or the other configurations in the following list with
|
79 |
-
# data = datasets.load_dataset('my_dataset', 'first_domain')
|
80 |
-
# data = datasets.load_dataset('my_dataset', 'second_domain')
|
81 |
-
BUILDER_CONFIGS = [
|
82 |
-
datasets.BuilderConfig(
|
83 |
-
name="ohsumed",
|
84 |
-
version=VERSION,
|
85 |
-
description="Config for the entire ohsumed dataset. An Interactive Retrieval Evaluation and New Large Test Collection for Research",
|
86 |
-
)
|
87 |
-
]
|
88 |
-
|
89 |
-
def _info(self):
|
90 |
-
# TODO: This method specifies the datasets.DatasetInfo object which contains informations and typings for the dataset
|
91 |
-
features = datasets.Features(
|
92 |
-
{
|
93 |
-
"seq_id": datasets.Value("int64"),
|
94 |
-
"medline_ui": datasets.Value("int64"),
|
95 |
-
"mesh_terms": datasets.Value("string"),
|
96 |
-
"title": datasets.Value("string"),
|
97 |
-
"publication_type": datasets.Value("string"),
|
98 |
-
"abstract": datasets.Value("string"),
|
99 |
-
"author": datasets.Value("string"),
|
100 |
-
"source": datasets.Value("string"),
|
101 |
-
}
|
102 |
-
)
|
103 |
-
return datasets.DatasetInfo(
|
104 |
-
# This is the description that will appear on the datasets page.
|
105 |
-
description=_DESCRIPTION,
|
106 |
-
# This defines the different columns of the dataset and their types
|
107 |
-
features=features, # Here we define them above because they are different between the two configurations
|
108 |
-
# If there's a common (input, target) tuple from the features,
|
109 |
-
# specify them here. They'll be used if as_supervised=True in
|
110 |
-
# builder.as_dataset.
|
111 |
-
supervised_keys=None,
|
112 |
-
# Homepage of the dataset for documentation
|
113 |
-
homepage=_HOMEPAGE,
|
114 |
-
# License for the dataset if available
|
115 |
-
license=_LICENSE,
|
116 |
-
# Citation for the dataset
|
117 |
-
citation=_CITATION,
|
118 |
-
)
|
119 |
-
|
120 |
-
def _split_generators(self, dl_manager):
|
121 |
-
"""Returns SplitGenerators."""
|
122 |
-
# TODO: This method is tasked with downloading/extracting the data and defining the splits depending on the configuration
|
123 |
-
# If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name
|
124 |
-
|
125 |
-
# dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLs
|
126 |
-
# It can accept any type or nested list/dict and will give back the same structure with the url replaced with path to local files.
|
127 |
-
# By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
|
128 |
-
my_urls = _URLs[self.config.name]
|
129 |
-
archive = dl_manager.download(my_urls)
|
130 |
-
return [
|
131 |
-
datasets.SplitGenerator(
|
132 |
-
name=datasets.Split.TRAIN,
|
133 |
-
# These kwargs will be passed to _generate_examples
|
134 |
-
gen_kwargs={
|
135 |
-
"filepath": "ohsu-trec/trec9-train/ohsumed.87",
|
136 |
-
"files": dl_manager.iter_archive(archive),
|
137 |
-
},
|
138 |
-
),
|
139 |
-
datasets.SplitGenerator(
|
140 |
-
name=datasets.Split.TEST,
|
141 |
-
# These kwargs will be passed to _generate_examples
|
142 |
-
gen_kwargs={
|
143 |
-
"filepath": "ohsu-trec/trec9-test/ohsumed.88-91",
|
144 |
-
"files": dl_manager.iter_archive(archive),
|
145 |
-
},
|
146 |
-
),
|
147 |
-
]
|
148 |
-
|
149 |
-
def _generate_examples(self, filepath, files):
|
150 |
-
"""Yields examples."""
|
151 |
-
# TODO: This method will receive as arguments the `gen_kwargs` defined in the previous `_split_generators` method.
|
152 |
-
# It is in charge of opening the given file and yielding (key, example) tuples from the dataset
|
153 |
-
# The key is not important, it's more here for legacy reason (legacy from tfds)
|
154 |
-
|
155 |
-
def ohsumed_dict():
|
156 |
-
"""Returns a dict."""
|
157 |
-
|
158 |
-
data = {
|
159 |
-
"seq_id": -1,
|
160 |
-
"medline_ui": -1,
|
161 |
-
"mesh_terms": "",
|
162 |
-
"title": "",
|
163 |
-
"publication_type": "",
|
164 |
-
"abstract": "",
|
165 |
-
"author": "",
|
166 |
-
"source": "",
|
167 |
-
}
|
168 |
-
|
169 |
-
return data
|
170 |
-
|
171 |
-
tag = ""
|
172 |
-
column_map = {
|
173 |
-
".I": "seq_id",
|
174 |
-
".U": "medline_ui",
|
175 |
-
".M": "mesh_terms",
|
176 |
-
".T": "title",
|
177 |
-
".P": "publication_type",
|
178 |
-
".W": "abstract",
|
179 |
-
".A": "author",
|
180 |
-
".S": "source",
|
181 |
-
}
|
182 |
-
|
183 |
-
for path, f in files:
|
184 |
-
if path == filepath:
|
185 |
-
data = ohsumed_dict()
|
186 |
-
|
187 |
-
for line in f.readlines():
|
188 |
-
line = line.decode("utf-8").strip()
|
189 |
-
|
190 |
-
if line.startswith(".I"):
|
191 |
-
tag = ".I"
|
192 |
-
if data["medline_ui"] != -1:
|
193 |
-
id_ = data["seq_id"] + "_" + data["medline_ui"]
|
194 |
-
yield id_, {
|
195 |
-
"seq_id": data["seq_id"],
|
196 |
-
"medline_ui": data["medline_ui"],
|
197 |
-
"mesh_terms": str(data["mesh_terms"]),
|
198 |
-
"title": str(data["title"]),
|
199 |
-
"publication_type": str(data["publication_type"]),
|
200 |
-
"abstract": str(data["abstract"]),
|
201 |
-
"author": str(data["author"]),
|
202 |
-
"source": str(data["source"]),
|
203 |
-
}
|
204 |
-
else:
|
205 |
-
data = ohsumed_dict()
|
206 |
-
line = line.replace(".I", "").strip()
|
207 |
-
data["seq_id"] = line
|
208 |
-
elif tag and not line.startswith("."):
|
209 |
-
key = column_map[tag]
|
210 |
-
data[key] = line
|
211 |
-
elif ".U" in line:
|
212 |
-
tag = ".U"
|
213 |
-
elif ".M" in line:
|
214 |
-
tag = ".M"
|
215 |
-
elif ".T" in line:
|
216 |
-
tag = ".T"
|
217 |
-
elif ".P" in line:
|
218 |
-
tag = ".P"
|
219 |
-
elif ".W" in line:
|
220 |
-
tag = ".W"
|
221 |
-
elif ".A" in line:
|
222 |
-
tag = ".A"
|
223 |
-
elif ".S" in line:
|
224 |
-
tag = ".S"
|
225 |
-
break
|
|
|
|
|
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