When to use 1 hot encoding with pythorch

I have a multi class classification problem so I am going with Cross entropy I have 12 label: initially categorical labels , but I perform an integer encoding, I was wondering if should I use one hot encoding instead and how that would fit or not my case ? thanks

Hi Oussama!

I can’t think of a good use case in pytorch where one-hot encoding
makes sense. (Of course, if you are using some third-party code
that expects one-hot encoding, then you’ll need it.)

In the case of pytorch’s CrossEntropyLoss, unless you are using
probabilistic values for target (the labels), integer (categorical)
class labels are expected.

So, no, don’t use one-hot encoding. Stick with your “integer encoding.”
That’s what CrossEntropyLoss expects, and it’s a perfectly fine approach.

Best.

K. Frank

1 Like