Datasets:

Languages:
English
Multilinguality:
momolingual
Tags:
License:
File size: 5,984 Bytes
3d90d4b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
664a39b
32068ce
3d90d4b
32068ce
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3d90d4b
 
32068ce
 
3d90d4b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
from pathlib import Path
from typing import List

import datasets
import pandas as pd

from .bigbiohub import text_features
from .bigbiohub import BigBioConfig
from .bigbiohub import Tasks


_SOURCE_VIEW_NAME = "source"
_UNIFIED_VIEW_NAME = "bigbio"

_LANGUAGES = ["English"]
_PUBMED = True
_LOCAL = False
_CITATION = """\
@article{Bravo2015,
  doi = {10.1186/s12859-015-0472-9},
  url = {https://doi.org/10.1186/s12859-015-0472-9},
  year = {2015},
  month = feb,
  publisher = {Springer Science and Business Media {LLC}},
  volume = {16},
  number = {1},
  author = {{\`{A}}lex Bravo and Janet Pi{\~{n}}ero and N{\'{u}}ria Queralt-Rosinach and Michael Rautschka and Laura I Furlong},
  title = {Extraction of relations between genes and diseases from text and large-scale data analysis: implications for translational research},
  journal = {{BMC} Bioinformatics}
}
"""

_DESCRIPTION = """\
A corpus identifying associations between genes and diseases by a semi-automatic
annotation procedure based on the Genetic Association Database
"""

_DATASETNAME = "gad"
_DISPLAYNAME = "GAD"

_HOMEPAGE = "https://github.com/dmis-lab/biobert"  # This data source is used by the BLURB benchmark

_LICENSE = "CC_BY_4p0"

_SUPPORTED_TASKS = [Tasks.TEXT_CLASSIFICATION]

_SOURCE_VERSION = "1.0.0"
_BIGBIO_VERSION = "1.0.0"


class GAD(datasets.GeneratorBasedBuilder):
    """GAD is a weakly labeled dataset for Entity Relations (REL) task which is treated as a sentence classification task."""

    BUILDER_CONFIGS = [
        # 10-fold source schema
        BigBioConfig(
            name=f"gad_fold{i}_source",
            version=datasets.Version(_SOURCE_VERSION),
            description="GAD source schema",
            schema="source",
            subset_id=f"gad_fold{i}",
        )
        for i in range(10)
    ] + [
        # 10-fold bigbio schema
        BigBioConfig(
            name=f"gad_fold{i}_bigbio_text",
            version=datasets.Version(_BIGBIO_VERSION),
            description="GAD BigBio schema",
            schema="bigbio_text",
            subset_id=f"gad_fold{i}",
        )
        for i in range(10)
    ]

    # BLURB Benchmark config https://microsoft.github.io/BLURB/
    BUILDER_CONFIGS.append(
        BigBioConfig(
            name=f"gad_blurb_bigbio_text",
            version=datasets.Version(_BIGBIO_VERSION),
            description=f"GAD BLURB benchmark in simplified BigBio schema",
            schema="bigbio_text",
            subset_id=f"gad_blurb",
        )
    )

    DEFAULT_CONFIG_NAME = "gad_fold0_source"

    def _info(self):
        if self.config.schema == "source":
            features = datasets.Features(
                {
                    "index": datasets.Value("string"),
                    "sentence": datasets.Value("string"),
                    "label": datasets.Value("int32"),
                }
            )
        elif self.config.schema == "bigbio_text":
            features = text_features

        return datasets.DatasetInfo(
            description=_DESCRIPTION,
            features=features,
            homepage=_HOMEPAGE,
            license=str(_LICENSE),
            citation=_CITATION,
        )

    def _split_generators(
        self, dl_manager: datasets.DownloadManager
    ) -> List[datasets.SplitGenerator]:

        data_dir = Path(dl_manager.download_and_extract("data/REdata.zip"))

        if "blurb" in self.config.name:
            data_files = {
                "train": data_dir / "GAD" / "blurb" / "train.tsv",
                "validation": data_dir / "GAD" / "blurb" / "dev.tsv",
                "test": data_dir / "GAD" / "blurb" / "test.tsv",
            }

            return [
                datasets.SplitGenerator(
                    name=datasets.Split.TRAIN,
                    gen_kwargs={"filepath": data_files["train"]},
                ),
                datasets.SplitGenerator(
                    name=datasets.Split.VALIDATION,
                    gen_kwargs={"filepath": data_files["validation"]},
                ),
                datasets.SplitGenerator(
                    name=datasets.Split.TEST,
                    gen_kwargs={"filepath": data_files["test"]},
                ),
            ]

        else:

            fold_id = int(self.config.subset_id.split("_fold")[1][0]) + 1

            data_files = {
                "train": data_dir / "GAD" / str(fold_id) / "train.tsv",
                "test": data_dir / "GAD" / str(fold_id) / "test.tsv",
            }

            return [
                datasets.SplitGenerator(
                    name=datasets.Split.TRAIN,
                    gen_kwargs={"filepath": data_files["train"]},
                ),
                datasets.SplitGenerator(
                    name=datasets.Split.TEST,
                    gen_kwargs={"filepath": data_files["test"]},
                ),
            ]

    def _generate_examples(self, filepath: Path):
        # train files in non-blurb splits don't have headers for some reason
        if "train.tsv" in str(filepath) and "blurb" not in self.config.name:
            df = pd.read_csv(filepath, sep="\t", header=None).reset_index()
        else:
            df = pd.read_csv(filepath, sep="\t")
        df.columns = ["id", "sentence", "label"]

        if self.config.schema == "source":
            for id, row in enumerate(df.itertuples()):
                ex = {
                    "index": row.id,
                    "sentence": row.sentence,
                    "label": int(row.label),
                }
                yield id, ex
        elif self.config.schema == "bigbio_text":
            for id, row in enumerate(df.itertuples()):
                ex = {
                    "id": id,
                    "document_id": row.id,
                    "text": row.sentence,
                    "labels": [str(row.label)],
                }
                yield id, ex
        else:
            raise ValueError(f"Invalid config: {self.config.name}")