-
Notifications
You must be signed in to change notification settings - Fork 2
/
dataset.py
42 lines (27 loc) · 989 Bytes
/
dataset.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
import torch
from torch.utils.data import Dataset
import config
import pickle
with open('preprocess_input/question.pkl','rb') as f:
question = pickle.load(f)
with open('preprocess_input/answers.pkl','rb') as f:
answers = pickle.load(f)
with open('preprocess_input/vocab.pkl','rb') as f:
vocab_dict = pickle.load(f)
vocab_dict[32350] = '<START>'
vocab_dict[32351] = '<END>'
class Dataset(Dataset):
def __init__(self):
self.question = question
self.answers = answers
self.dataset_size = len(self.question)
def __getitem__(self, i):
question = torch.LongTensor(self.question[i])
reply = torch.LongTensor(self.answers[i])
return question, reply
def __len__(self):
return self.dataset_size
train_loader = torch.utils.data.DataLoader(Dataset(),
config.batch_size,
shuffle= True,
pin_memory=True)