Dense layer with 5 units (since there are 5 categories) with a softmax activation

I have the following code:

def fit_tokenizer(train_sentences, num_words, oov_token):
    tokenizer = Tokenizer(num_words=num_words, oov_token=oov_token)

When I assign the units=5 for my last Dense layer as follows:

model = tf.keras.Sequential([
        tf.keras.layers.Embedding(num_words, embedding_dim, input_length=maxlen),
        tf.keras.layers.GlobalAveragePooling1D(),
        tf.keras.layers.Dense(units=5, activation='softmax')
    ])

Then I obtain the following error:

However, when I change it units=1 in my Dense layer, it starts training (it is incorrect I guess?!!).
What am I doing wrong?
Cheers,

Try comparing your output shape with your input shape. Are they the same?

EDIT: My fingers wrote input shape but my head was thinking about labels, which is what needs be compatible. My bad.

@mrgransky Please fix the loss function of the model. You’ll find this lab helpul.

I fixed the problem by changing the loss function to [code removed - moderator] since we are dealing with labels to be provided as integers.
Earlier I had [code removed - moderator] which mainly expects the labels to be provided in a one_hot representation.
Thanks for the heads up!