forked from facebookresearch/code-prediction-transformer
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdata.py
29 lines (22 loc) · 753 Bytes
/
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
import utils
import json
import pickle
from torch.utils.data import Dataset
class CodeDataset(Dataset):
def __init__(self):
self.inputs = []
def __len__(self):
return len(self.inputs)
def __getitem__(self, index):
# Add padding?
return self.inputs[index]
def cache_dataset(self, dest_path):
with open(dest_path, "wb") as fout:
pickle.dump(self.inputs, fout)
def load_from_cache(self, cache_path):
with open(cache_path, "rb") as fin:
self.inputs = pickle.load(fin)
def load_from_file(self, file_path):
with open(file_path) as fin:
for line in utils.file_tqdm(fin):
self.inputs.append([int(s) for s in line.split()])