ptrblck:

class MyDataset(Dataset):
    def __init__(self, data, window_size):
        self.data = data
        self.window_size = window_size
        
    def __getitem__(self, index):
        x = self.data[index:index+self.window_size]
        return x
    
    def __len__(self):
        return len(self.data) - self.window_size + 1

data = torch.arange(100).view(100, 1).float()
dataset = MyDataset(data, window_size=10)
loader = DataLoader(dataset, batch_size=2, shuffle=False)

for batch in loader:
    print(batch)



Thanks a lot for the super fast reply! IMHO, your answers on this forum are the single best learning resource for PyTorch beginners out there… 
I was hoping for a solution that loads consecutive seq’s within batch, while randomly splitting batches to train-test subsets, but I guess this may over-complicate things and is not strictly necessary. Instead, I’ve tried to adapt your suggestion for the common case of non-overlapping sequences (e.g. as in the PyTorch tutorial on seq-to-seq with Transformers mention above):
class NoOverlapDataset(Dataset):
    def __init__(self, data, window_size):
        self.data = data
        self.window_size = window_size

    def __getitem__(self, index):
        seq_i = index * self.window_size
        x = self.data[seq_i : seq_i + self.window_size]
        return x

    def __len__(self):
        return len(self.data) // self.window_size

Dose that make sense/look correct?