File size: 9,687 Bytes
5f93979 8cd0988 5f93979 3efecce 5f93979 8cd0988 3efecce 5f93979 d5a2aed 5f93979 d5a2aed 5f93979 d5a2aed e825117 d5a2aed 5f93979 335151c 5f93979 d5a2aed 5f93979 |
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 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
# coding=utf-8
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Medical BIOS"""
import json
import os
import textwrap
import datasets
MAIN_CITATION = """NA"""
_DESCRIPTION = """NA"""
MAIN_PATH = 'https://huggingface.co/datasets/coastalcph/medical-bios/resolve/main'
class MedicalBIOSConfig(datasets.BuilderConfig):
"""BuilderConfig for Medical BIOS."""
def __init__(
self,
label_classes,
url,
data_url,
citation,
**kwargs,
):
"""BuilderConfig for Medical BIOS.
Args:
label_classes: `list`, list of label classes
url: `string`, url for the original project
data_url: `string`, url to download the zip file from
data_file: `string`, filename for data set
citation: `string`, citation for the data set
url: `string`, url for information about the data set
**kwargs: keyword arguments forwarded to super.
"""
super(MedicalBIOSConfig, self).__init__(version=datasets.Version("1.0.0", ""), **kwargs)
self.label_classes = label_classes
self.url = url
self.data_url = data_url
self.citation = citation
class XAIFairness(datasets.GeneratorBasedBuilder):
"""Fairlex: A multilingual benchmark for evaluating fairness in legal text processing. Version 1.0"""
BUILDER_CONFIGS = [
MedicalBIOSConfig(
name="standard",
description=textwrap.dedent(
"""\
The dataset is based on the Common Crawl. Specifically, De-Arteaga et al. identified online
biographies, written in English, by filtering for lines that began
with a name-like pattern (i.e., a sequence of two capitalized words)
followed by the string “is a(n) (xxx) title,” where title is
an occupation from the BLS Standard Occupation Classification system.
This version of the dataset comprises English biographies labeled with occupations.
We also include a subset of biographies labeled with human rationales.
"""
),
label_classes=['psychologist', 'surgeon', 'nurse', 'dentist', 'physician'],
data_url=os.path.join(MAIN_PATH, "bios.zip"),
url="https://github.com/microsoft/biosbias",
citation=textwrap.dedent(
"""\
@inproceedings{10.1145/3287560.3287572,
author = {De-Arteaga, Maria and Romanov, Alexey and Wallach, Hanna and Chayes,
Jennifer and Borgs, Christian and Chouldechova, Alexandra and Geyik, Sahin
and Kenthapadi, Krishnaram and Kalai, Adam Tauman},
title = {Bias in Bios: A Case Study of Semantic Representation Bias in a High-Stakes Setting},
year = {2019},
isbn = {9781450361255},
publisher = {Association for Computing Machinery},
address = {New York, NY, USA},
url = {https://doi.org/10.1145/3287560.3287572},
doi = {10.1145/3287560.3287572},
booktitle = {Proceedings of the Conference on Fairness, Accountability, and Transparency},
pages = {120–128},
numpages = {9},
location = {Atlanta, GA, USA},
series = {FAT* '19}
}"""
),
),
MedicalBIOSConfig(
name="rationales",
description=textwrap.dedent(
"""\
The dataset is based on the Common Crawl. Specifically, De-Arteaga et al. identified online
biographies, written in English, by filtering for lines that began
with a name-like pattern (i.e., a sequence of two capitalized words)
followed by the string “is a(n) (xxx) title,” where title is
an occupation from the BLS Standard Occupation Classification system.
This version of the dataset comprises English biographies labeled with occupations.
We also include a subset of biographies labeled with human rationales.
"""
),
label_classes=['psychologist', 'surgeon', 'nurse', 'dentist', 'physician'],
data_url=os.path.join(MAIN_PATH, "bios.zip"),
url="https://github.com/microsoft/biosbias",
citation=textwrap.dedent(
"""\
@inproceedings{10.1145/3287560.3287572,
author = {De-Arteaga, Maria and Romanov, Alexey and Wallach, Hanna and Chayes,
Jennifer and Borgs, Christian and Chouldechova, Alexandra and Geyik, Sahin
and Kenthapadi, Krishnaram and Kalai, Adam Tauman},
title = {Bias in Bios: A Case Study of Semantic Representation Bias in a High-Stakes Setting},
year = {2019},
isbn = {9781450361255},
publisher = {Association for Computing Machinery},
address = {New York, NY, USA},
url = {https://doi.org/10.1145/3287560.3287572},
doi = {10.1145/3287560.3287572},
booktitle = {Proceedings of the Conference on Fairness, Accountability, and Transparency},
pages = {120–128},
numpages = {9},
location = {Atlanta, GA, USA},
series = {FAT* '19}
}"""
),
),
]
def _info(self):
if self.config.name == "standard":
features = {"text": datasets.Value("string"), "label": datasets.ClassLabel(names=self.config.label_classes)}
else:
features = {"text": datasets.Value("string"), "label": datasets.ClassLabel(names=self.config.label_classes),
"foil": datasets.ClassLabel(names=self.config.label_classes),
"words": datasets.Sequence(datasets.Value("string")),
"rationales": datasets.Sequence(datasets.Value("int"))}
return datasets.DatasetInfo(
description=self.config.description,
features=datasets.Features(features),
homepage=self.config.url,
citation=self.config.citation + "\n" + MAIN_CITATION,
)
def _split_generators(self, dl_manager):
data_dir = dl_manager.download_and_extract(self.config.data_url)
if self.config.name == 'standard':
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
# These kwargs will be passed to _generate_examples
gen_kwargs={
"filepath": os.path.join(data_dir, f"train.jsonl"),
"split": "train",
},
),
datasets.SplitGenerator(
name=datasets.Split.TEST,
# These kwargs will be passed to _generate_examples
gen_kwargs={
"filepath": os.path.join(data_dir, "test.jsonl"),
"split": "test",
},
),
datasets.SplitGenerator(
name=datasets.Split.VALIDATION,
# These kwargs will be passed to _generate_examples
gen_kwargs={
"filepath": os.path.join(data_dir, f"validation.jsonl"),
"split": "val",
},
),
]
else:
return [
datasets.SplitGenerator(
name=datasets.Split.TEST,
# These kwargs will be passed to _generate_examples
gen_kwargs={
"filepath": os.path.join(data_dir, "test_rationales.jsonl"),
"split": "test",
},
),
]
def _generate_examples(self, filepath, split):
"""This function returns the examples in the raw (text) form."""
with open(filepath, encoding="utf-8") as f:
for id_, row in enumerate(f):
data = json.loads(row)
example = {
"text": data["text"],
"label": data["title"]
}
if self.config.name == "rationales":
example["foil"] = data["foil"]
example["words"] = data["words"]
example["rationales"] = data["rationales"]
example["contrastive_rationales"] = data["contrastive_rationales"]
yield id_, example |