Solved by ptrblck in post #2 
              
              
                You could just sample another index which is different to the one you are getting in __getitem__(self, index) and return this negative sample. 
Something like this should work: 
class MyDataset(Dataset):
    def __init__(self):
        self.data = torch.randn(100, 1)
        
    def __getitem__(sel…