forked from autumn0409/Log-based-Anomaly-Detection-System
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdataloader.py
29 lines (21 loc) · 807 Bytes
/
dataloader.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
import numpy as np
import keras
from keras.preprocessing.sequence import pad_sequences
import math
EMBEDDING_DIM = 768
class DataGenerator(keras.utils.Sequence):
def __init__(self, x, y, batch_size):
'Initialization'
self.x = x
self.y = y
self.batch_size = batch_size
def __len__(self):
'Denotes the number of batches'
return math.ceil(len(self.x) / self.batch_size)
def __getitem__(self, index):
'Generate one batch of data'
x = self.x[index * self.batch_size:(index + 1) * self.batch_size]
y = self.y[index * self.batch_size:(index + 1) * self.batch_size]
x = pad_sequences(x, dtype='object', padding='post',
value=np.zeros(EMBEDDING_DIM)).astype(np.float32)
return x, y