Loading...
Create a custom Dataset class that generates data on-the-fly instead of storing it all in memory.
For large datasets, storing everything in memory isn't practical. PyTorch's Dataset interface lets you generate or load data on demand by implementing three methods: init, len, and getitem.
Create a class SequenceDataset that generates sequential data. For index i, it should return:
The class must accept a size parameter that determines how many samples it contains.
Each sample should be a tuple of (feature_tensor, label_tensor).
features=[[1.0, 2.0], [3.0, 4.0]], labels=[0, 1]
Dataset with 2 samples, dataset[0] returns (tensor([1., 2.]), tensor(0))
We create a Dataset class that stores features and labels and returns them as tensors