PyTocrh way for one-hot-encoding multiclass target variable

You could use this code snippet to transform your class indices into a one-hot encoded target:

target = torch.randint(0, 10, (10,))
one_hot = torch.nn.functional.one_hot(target)
30 Likes