-
Notifications
You must be signed in to change notification settings - Fork 3
/
preprocess.py
27 lines (22 loc) · 918 Bytes
/
preprocess.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
import numpy as np
class Preprocess:
def __init__(self, flows, word_to_id, window_size):
self.flows = flows
self.word_to_id = word_to_id
self.window_size = window_size
def generate_training_data(self):
X_train = []
y_train = []
for flow in self.flows:
for i in range(len(flow)):
center_word = self.word_to_id[flow[i]]
for j in range(i-self.window_size,i+self.window_size+1):
if (i==1 and j==0)|(i==2 and j==0):
continue
if i!=j and j>=0 and j<len(flow):
context = self.word_to_id[flow[j]]
X_train.append(center_word)
y_train.append(context)
X_train = np.expand_dims(X_train, axis=0)
y_train = np.expand_dims(y_train, axis=0)
return X_train, y_train