-
Notifications
You must be signed in to change notification settings - Fork 4
/
prepare_training.py
64 lines (45 loc) · 1.61 KB
/
prepare_training.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import numpy as np
import pickle
# load all parts
number_of_parts = 22
data1_to_concat = []
data2_to_concat = []
word_counts = []
for i in range(number_of_parts + 1):
part = np.load("H:/data/data1_{}.npy".format(i))
if len(part) > 0:
print("Reading part {}".format(i))
data1_to_concat.append(part.astype('float16'))
part = pickle.load( open( "H:/data/word_count_{}.pkl".format(i), "rb" ) )
word_counts = word_counts + part
data1 = np.concatenate( data1_to_concat )
data1_to_concat = None
word_counts = np.array(word_counts)
print(data1.shape)
# increase data by adding in more copies of words that are more frequent by sample from frequencies saved
for i in range(2, 6):
indices = (word_counts >= i ).nonzero()
data1 = np.concatenate( [data1, data1[indices] ])
print(data1.shape)
# shuffle
randomize = np.arange(len(data1))
np.random.shuffle(randomize)
data1 = data1[randomize]
np.save("H:/data/data1_with_dup_full", data1)
data1 = None
word_counts = []
for i in range(number_of_parts + 1):
part = np.load("H:/data/data2_{}.npy".format(i))
if len(part) > 0:
print("Reading part {}".format(i))
data2_to_concat.append(part.astype('float16'))
part = pickle.load( open( "H:/data/word_count_{}.pkl".format(i), "rb" ) )
word_counts = word_counts + part
data2 = np.concatenate( data2_to_concat )
data2_to_concat = None
word_counts = np.array(word_counts)
for i in range(2, 6):
indices = (word_counts >= i ).nonzero()
data2 = np.concatenate( [data2, data2[indices] ])
data2 = data2[randomize]
np.save("H:/data/data2_with_dup_full", data2)