inoid commited on
Commit
d3b652c
1 Parent(s): 219ab4d

Upload 4 files

Browse files
cantemist/ICD-O-3_valid-codes.txt ADDED
The diff for this file is too large to render. See raw diff
 
cantemist/README.md ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+
3
+ https://temu.bsc.es/cantemist/?cat=2
4
+
5
+ Codigos validos
6
+
7
+ ==> https://temu.bsc.es/cantemist/wp-content/uploads/2020/07/valid-codes.txt
8
+
9
+ On HugginFace Database
10
+ https://huggingface.co/datasets/bigbio/cantemist/viewer/cantemist_bigbio_kb
11
+
12
+ bigbio/cantemist
cantemist/using_dataset_hugginface.ipynb ADDED
The diff for this file is too large to render. See raw diff
 
cantemist/using_dataset_hugginface.py ADDED
@@ -0,0 +1,176 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ """using_dataset_hugginface.ipynb
3
+
4
+ Automatically generated by Colaboratory.
5
+
6
+ Original file is located at
7
+ https://colab.research.google.com/drive/1soGxkZu4antYbYG23GioJ6zoSt_GhSNT
8
+ """
9
+
10
+ """**Hugginface loggin for push on Hub**"""
11
+ ###
12
+ #
13
+ # Used bibliografy:
14
+ # https://huggingface.co/learn/nlp-course/chapter5/5
15
+ #
16
+ ###
17
+
18
+ import os
19
+ import time
20
+ import math
21
+ from huggingface_hub import login
22
+ from datasets import load_dataset, concatenate_datasets
23
+ from functools import reduce
24
+ from pathlib import Path
25
+ import pandas as pd
26
+
27
+ # Load model directly
28
+ from transformers import AutoTokenizer, AutoModelForCausalLM
29
+
30
+ HF_TOKEN = ''
31
+ DATASET_TO_LOAD = 'bigbio/cantemist'
32
+ DATASET_TO_UPDATE = 'somosnlp/spanish_medica_llm'
33
+ DATASET_SOURCE_ID = '1'
34
+
35
+ #Loggin to Huggin Face
36
+ login(token = HF_TOKEN)
37
+
38
+ dataset_CODING = load_dataset(DATASET_TO_LOAD)
39
+ royalListOfCode = {}
40
+ issues_path = 'dataset'
41
+ tokenizer = AutoTokenizer.from_pretrained("DeepESP/gpt2-spanish-medium")
42
+
43
+ #Read current path
44
+ path = Path(__file__).parent.absolute()
45
+
46
+ with open( str(path) + os.sep + 'ICD-O-3_valid-codes.txt',encoding='utf8') as file:
47
+ """
48
+ # Build a dictionary with ICD-O-3 associated with
49
+ # healtcare problems
50
+ """
51
+ linesInFile = file.readlines()
52
+ for iLine in linesInFile:
53
+ listOfData = iLine.split('\t')
54
+
55
+ code = listOfData[0]
56
+ description = reduce(lambda a, b: a + " "+ b, listOfData[1:2], "")
57
+ royalListOfCode[code.strip()] = description.strip()
58
+
59
+
60
+ def getCodeDescription(labels_of_type, royalListOfCode):
61
+ """
62
+ Search description associated with some code
63
+ in royalListOfCode
64
+
65
+ """
66
+ classification = []
67
+
68
+ for iValue in labels_of_type:
69
+ if iValue in royalListOfCode.keys():
70
+ classification.append(royalListOfCode[iValue])
71
+ return classification
72
+
73
+
74
+ # raw_text: Texto asociado al documento, pregunta, caso clínico u otro tipo de información.
75
+
76
+ # topic: (puede ser healthcare_treatment, healthcare_diagnosis, tema, respuesta a pregunta, o estar vacío p.ej en el texto abierto)
77
+
78
+ # speciality: (especialidad médica a la que se relaciona el raw_text p.ej: cardiología, cirugía, otros)
79
+
80
+ # raw_text_type: (puede ser caso clínico, open_text, question)
81
+
82
+ # topic_type: (puede ser medical_topic, medical_diagnostic,answer,natural_medicine_topic, other, o vacio)
83
+
84
+ # source: Identificador de la fuente asociada al documento que aparece en el README y descripción del dataset.
85
+
86
+ # country: Identificador del país de procedencia de la fuente (p.ej.; ch, es) usando el estándar ISO 3166-1 alfa-2 (Códigos de país de dos letras.).
87
+ cantemistDstDict = {
88
+ 'raw_text': '',
89
+ 'topic': '',
90
+ 'speciallity': '',
91
+ 'raw_text_type': 'clinic_case',
92
+ 'topic_type': 'medical_diagnostic',
93
+ 'source': DATASET_SOURCE_ID,
94
+ 'country': 'es',
95
+ 'document_id': ''
96
+ }
97
+
98
+ totalOfTokens = 0
99
+ corpusToLoad = []
100
+ countCopySeveralDocument = 0
101
+ counteOriginalDocument = 0
102
+
103
+ for iDataset in dataset_CODING:
104
+ if iDataset == 'test':
105
+ for item in dataset_CODING[iDataset]:
106
+ #print ("Element in dataset")
107
+ idFile = item['id']
108
+ text = item['text']
109
+ list_of_type = item['text_bound_annotations']
110
+ labels_of_type = item['labels']
111
+
112
+ #Find topic or diagnosti clasification about the text
113
+ diagnostyc_types = getCodeDescription( labels_of_type, royalListOfCode)
114
+ counteOriginalDocument += 1
115
+ classFileSize = len(diagnostyc_types)
116
+
117
+ #If there are more clasification about the file
118
+
119
+ if classFileSize > 1:
120
+ countCopySeveralDocument += classFileSize - 1
121
+
122
+ listOfTokens = tokenizer.tokenize(text)
123
+ currentSizeOfTokens = len(listOfTokens)
124
+ totalOfTokens += currentSizeOfTokens
125
+
126
+ for iTypes in diagnostyc_types:
127
+ #print(iTypes)
128
+ newCorpusRow = cantemistDstDict.copy()
129
+
130
+ #print('Current text has ', currentSizeOfTokens)
131
+ #print('Total of tokens is ', totalOfTokens)
132
+ newCorpusRow['raw_text'] = text
133
+ newCorpusRow['document_id'] = str(idFile)
134
+ newCorpusRow['topic'] = iTypes
135
+ corpusToLoad.append(newCorpusRow)
136
+
137
+ df = pd.DataFrame.from_records(corpusToLoad)
138
+
139
+ if os.path.exists(f"{str(path)}/{issues_path}/spanish_medical_llms.jsonl"):
140
+ os.remove(f"{str(path)}/{issues_path}/spanish_medical_llms.jsonl")
141
+
142
+ df.to_json(f"{str(path)}/{issues_path}/spanish_medical_llms.jsonl", orient="records", lines=True)
143
+ print(
144
+ f"Downloaded all the issues for {DATASET_TO_LOAD}! Dataset stored at {issues_path}/spanish_medical_llms.jsonl"
145
+ )
146
+
147
+ print(' On dataset there are as document ', counteOriginalDocument)
148
+ print(' On dataset there are as copy document ', countCopySeveralDocument)
149
+ print(' On dataset there are as size of Tokens ', totalOfTokens)
150
+ file = Path(f"{str(path)}/{issues_path}/spanish_medical_llms.jsonl") # or Path('./doc.txt')
151
+ size = file.stat().st_size
152
+ print ('File size on Kilobytes (kB)', size >> 10) # 5242880 kilobytes (kB)
153
+ print ('File size on Megabytes (MB)', size >> 20 ) # 5120 megabytes (MB)
154
+ print ('File size on Gigabytes (GB)', size >> 30 ) # 5 gigabytes (GB)
155
+
156
+ #Once the issues are downloaded we can load them locally using our
157
+ local_spanish_dataset = load_dataset("json", data_files=f"{str(path)}/{issues_path}/spanish_medical_llms.jsonl", split="train")
158
+
159
+ ##Update local dataset with cloud dataset
160
+ try:
161
+ spanish_dataset = load_dataset(DATASET_TO_UPDATE, split="train")
162
+ spanish_dataset = concatenate_datasets([spanish_dataset, local_spanish_dataset])
163
+ except Exception:
164
+ spanish_dataset = local_spanish_dataset
165
+
166
+ spanish_dataset.push_to_hub(DATASET_TO_UPDATE)
167
+
168
+ print(spanish_dataset)
169
+
170
+ # Augmenting the dataset
171
+
172
+ #Importan if exist element on DATASET_TO_UPDATE we must to update element
173
+ # in list, and review if the are repeted elements
174
+
175
+
176
+