Thank you much for your detailed response!
Can you elaborate on the last block of code beginning at
# Generate a batch of 4 pairs i,j

Does this code block replace the nested for loop?
And what is the significance of the pairs, just an example? Or will this sample large batches of data?
i = torch.LongTensor([1, 3, 4, 5])
j = torch.LongTensor([2, 4, 6, 7])

Thanks @albanD!