Datasets:
Upload folder using huggingface_hub
Browse files- README.md +83 -0
- medqa_corpus_en.py +207 -0
README.md
ADDED
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
annotations_creators: []
|
2 |
+
language:
|
3 |
+
- en
|
4 |
+
language_creators:
|
5 |
+
- found
|
6 |
+
- other
|
7 |
+
license:
|
8 |
+
- mit
|
9 |
+
multilinguality:
|
10 |
+
- monolingual
|
11 |
+
pretty_name: MedQA Textbook (English) Corpus
|
12 |
+
size_categories:
|
13 |
+
- 10K<n<100K
|
14 |
+
source_datasets:
|
15 |
+
- extended|medmcqa
|
16 |
+
tags:
|
17 |
+
- medical
|
18 |
+
- clinical medicine
|
19 |
+
- biology
|
20 |
+
task_categories:
|
21 |
+
- text-generation
|
22 |
+
task_ids:
|
23 |
+
- language-modeling
|
24 |
+
|
25 |
+
# Dataset Card for MedQA English Textbooks
|
26 |
+
|
27 |
+
## Table of Contents
|
28 |
+
- [Dataset Description](#dataset-description)
|
29 |
+
- [Dataset Summary](#dataset-summary)
|
30 |
+
- [Languages](#languages)
|
31 |
+
- [Dataset Structure](#dataset-structure)
|
32 |
+
- [Data Instances](#data-instances)
|
33 |
+
- [Dataset Creation](#dataset-creation)
|
34 |
+
- [Curation Rationale](#curation-rationale)
|
35 |
+
- [Source Data](#source-data)
|
36 |
+
- [Annotations](#annotations)
|
37 |
+
- [Personal and Sensitive Information](#personal-and-sensitive-information)
|
38 |
+
- [Considerations for Using the Data](#considerations-for-using-the-data)
|
39 |
+
- [Social Impact of Dataset](#social-impact-of-dataset)
|
40 |
+
- [Discussion of Biases](#discussion-of-biases)
|
41 |
+
- [Other Known Limitations](#other-known-limitations)
|
42 |
+
- [Additional Information](#additional-information)
|
43 |
+
- [Dataset Curators](#dataset-curators)
|
44 |
+
- [Licensing Information](#licensing-information)
|
45 |
+
- [Citation Information](#citation-information)
|
46 |
+
|
47 |
+
## Dataset Description
|
48 |
+
|
49 |
+
### Dataset Summary
|
50 |
+
|
51 |
+
MedQA Textbook (English) with focused emphasis on domain of Clinical Medicine and other subsets relevant for use with
|
52 |
+
training medical LLMs with gold standard domain text.
|
53 |
+
|
54 |
+
### Languages
|
55 |
+
|
56 |
+
English
|
57 |
+
|
58 |
+
## Dataset Structure
|
59 |
+
|
60 |
+
### Data Instances
|
61 |
+
|
62 |
+
```json
|
63 |
+
{"text": "The manifestations of acute intestinal obstruction depend on the nature of the underlying disease process, its location, and changes in blood flow (Fig. 355-1). Increased intestinal contractility, which occurs proximally and distal to the obstruction, is a characteristic response. Subsequently, intestinal peristalsis slows as the intestine or stomach proximal to the point of obstruction dilates and fills with gastrointestinal secretions and swallowed air. Although swallowed air is the primary contributor to intestinal distension, intraluminal air may also accumulate from fermentation, local carbon dioxide production, and altered gaseous diffusion. Intraluminal dilation also increases intraluminal pressure. When luminal pressure exceeds venous pressure, venous and lymphatic drainage is impeded. Edema ensues, and the bowel wall proximal to the site of blockage may become hypoxemic. Epithelial necrosis can be identified within 12 h of obstruction. Ultimately, arterial blood supply may become so compromised that full-thickness ischemia, necrosis, and perforation result. Stasis increases the bacteria counts within the jejunum and ileum. The most commonly cultured intraluminal organisms are Escherichia coli, Streptococcus faecalis, and Klebsiella, which may also be recovered from mesenteric lymph nodes and other more distant sites.",
|
64 |
+
"source": "textbooks/en/InternalMed_Harrison.txt"}
|
65 |
+
```
|
66 |
+
## Dataset Creation
|
67 |
+
|
68 |
+
### Curation Rationale
|
69 |
+
|
70 |
+
The MedQA dataset includes raw text corpus that is excluded from most of the datasets derived and the raw text is
|
71 |
+
valuable for pre-training of medical LLMS
|
72 |
+
|
73 |
+
### Source Data
|
74 |
+
|
75 |
+
#### Initial Data Collection and Normalization
|
76 |
+
|
77 |
+
Langchain's RecursiveCharacterTextSplitter is used for chunking and the most commonly-appearing non-ASCII characters
|
78 |
+
are replaced with readable equivalents. The texts are then broken into separate subsets:
|
79 |
+
|
80 |
+
- Core Clinical Medicine
|
81 |
+
- Basic Biology
|
82 |
+
- Pharmacology
|
83 |
+
- Psychiatry
|
medqa_corpus_en.py
ADDED
@@ -0,0 +1,207 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
|
2 |
+
#
|
3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4 |
+
# you may not use this file except in compliance with the License.
|
5 |
+
# You may obtain a copy of the License at
|
6 |
+
#
|
7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8 |
+
#
|
9 |
+
# Unless required by applicable law or agreed to in writing, software
|
10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12 |
+
# See the License for the specific language governing permissions and
|
13 |
+
# limitations under the License.
|
14 |
+
"""
|
15 |
+
MedQA Textbook (English) with focused emphasis on domain of Clinical Medicine and other subsets relevant for use with
|
16 |
+
Clinical Ontologies.
|
17 |
+
|
18 |
+
Textbooks:
|
19 |
+
|
20 |
+
Anatomy_Gray.txt Clinical medicine
|
21 |
+
Biochemistry_Lippincott.txt Basic biology
|
22 |
+
Cell_Biology_Alberts.txt Basic biology
|
23 |
+
First_Aid_Step1.txt Clinical medicine
|
24 |
+
First_Aid_Step2.txt Clinical medicine
|
25 |
+
Gynecology_Novak.txt Clinical medicine
|
26 |
+
Histology_Ross.txt Basic biology
|
27 |
+
Immunology_Janeway.txt Allergy and immunology Clinical medicine
|
28 |
+
InternalMed_Harrison.txt Clinical medicine
|
29 |
+
Neurology_Adams.txt Neurology Clinical medicine
|
30 |
+
Obstentrics_Williams.txt OBGYN Clinical medicine
|
31 |
+
Pathology_Robbins.txt Basic biology
|
32 |
+
Pathoma_Husain.txt Pathology Clinical medicine
|
33 |
+
Pediatrics_Nelson.txt Pediatrics Clinical medicine
|
34 |
+
Pharmacology_Katzung.txt Pharmacology
|
35 |
+
Physiology_Levy.txt Basic biology
|
36 |
+
Psichiatry_DSM-5.txt Psychiatry
|
37 |
+
Surgery_Schwartz.txt Surgery Clinical medicine
|
38 |
+
|
39 |
+
"""
|
40 |
+
|
41 |
+
SUBJECT_SUBSETS = {
|
42 |
+
"core_clinical":
|
43 |
+
["Anatomy_Gray.txt", "First_Aid_Step1.txt", "First_Aid_Step2.txt", "Immunology_Janeway.txt",
|
44 |
+
"InternalMed_Harrison.txt", "Neurology_Adams.txt", "Obstentrics_Williams.txt", "Pathoma_Husain.txt",
|
45 |
+
"Pediatrics_Nelson.txt", "Surgery_Schwartz.txt"],
|
46 |
+
"basic_biology":
|
47 |
+
["Biochemistry_Lippincott.txt", "Cell_Biology_Alberts.txt", "Histology_Ross.txt", "Pathology_Robbins.txt",
|
48 |
+
"Physiology_Levy.txt"],
|
49 |
+
"pharmacology":
|
50 |
+
["Pharmacology_Katzung.txt"],
|
51 |
+
"psychiatry":
|
52 |
+
["Psichiatry_DSM-5.txt"]
|
53 |
+
}
|
54 |
+
|
55 |
+
from pathlib import Path
|
56 |
+
try:
|
57 |
+
from ogbujipt.text_helper import text_splitter
|
58 |
+
except ImportError as e:
|
59 |
+
raise ImportError("Need ogbujipt installed. Try: pip install ogbujipt")
|
60 |
+
import datasets
|
61 |
+
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
62 |
+
|
63 |
+
CHUNK_OVERLAP = 20
|
64 |
+
MAX_CHUNK_SIZE = 800
|
65 |
+
|
66 |
+
# TODO: Add description of the dataset here
|
67 |
+
# You can copy an official description
|
68 |
+
_DESCRIPTION = """\
|
69 |
+
MedQA Textbook (English) with emphasis on domain of Clinical Medicine and other subsets.
|
70 |
+
"""
|
71 |
+
|
72 |
+
# TODO: Add a link to an official homepage for the dataset here
|
73 |
+
_HOMEPAGE = "https://github.com/jind11/MedQA"
|
74 |
+
|
75 |
+
# TODO: Add the licence for the dataset here if you can find it
|
76 |
+
_LICENSE = """
|
77 |
+
MIT License
|
78 |
+
|
79 |
+
Copyright (c) 2022 Di Jin
|
80 |
+
|
81 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
82 |
+
of this software and associated documentation files (the "Software"), to deal
|
83 |
+
in the Software without restriction, including without limitation the rights
|
84 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
85 |
+
copies of the Software, and to permit persons to whom the Software is
|
86 |
+
furnished to do so, subject to the following conditions:
|
87 |
+
|
88 |
+
The above copyright notice and this permission notice shall be included in all
|
89 |
+
copies or substantial portions of the Software.
|
90 |
+
|
91 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
92 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
93 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
94 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
95 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
96 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
97 |
+
SOFTWARE.
|
98 |
+
"""
|
99 |
+
|
100 |
+
_URLS = [
|
101 |
+
"https://huggingface.co/datasets/bigbio/med_qa/resolve/main/data_clean.zip?download=true"
|
102 |
+
]
|
103 |
+
|
104 |
+
_CITATION = """\
|
105 |
+
@article{jin2021disease,
|
106 |
+
title={What disease does this patient have? a large-scale open domain question answering dataset from medical exams},
|
107 |
+
author={Jin, Di and Pan, Eileen and Oufattole, Nassim and Weng, Wei-Hung and Fang, Hanyi and Szolovits, Peter},
|
108 |
+
journal={Applied Sciences},
|
109 |
+
volume={11},
|
110 |
+
number={14},
|
111 |
+
pages={6421},
|
112 |
+
year={2021},
|
113 |
+
publisher={MDPI}
|
114 |
+
}
|
115 |
+
"""
|
116 |
+
|
117 |
+
REPL_MAP = {
|
118 |
+
'\n': ' ',
|
119 |
+
'\u2019': "'",
|
120 |
+
'\u2013': '/',
|
121 |
+
'\ufb02': 'fl',
|
122 |
+
'\u2014': ' - ',
|
123 |
+
'\u201c': "'",
|
124 |
+
'\u2003': ' ',
|
125 |
+
'\u201d': "'",
|
126 |
+
'\u2193': 'decreased',
|
127 |
+
}
|
128 |
+
|
129 |
+
|
130 |
+
def recursive_replace(text, items=None):
|
131 |
+
items = items if items is not None else list(REPL_MAP.items())
|
132 |
+
if items:
|
133 |
+
old, new = items[0]
|
134 |
+
return recursive_replace(text.replace(old, new), items[1:])
|
135 |
+
else:
|
136 |
+
return text
|
137 |
+
|
138 |
+
|
139 |
+
def proportion_of_ascii_characters(string):
|
140 |
+
# Count the number of ASCII characters in the string.
|
141 |
+
num_ascii_characters = 0
|
142 |
+
for character in string:
|
143 |
+
if ord(character) < 128:
|
144 |
+
num_ascii_characters += 1
|
145 |
+
|
146 |
+
# Calculate the proportion of ASCII characters in the string.
|
147 |
+
prop = num_ascii_characters / len(string)
|
148 |
+
|
149 |
+
return prop
|
150 |
+
|
151 |
+
|
152 |
+
def get_med_qa_textbooks(location, subset_name):
|
153 |
+
for textbook_content in location.glob('*.txt'):
|
154 |
+
if textbook_content.name in SUBJECT_SUBSETS[subset_name]:
|
155 |
+
r_splitter = RecursiveCharacterTextSplitter(
|
156 |
+
chunk_size=MAX_CHUNK_SIZE,
|
157 |
+
chunk_overlap=CHUNK_OVERLAP,
|
158 |
+
separators=["\n", " ", ". ", ""]
|
159 |
+
)
|
160 |
+
for chunk in r_splitter.split_text(textbook_content.open(encoding='utf-8').read()):
|
161 |
+
chunk = recursive_replace(chunk)
|
162 |
+
if proportion_of_ascii_characters(chunk) >= .9:
|
163 |
+
yield {"text": chunk, "source": str(textbook_content)}
|
164 |
+
|
165 |
+
|
166 |
+
# TODO: Name of the dataset usually matches the script name with CamelCase instead of snake_case
|
167 |
+
class MedQACorpus(datasets.GeneratorBasedBuilder):
|
168 |
+
"""MedQA Textbook (English) with emphasis on domain of Clinical Medicine and other subsets."""
|
169 |
+
|
170 |
+
VERSION = datasets.Version("0.0.1")
|
171 |
+
|
172 |
+
BUILDER_CONFIGS = [
|
173 |
+
datasets.BuilderConfig(name="core_clinical", version=VERSION, description="Core clinical medicine"),
|
174 |
+
datasets.BuilderConfig(name="basic_biology", version=VERSION, description="Basic biology"),
|
175 |
+
datasets.BuilderConfig(name="pharmacology", version=VERSION, description="Pharmacology"),
|
176 |
+
datasets.BuilderConfig(name="Psychiatry", version=VERSION, description="Psychiatry")
|
177 |
+
]
|
178 |
+
|
179 |
+
DEFAULT_CONFIG_NAME = "core_clinical"
|
180 |
+
|
181 |
+
def _info(self):
|
182 |
+
features = datasets.Features(
|
183 |
+
{
|
184 |
+
"text": datasets.Value("string"),
|
185 |
+
"source": datasets.Value("string"),
|
186 |
+
}
|
187 |
+
)
|
188 |
+
return datasets.DatasetInfo(
|
189 |
+
description=_DESCRIPTION,
|
190 |
+
features=features,
|
191 |
+
homepage=_HOMEPAGE,
|
192 |
+
license=_LICENSE,
|
193 |
+
citation=_CITATION,
|
194 |
+
)
|
195 |
+
|
196 |
+
def _split_generators(self, dl_manager):
|
197 |
+
urls = _URLS[0]
|
198 |
+
data_dir = Path(dl_manager.download_and_extract(urls))
|
199 |
+
self.base_dir = data_dir / "data_clean" / "textbooks" / "en"
|
200 |
+
|
201 |
+
return [
|
202 |
+
datasets.SplitGenerator(name=datasets.Split.TRAIN)
|
203 |
+
]
|
204 |
+
|
205 |
+
def _generate_examples(self):
|
206 |
+
for key, record in enumerate(get_med_qa_textbooks(self.base_dir, self.config.name)):
|
207 |
+
yield key, record
|