ANKITYADAV247 moukaii commited on
Commit
f99d677
·
0 Parent(s):

Duplicate from moukaii/Tuberculosis_Dataset

Browse files

Co-authored-by: Zhankai Ye <moukaii@users.noreply.huggingface.co>

.gitattributes ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.lz4 filter=lfs diff=lfs merge=lfs -text
12
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
13
+ *.model filter=lfs diff=lfs merge=lfs -text
14
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
15
+ *.npy filter=lfs diff=lfs merge=lfs -text
16
+ *.npz filter=lfs diff=lfs merge=lfs -text
17
+ *.onnx filter=lfs diff=lfs merge=lfs -text
18
+ *.ot filter=lfs diff=lfs merge=lfs -text
19
+ *.parquet filter=lfs diff=lfs merge=lfs -text
20
+ *.pb filter=lfs diff=lfs merge=lfs -text
21
+ *.pickle filter=lfs diff=lfs merge=lfs -text
22
+ *.pkl filter=lfs diff=lfs merge=lfs -text
23
+ *.pt filter=lfs diff=lfs merge=lfs -text
24
+ *.pth filter=lfs diff=lfs merge=lfs -text
25
+ *.rar filter=lfs diff=lfs merge=lfs -text
26
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
27
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
28
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
29
+ *.tar filter=lfs diff=lfs merge=lfs -text
30
+ *.tflite filter=lfs diff=lfs merge=lfs -text
31
+ *.tgz filter=lfs diff=lfs merge=lfs -text
32
+ *.wasm filter=lfs diff=lfs merge=lfs -text
33
+ *.xz filter=lfs diff=lfs merge=lfs -text
34
+ *.zip filter=lfs diff=lfs merge=lfs -text
35
+ *.zst filter=lfs diff=lfs merge=lfs -text
36
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
37
+ # Audio files - uncompressed
38
+ *.pcm filter=lfs diff=lfs merge=lfs -text
39
+ *.sam filter=lfs diff=lfs merge=lfs -text
40
+ *.raw filter=lfs diff=lfs merge=lfs -text
41
+ # Audio files - compressed
42
+ *.aac filter=lfs diff=lfs merge=lfs -text
43
+ *.flac filter=lfs diff=lfs merge=lfs -text
44
+ *.mp3 filter=lfs diff=lfs merge=lfs -text
45
+ *.ogg filter=lfs diff=lfs merge=lfs -text
46
+ *.wav filter=lfs diff=lfs merge=lfs -text
47
+ # Image files - uncompressed
48
+ *.bmp filter=lfs diff=lfs merge=lfs -text
49
+ *.gif filter=lfs diff=lfs merge=lfs -text
50
+ *.png filter=lfs diff=lfs merge=lfs -text
51
+ *.tiff filter=lfs diff=lfs merge=lfs -text
52
+ # Image files - compressed
53
+ *.jpg filter=lfs diff=lfs merge=lfs -text
54
+ *.jpeg filter=lfs diff=lfs merge=lfs -text
55
+ *.webp filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,129 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - en
4
+ license: apache-2.0
5
+ size_categories:
6
+ - 100M<n<1B
7
+ task_categories:
8
+ - feature-extraction
9
+ - text-classification
10
+ tags:
11
+ - biomedical
12
+ - imaging
13
+ - computer vision
14
+ - tuberculosis
15
+ - multimodal
16
+ dataset_info:
17
+ features:
18
+ - name: case_id
19
+ dtype: string
20
+ - name: gender
21
+ dtype: string
22
+ - name: age
23
+ dtype: int8
24
+ - name: case_text
25
+ dtype: string
26
+ - name: keywords
27
+ dtype: string
28
+ - name: image_file
29
+ dtype: image
30
+ - name: caption
31
+ dtype: string
32
+ splits:
33
+ - name: train
34
+ num_bytes: 70088819.588
35
+ num_examples: 6284
36
+ download_size: 42809832
37
+ dataset_size: 70088819.588
38
+ configs:
39
+ - config_name: default
40
+ data_files:
41
+ - split: train
42
+ path: data/train-*
43
+ ---
44
+
45
+ # Multimodal Dataset of Tuberculosis Patients including CT and Clinical Case Reports
46
+
47
+ Zhankai Ye <br>
48
+ NetID: zy172
49
+
50
+ ## Dataset Summary
51
+ This dataset is curated from the original “The MultiCaRe Dataset” to focus on the chest tuberculosis patients. This is a multimodal dataset consisting of lung computed tomography (CT) imaging data and the clinical case records of tuberculosis patients, along with their case keywords, the captions of their CT images, patient_id, gender, and age information.
52
+
53
+ ## Dataset Sources
54
+ - Homepage: https://zenodo.org/records/10079370
55
+ - DOI: 10.5281/zenodo.10079370
56
+ - Data article: https://www.sciencedirect.com/science/article/pii/S2352340923010351
57
+
58
+ ## Supported Tasks:
59
+ This dataset can be utilized for:
60
+ - Developing algorithms of the segmentation of chest CT images and the classification of tuberculosis positive or control.
61
+ - Developing novel natural language processing (NLP) methods and unsupervised machine learning methods to extract medical terms from clinical notes.
62
+
63
+ ## Languages:
64
+ English
65
+
66
+ ## Data Structure and Instance:
67
+ The data will follow the structure below:
68
+ {
69
+ - `"case_id"`: "PMC10129030_01",
70
+ - `"gender"`: "male",
71
+ - `"age"`: 62,
72
+ - `"case_text"`: "A 62-year-old man presented with acute dyspnea at rest, requiring high-flow…",
73
+ - `"keywords"`: "["dendriform pulmonary ossification", "lung transplant", "pulmonary fibrosis"]",
74
+ - `"pics_array"`: image
75
+ - `"Caption"`: "coronal. chest CT shows ground-glass and reticular opacities in the dependent…"
76
+ }
77
+
78
+ ## Data Fields:
79
+ - **case_id (string)**: ID of the patient, created combining the PMC of the article plus a sequential number.
80
+ - **gender (string)**: Gender of the patient. It can be either Female, Male, Transgender or Unknown.
81
+ - **age (int)**: Age of the patient. Ages lower than 1 y.o. are assigned 0 as age.
82
+ - **case_text (string)**: Self-explanatory.
83
+ - **keywords (string)**: Keywords are taken from the keywords section that is sometimes available in the content of the article.
84
+ - **pics_array (int)**: image
85
+ - **Caption (string)**: Image caption.
86
+
87
+ ## Initial Data Collect and Preprocessing
88
+ 1. The original MultiCaRe Dataset, approximately 9GB in size, encompasses a diverse range of medical specialties including oncology, cardiology, surgery, and pathology. To create your tuberculosis-focused subset, the dataset undergoes a filtering process based on specific criteria:
89
+ - Case Report Selection: The selection criterion for case reports is the presence of keywords such as 'tuberculosis' or 'tb'. This ensures that only reports relevant to tuberculosis are included.
90
+ - Caption Filtering: The dataset is further refined by filtering captions that contain keywords like 'ct', 'lung', or 'chest'.
91
+ - Image Labeling: Finally, the images are chosen based on the presence of labels 'ct' and 'lung'. This dual-label requirement ensures that the selected images are relevant to CT scans of the lungs, which are instrumental in detecting and assessing tuberculosis.
92
+ - Through this meticulous filtering process, an initial tuberculosis dataset is compiled from the broader MultiCaRe Dataset. This dataset is messy, contains many diffferent files.
93
+ 2. To enhance the quality and relevance of the tuberculosis dataset, additional processing steps are implemented after in the Hugging Face python script after the initial filtration from the MultiCaRe Dataset:
94
+ - Exclusion of Records with Missing Age Information.
95
+ - Merge of data from difference files, including .csv, .JSON, and .jpg.
96
+
97
+ ## Social Impact
98
+ The multimodal dataset of tuberculosis patients, meticulously curated from the larger MultiCaRe Dataset, stands to have a significant social impact, particularly in the field of public health and medical research. Tuberculosis (TB) remains a major global health issue, especially in low- and middle-income countries, and the integration of CT imaging with clinical case reports in this dataset provides a rich resource for advanced diagnostic and treatment research. By facilitating the development of more precise algorithms for CT image segmentation and classification, as well as enhancing natural language processing (NLP) techniques for extracting medical terms from clinical notes, this dataset has the potential to improve the accuracy and efficiency of TB diagnosis.
99
+
100
+ ## Personal and Sensitive Information
101
+ Case reports are designed with the intention of being publicly accessible, and as a result, they deliberately omit any personal identifying details of the patients to ensure their privacy and confidentiality.
102
+
103
+ ## Bias, Risks, and Limitations
104
+ ### Bias
105
+ 1. Selection Bias: The original MultiCaRe Dataset was generated from 75,382 open access PubMed Central articles spanning the period from 1990 to 2023. Therefore, the random sampling of the cases from difference demographic groups cannot be guaranteed. The data may have bias as the collection process was not representative of the broader population. For example, the dataset may predominantly includes cases from a specific geographic location, age group, or socioeconomic status, and the findings may not apply to other groups.
106
+ 2. Technology Bias: Advanced imaging technologies might not be equally available in all settings, leading to a dataset that disproportionately represents patients from better-equipped facilities. This can skew the dataset towards conditions that are more likely to be diagnosed in such settings.
107
+ 3. Interpreter Bias: For the `"case_text"` and the `"caption"`, variability in the expertise and experience of radiologists or clinicians interpreting the images can lead to differences in diagnosis or findings reported in the dataset.
108
+
109
+ ### Risks
110
+ 1. Privacy and Confidentiality Risks: Patient data, including case records and images, are highly sensitive. There's a risk of identifying individuals even if the data is properly anonymized.
111
+ 2. Data Integrity and Quality Risks: Inaccuracies, missing data, and inconsistencies within the dataset can compromise the validity of research findings or clinical decisions based on the data. This could lead to ineffective or harmful interventions.
112
+
113
+ ### Limitations
114
+ - Data Quality:
115
+ 1. For textual data, certain patient records are missing key descriptive terms. Meanwhile, cases where imaging studies were not conducted lack both the images and their respective descriptive captions.
116
+ 2. Regarding images, a primary concern is also the incomplete nature of the dataset, as images do not accompany all patient records. Additionally, the image resolution varies, which can impede detailed examination. The inconsistency in image sizes and variations in the positioning of patient photographs may also pose challenges for consistent image analysis.
117
+
118
+ ## Citation
119
+ ```bibtex
120
+ @dataset{NievasOffidani2023MultiCaRe,
121
+ author = {Nievas Offidani, M. and Delrieux, C.},
122
+ title = {The MultiCaRe Dataset: A Multimodal Case Report Dataset with Clinical Cases, Labeled Images and Captions from Open Access PMC Articles},
123
+ year = {2023},
124
+ version = {1.0},
125
+ publisher = {Zenodo},
126
+ doi = {10.5281/zenodo.10079370},
127
+ url = {https://doi.org/10.5281/zenodo.10079370},
128
+ }
129
+ ```
TubercuIosis_Dataset.py ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from datasets import GeneratorBasedBuilder, DownloadManager, DatasetInfo, Features, Value, Sequence, ClassLabel, Image, BuilderConfig, SplitGenerator, Version
2
+ import datasets
3
+ import pandas as pd
4
+ import json
5
+ import zipfile
6
+ import os
7
+
8
+ _DESCRIPTION = """\
9
+ This dataset is curated from the original “The MultiCaRe Dataset” to focus on the chest tuberculosis patients and can be used to develop algorithms of the segmentation of chest CT images and the classification of tuberculosis positive or control.
10
+ """
11
+
12
+ _CITATION = """\
13
+ Nievas Offidani, M. and Delrieux, C. (2023) “The MultiCaRe Dataset: A Multimodal Case Report Dataset with Clinical Cases, Labeled Images and Captions from Open Access PMC Articles”. Zenodo. doi: 10.5281/zenodo.10079370.
14
+ """
15
+
16
+ class TuberculosisDataset(GeneratorBasedBuilder):
17
+ # Define dataset's name
18
+ BUILDER_CONFIGS = [
19
+ BuilderConfig(name="tuberculosis_dataset", version=Version("1.0.0"))
20
+ ]
21
+
22
+ def _info(self):
23
+ return DatasetInfo(
24
+ description=_DESCRIPTION,
25
+ features=Features({
26
+ "case_id": Value("string"),
27
+ "gender": Value("string"),
28
+ "age": Value("int8"),
29
+ "case_text": Value("string"),
30
+ "keywords": Value("string"),
31
+ "image_file": Image(), # Using Image type
32
+ "caption": Value("string"),
33
+ }),
34
+ supervised_keys=None,
35
+ homepage="https://zenodo.org/records/10079370",
36
+ citation=_CITATION,
37
+ )
38
+
39
+ def _split_generators(self, dl_manager):
40
+ base_url = "https://raw.githubusercontent.com/zhankai-ye/tuberculosis_dataset/main/"
41
+ urls = {
42
+ "cases_csv": f"{base_url}cases.csv",
43
+ "keywords_json": "https://raw.githubusercontent.com/zhankai-ye/tuberculosis_dataset/a774776663fe4ce5e960f502dc337b0e77451ca7/article_metadata.json",
44
+ "caption_json": f"{base_url}image_metadata.json",
45
+ "images_zip": "https://github.com/zhankai-ye/tuberculosis_dataset/raw/main/images/PMC.zip"
46
+ }
47
+ downloaded_files = dl_manager.download_and_extract(urls)
48
+
49
+ return [
50
+ SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs=downloaded_files),
51
+ ]
52
+
53
+ def _generate_examples(self, cases_csv, keywords_json, caption_json, images_zip):
54
+ # Load CSV
55
+ cases_df = pd.read_csv(cases_csv)
56
+ cases_df.dropna(subset=['age'], inplace=True)
57
+
58
+ # Load Keywords JSON
59
+ with open(keywords_json, 'r') as f:
60
+ keywords_json_data = json.load(f)
61
+ keywords = pd.json_normalize(keywords_json_data)
62
+ keywords['keywords'] = keywords['keywords'].apply(lambda x: ', '.join(x) if isinstance(x, list) else x)
63
+
64
+ # Load Caption JSON
65
+ caption_json_data = []
66
+ with open(caption_json, 'r') as f:
67
+ for line in f:
68
+ caption_json_data.append(json.loads(line))
69
+ caption = pd.json_normalize(caption_json_data)
70
+
71
+ # Merge DataFrames
72
+ merged_df = pd.merge(cases_df, keywords[['pmcid', 'keywords']], left_on='pmcid', right_on='pmcid', how='left')
73
+ merged_df = pd.merge(merged_df, caption[['case_id', 'caption']], on='case_id', how='left')
74
+ merged_df = merged_df.where(pd.notnull(merged_df), None)
75
+ merged_df['age'] = merged_df['age'].astype('int8')
76
+
77
+ # Extract and prepare image file paths
78
+ image_file_paths = self._prepare_image_file_paths(images_zip)
79
+
80
+ # Yield examples
81
+ for idx, row in merged_df.iterrows():
82
+ image_file = image_file_paths.get(row["pmcid"],None)
83
+
84
+ yield idx, {
85
+ "case_id": row["case_id"],
86
+ "gender": row["gender"],
87
+ "age": int(row["age"]),
88
+ "case_text": row["case_text"],
89
+ "keywords": row["keywords"],
90
+ "image_file": image_file,
91
+ "caption": row["caption"],
92
+ }
93
+
94
+ def _prepare_image_file_paths(self, images_zip_path):
95
+ image_file_paths = {}
96
+ temp_dir = "temp_images"
97
+
98
+ # Check if images_zip_path is a directory or a zip file
99
+ if os.path.isdir(images_zip_path):
100
+ base_path = images_zip_path
101
+ elif os.path.isfile(images_zip_path) and zipfile.is_zipfile(images_zip_path):
102
+ # Extract the zip file to a temporary directory
103
+ with zipfile.ZipFile(images_zip_path, 'r') as zip_ref:
104
+ zip_ref.extractall(temp_dir)
105
+ base_path = temp_dir
106
+ else:
107
+ raise ValueError("images_zip_path must be a directory or a zip file")
108
+
109
+ # Walk through the base_path
110
+ for root, _, files in os.walk(base_path):
111
+ for file in files:
112
+ key = file.split('_')[0]
113
+ if key not in image_file_paths:
114
+ image_file_paths[key] = os.path.join(root, file)
115
+
116
+ return image_file_paths
data/train-00000-of-00001.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f35b946a12510dd0db49d713a3c72f458145ba26eca1986e69ff2e8d96fb8a57
3
+ size 42809832