Datasets:

Languages:
English
ArXiv:
License:
kiddothe2b commited on
Commit
d5a2aed
1 Parent(s): 3efecce

Update medical-bios.py

Browse files
Files changed (1) hide show
  1. medical-bios.py +83 -45
medical-bios.py CHANGED
@@ -95,14 +95,53 @@ class XAIFairness(datasets.GeneratorBasedBuilder):
95
  }"""
96
  ),
97
  ),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
98
  ]
99
 
100
  def _info(self):
101
- features = {"text": datasets.Value("string"), "label": datasets.ClassLabel(names=self.config.label_classes),
102
- "foil": datasets.ClassLabel(names=self.config.label_classes),
103
- "words": datasets.Sequence(datasets.Value("string")),
104
- "rationales": datasets.Sequence(datasets.Value("int")),
105
- "contrastive_rationales": datasets.Sequence(datasets.Value("int"))}
 
 
106
  return datasets.DatasetInfo(
107
  description=self.config.description,
108
  features=datasets.Features(features),
@@ -112,40 +151,44 @@ class XAIFairness(datasets.GeneratorBasedBuilder):
112
 
113
  def _split_generators(self, dl_manager):
114
  data_dir = dl_manager.download_and_extract(self.config.data_url)
115
- return [
116
- datasets.SplitGenerator(
117
- name=datasets.Split.TRAIN,
118
- # These kwargs will be passed to _generate_examples
119
- gen_kwargs={
120
- "filepath": os.path.join(data_dir, f"train.jsonl"),
121
- "split": "train",
122
- },
123
- ),
124
- datasets.SplitGenerator(
125
- name=datasets.Split.TEST,
126
- # These kwargs will be passed to _generate_examples
127
- gen_kwargs={
128
- "filepath": os.path.join(data_dir, "test.jsonl"),
129
- "split": "test",
130
- },
131
- ),
132
- datasets.SplitGenerator(
133
- name=datasets.Split.VALIDATION,
134
- # These kwargs will be passed to _generate_examples
135
- gen_kwargs={
136
- "filepath": os.path.join(data_dir, f"validation.jsonl"),
137
- "split": "val",
138
- },
139
- ),
140
- datasets.SplitGenerator(
141
- name="test-extra",
142
- # These kwargs will be passed to _generate_examples
143
- gen_kwargs={
144
- "filepath": os.path.join(data_dir, f"test_extra.jsonl"),
145
- "split": "test-extra",
146
- },
147
- ),
148
- ]
 
 
 
 
149
 
150
  def _generate_examples(self, filepath, split):
151
  """This function returns the examples in the raw (text) form."""
@@ -156,14 +199,9 @@ class XAIFairness(datasets.GeneratorBasedBuilder):
156
  "text": data["text"],
157
  "label": data[self.config.label_column]
158
  }
159
- if split != "test-extra":
160
  example["foil"] = data["foil"]
161
  example["words"] = data["words"]
162
  example["rationales"] = data["rationales"]
163
  example["contrastive_rationales"] = data["contrastive_rationales"]
164
- else:
165
- example["foil"] = 'N/A'
166
- example["words"] = ['N/A']
167
- example["rationales"] = [0]
168
- example["contrastive_rationales"] = [0]
169
  yield id_, example
 
95
  }"""
96
  ),
97
  ),
