[8956d4]: / unimol / data / from_str_dataset.py

Download this file

20 lines (14 with data), 459 Bytes

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
import torch
from functools import lru_cache
from unicore.data import UnicoreDataset
class FromStrLabelDataset(UnicoreDataset):
def __init__(self, labels):
super().__init__()
self.labels = labels
@lru_cache(maxsize=16)
def __getitem__(self, index):
return self.labels[index]
def __len__(self):
return len(self.labels)
def collater(self, samples):
return torch.tensor(list(map(float, samples)))