Search code examples
tensorflowclassificationmnistone-hot-encoding

Do you always need to one-hot encode if you have classification task


I’m really new in deep learning and I came across with MNIST dataset problem.

So my question is when you have a classification task are you supposed to do one hot encoding before feeding it to neural network?


Solution

  • No you have a number of options based on the loss you select in compiling your model. Typical you set the loss in model.compile to categorical_cross_entropy if you have one hot encoded your labels. However you can encode your labels as integers and use sparse_categorical_crossentropy as you loss function.