# ValueError: labels.shape must equal logits.shape except for the last dimension. Received: labels.shape=(880,) and logits.shape=(16, 3)

This is my multiclass neural network model.

# We declared a function for creating a model.
def build_model1_two_hidden_layers():
model = Sequential()

# Input layer => input_shape must be explicitly designated

# Output layer => output dimension = 1 since it is a regression problem

# Activation: sigmoid, softmax, tanh, relu, LeakyReLU.
# Optimizer: SGD, Adam, RMSProp, etc.
# https://www.tensorflow.org/api_docs/python/tf/keras/optimizers
learning_rate = 0.0001
model.compile(
optimizer=optimizer1,
loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True),
metrics=['accuracy']
)
return model


Currently, I am not adding any hidden layer , just want to test the model withou hidden layers first.However , I have an assumption that the model recognize my output layer as hidden layer.

This is my sample data input.

SEX AGE        MENTAL DIS   HISTORY     SUIC        HISTORY     LIVING      ECONOMIC    SUIC RISK   ANXIETY STATE   ANXIETY TRAIT
0.510342       2.133002                 -0.605015   -0.645996   0.417973    0.429160    -1.533806   -1.690477      -1.867256


This is my error

ValueError: labels.shape must equal logits.shape except for the last dimension. Received: labels.shape=(880,) and logits.shape=(16, 3)

I think 880 is my size of dataset and 16 is the perceptrons for the input layer and 3 is the perceptron for output layer. How to rectify this error?

• We'd need more info, you've shown us one datapoint but did not mention which are the features and which is the response variable. I could see a couple of mistakes in the code that you have presented, but it's difficult to correct it when you don't know the entire premise. Also, there's inconsistency in the comment and code. Jun 13 at 7:57