Hi,
label or target has to be LongTensor not Float.



 Prajin_Khadka:

y = torch.LongTensor(batch_size,1).random_() % nb_digits


Here, target is float and you need to convert it to long using .long()



 Prajin_Khadka:

target = target.unsqueeze(-1) -------> target = target.unsqueeze(-1).long()


PS. it would be great if you could use more descriptive title such as onehot matrix generation using scatter_, it help people to interact with questions easier.
Bests