-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmake_data.py
46 lines (38 loc) · 1.11 KB
/
make_data.py
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
from sklearn.model_selection import train_test_split
from tqdm import tqdm
import os
path = "./data/data.tsv"
data = []
with open(path, mode="r", encoding="utf-8") as f:
for file_list in f:
data.append(file_list)
train_size = int(len(data) * 0.7)
test_size = len(data) - train_size
train, test = train_test_split(data, train_size = train_size, test_size = test_size)
test_size = int(len(test)/2)
val_size = len(test) - test_size
test, val = train_test_split(test, train_size = test_size, test_size = val_size)
print(len(train))
print(len(test))
print(len(val))
path = os.getcwd() + "/data/train.tsv"
print(path)
bar = tqdm(total = len(train))
with open(path, "w", encoding="utf-8") as f:
for i in train:
f.write(i)
bar.update(1)
bar = tqdm(total = len(test))
path = os.getcwd() + "/data/test.tsv"
print(path)
with open(path, "w", encoding="utf-8") as f:
for i in test:
f.write(i)
bar.update(1)
bar = tqdm(total = len(val))
path = os.getcwd() + "/data/val.tsv"
print(path)
with open(path, "w", encoding="utf-8") as f:
for i in val:
f.write(i)
bar.update(1)