What's wrong with output layer and loss function?

I have multi-class dataset and labels values range is 5 to 9. I am using SoftMax function, and sparse_categorical_crossentropy loss function.

When I give 10 units in the dense layer it works fine, although data has only 5 classes.
Why it only works with 10 but not with 5 units in output layer?
How to get it done for 5 units in output layer?

Thank you!

It only works with ten because your labels are 5 to 9 so the 9 requires the dense layer to have 10 outputs. If you wanted to change this you would have to lower your labels to a range of 0 to 4.

1 Like

Thank you… How to do it?

Where do you define your labels? You could just subtract 5 from each label.