-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPCLDataset.py
More file actions
32 lines (21 loc) · 800 Bytes
/
PCLDataset.py
File metadata and controls
32 lines (21 loc) · 800 Bytes
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
import torch
class PCLDataset(torch.utils.data.Dataset):
def __init__(self, tokenizer, input_set):
self.tokenizer = tokenizer
self.texts = input_set['text']
self.labels =input_set['labels']
def collate_fn(self, batch):
texts = []
labels = []
for b in batch:
texts.append(b['text'])
labels.append(b['labels'])
encodings = self.tokenizer(texts, return_tensors='pt', padding=True, truncation=True, max_length=128)
encodings['labels'] = torch.tensor(labels)
return encodings
def __len__(self):
return len(self.texts)
def __getitem__(self, idx):
item = {'text': self.texts[idx],
'labels': self.labels[idx]}
return item