98
+ MedicalBIOSConfig(
99
+ name="rationales",
100
+ description=textwrap.dedent(
101
+ """\
102
+ The dataset is based on the Common Crawl. Specifically, De-Arteaga et al. identified online
103
+ biographies, written in English, by filtering for lines that began
104
+ with a name-like pattern (i.e., a sequence of two capitalized words)
105
+ followed by the string “is a(n) (xxx) title,” where title is
106
+ an occupation from the BLS Standard Occupation Classification system.
107
+ This version of the dataset comprises English biographies labeled with occupations.
108
+ We also include a subset of biographies labeled with human rationales.
109
+ """
110
+ ),
111
+ label_classes=['psychologist', 'surgeon', 'nurse', 'dentist', 'physician'],
112
+ data_url=os.path.join(MAIN_PATH, "bios.zip"),
113
+ url="https://github.com/microsoft/biosbias",
114
+ citation=textwrap.dedent(
115
+ """\
116
+ @inproceedings{10.1145/3287560.3287572,
117
+ author = {De-Arteaga, Maria and Romanov, Alexey and Wallach, Hanna and Chayes,
118
+ Jennifer and Borgs, Christian and Chouldechova, Alexandra and Geyik, Sahin
119
+ and Kenthapadi, Krishnaram and Kalai, Adam Tauman},
120
+ title = {Bias in Bios: A Case Study of Semantic Representation Bias in a High-Stakes Setting},
121
+ year = {2019},
122
+ isbn = {9781450361255},
123
+ publisher = {Association for Computing Machinery},
124
+ address = {New York, NY, USA},
125
+ url = {https://doi.org/10.1145/3287560.3287572},
126
+ doi = {10.1145/3287560.3287572},
127
+ booktitle = {Proceedings of the Conference on Fairness, Accountability, and Transparency},
128
+ pages = {120–128},
129
+ numpages = {9},
130
+ location = {Atlanta, GA, USA},
131
+ series = {FAT* '19}
132
+ }"""
133
+ ),
134
+ ),
135
  ]
136
 
137
  def _info(self):
138
+ if self.config.name == "standard":
139
+ features = {"text": datasets.Value("string"), "label": datasets.ClassLabel(names=self.config.label_classes)}
140
+ else:
141
+ features = {"text": datasets.Value("string"), "label": datasets.ClassLabel(names=self.config.label_classes),
142
+ "foil": datasets.ClassLabel(names=self.config.label_classes),
143
+ "words": datasets.Sequence(datasets.Value("string")),
144
+ "rationales": datasets.Sequence(datasets.Value("int"))}
145
  return datasets.DatasetInfo(
146
  description=self.config.description,
147
  features=datasets.Features(features),
 
151
 
152
  def _split_generators(self, dl_manager):
153
  data_dir = dl_manager.download_and_extract(self.config.data_url)
154
+ if self.config.name == 'standard':
155
+ return [
156
+ datasets.SplitGenerator(
157
+ name=datasets.Split.TRAIN,
158
+ # These kwargs will be passed to _generate_examples
159
+ gen_kwargs={
160
+ "filepath": os.path.join(data_dir, f"train.jsonl"),
161
+ "split": "train",
162
+ },
163
+ ),
164
+ datasets.SplitGenerator(
165
+ name=datasets.Split.TEST,
166
+ # These kwargs will be passed to _generate_examples
167
+ gen_kwargs={
168
+ "filepath": os.path.join(data_dir, "test.jsonl"),
169
+ "split": "test",
170
+ },
171
+ ),
172
+ datasets.SplitGenerator(
173
+ name=datasets.Split.VALIDATION,
174
+ # These kwargs will be passed to _generate_examples
175
+ gen_kwargs={
176
+ "filepath": os.path.join(data_dir, f"validation.jsonl"),
177
+ "split": "val",
178
+ },
179
+ ),
180
+ ]
181
+ else:
182
+ return [
183
+ datasets.SplitGenerator(
184
+ name=datasets.Split.TEST,
185
+ # These kwargs will be passed to _generate_examples
186
+ gen_kwargs={
187
+ "filepath": os.path.join(data_dir, "test.jsonl"),
188
+ "split": "test",
189
+ },
190
+ ),
191
+ ]
192
 
193
  def _generate_examples(self, filepath, split):
194
  """This function returns the examples in the raw (text) form."""
 
199
  "text": data["text"],
200
  "label": data[self.config.label_column]
201
  }
202
+ if self.config.name == "rationales":
203
  example["foil"] = data["foil"]
204
  example["words"] = data["words"]
205
  example["rationales"] = data["rationales"]
206
  example["contrastive_rationales"] = data["contrastive_rationales"]
 
 
 
 
 
207
  yield id_, example