# 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. """ MedQA Textbook (English) with focused emphasis on domain of Clinical Medicine and other subsets relevant for use with Clinical Ontologies. Textbooks: Anatomy_Gray.txt Clinical medicine Biochemistry_Lippincott.txt Basic biology Cell_Biology_Alberts.txt Basic biology First_Aid_Step1.txt Clinical medicine First_Aid_Step2.txt Clinical medicine Gynecology_Novak.txt Clinical medicine Histology_Ross.txt Basic biology Immunology_Janeway.txt Allergy and immunology Clinical medicine InternalMed_Harrison.txt Clinical medicine Neurology_Adams.txt Neurology Clinical medicine Obstentrics_Williams.txt OBGYN Clinical medicine Pathology_Robbins.txt Basic biology Pathoma_Husain.txt Pathology Clinical medicine Pediatrics_Nelson.txt Pediatrics Clinical medicine Pharmacology_Katzung.txt Pharmacology Physiology_Levy.txt Basic biology Psichiatry_DSM-5.txt Psychiatry Surgery_Schwartz.txt Surgery Clinical medicine """ SUBJECT_SUBSETS = { "core_clinical": ["Anatomy_Gray", "First_Aid_Step1", "First_Aid_Step2", "Immunology_Janeway", "InternalMed_Harrison", "Neurology_Adams", "Obstentrics_Williams", "Pathoma_Husain", "Pediatrics_Nelson", "Surgery_Schwartz"], "basic_biology": ["Biochemistry_Lippincott", "Cell_Biology_Alberts", "Histology_Ross", "Pathology_Robbins", "Physiology_Levy"], "pharmacology": ["Pharmacology_Katzung"], "psychiatry": ["Psichiatry_DSM-5"] } from pathlib import Path import json import datasets CHUNK_OVERLAP = 20 MAX_CHUNK_SIZE = 800 # TODO: Add description of the dataset here # You can copy an official description _DESCRIPTION = """\ MedQA Textbook (English) with emphasis on domain of Clinical Medicine and other subsets. """ # TODO: Add a link to an official homepage for the dataset here _HOMEPAGE = "https://github.com/jind11/MedQA" # TODO: Add the licence for the dataset here if you can find it _LICENSE = """ MIT License Copyright (c) 2022 Di Jin Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ _URLS = ["textbooks_en_jsonl.zip"] _CITATION = """\ @article{jin2021disease, title={What disease does this patient have? a large-scale open domain question answering dataset from medical exams}, author={Jin, Di and Pan, Eileen and Oufattole, Nassim and Weng, Wei-Hung and Fang, Hanyi and Szolovits, Peter}, journal={Applied Sciences}, volume={11}, number={14}, pages={6421}, year={2021}, publisher={MDPI} } """ def get_med_qa_textbooks(location, subset_name): for textbook_content in location.glob('*.jsonl'): textbook_name = textbook_content.name.split('.')[0] if textbook_name in SUBJECT_SUBSETS[subset_name]: with textbook_content.open("r") as fid: for line in fid: yield json.loads(line) class MedQACorpus(datasets.GeneratorBasedBuilder): """MedQA Textbook (English) with emphasis on domain of Clinical Medicine and other subsets.""" VERSION = datasets.Version("0.0.1") BUILDER_CONFIGS = [ datasets.BuilderConfig(name="core_clinical", version=VERSION, description="Core clinical medicine"), datasets.BuilderConfig(name="basic_biology", version=VERSION, description="Basic biology"), datasets.BuilderConfig(name="pharmacology", version=VERSION, description="Pharmacology"), datasets.BuilderConfig(name="psychiatry", version=VERSION, description="Psychiatry") ] DEFAULT_CONFIG_NAME = "core_clinical" def _info(self): features = datasets.Features( { "text": datasets.Value("string"), "source": datasets.Value("string"), } ) return datasets.DatasetInfo( description=_DESCRIPTION, features=features, homepage=_HOMEPAGE, license=_LICENSE, citation=_CITATION, ) def _split_generators(self, dl_manager): urls = _URLS[0] data_dir = Path(dl_manager.download_and_extract(urls)) self.base_dir = data_dir / "textbooks" / "en" return [ datasets.SplitGenerator(name=datasets.Split.TRAIN) ] def _generate_examples(self): for key, record in enumerate(get_med_qa_textbooks(self.base_dir, self.config.name)): yield key, record