-
Notifications
You must be signed in to change notification settings - Fork 6
/
input_data.py
46 lines (28 loc) · 1.02 KB
/
input_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
import random
import copy
import json
import re,pprint
class ToyDataset:
def __init__(self):
with open('data.json') as f:
self.data = json.load(f)
self.train_data = self.data[1000:]
self.test_data = self.data[:1000]
self.batch_id = 0
def get_batch(self, batch_size=20):
if self.batch_id+batch_size>=len(self.train_data):
self.batch_id = 0
random.shuffle(self.train_data)
batch_data = self.train_data[self.batch_id:self.batch_id + batch_size]
batch_source = copy.deepcopy(batch_data)
batch_target = copy.deepcopy(batch_data)
self.batch_id = self.batch_id + batch_size
return batch_source, batch_target
def get_test_data(self):
batch_data = self.test_data
batch_source = copy.deepcopy(batch_data)
batch_target = copy.deepcopy(batch_data)
return batch_source, batch_target
if __name__ == '__main__':
dataset = ToyDataset()
pprint.pprint(dataset.get_batch())