-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsplit_examples.py
More file actions
73 lines (47 loc) · 1.58 KB
/
split_examples.py
File metadata and controls
73 lines (47 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env python
# coding: utf-8
# In[1]:
import csv
import os,glob
from transformers import AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained("emilyalsentzer/Bio_ClinicalBERT")
# In[2]:
def tokenize(patientID):
with open('../../data/update/patients/'+patientID,'r') as f:
with open('../../data/update/processPatient/'+patientID,'w') as g:
test = ''
newLength = 0
i = 220
for line in f:
words = line.split(" ")
chunk = " ".join(words[0:i])
g.write(chunk+" ")
test += chunk + " "
while i < len(words):
if newLength >= 475:
g.write('\n'+ words[i] +" ")
test = words[i] + " "
token = tokenizer.encode(test)
newLength = len(token)
i += 1
else:
chunk = " ".join(words[i:(i+5)])
g.write(chunk+" ")
test += chunk + " "
token = tokenizer.encode(test)
newLength = len(token)
i += 5
else:
continue
break
# In[4]:
# open patients text file
patientList = os.listdir('../../data/update/patients/')
for i in range(len(patientList)):
tokenize(patientList[i])
print(patientList[i])
# In[4]:
patientList = os.listdir('../../data/update/patients/')
# In[5]:
patientList[0]
# In[ ]: