Getting Value Error while training a model for binary classification While training a sequential model using Keras, Im getting this error

The model summary is shown below

Layer (type)                 Output Shape              Param #   
=================================================================
dense_1 (Dense)              (None, 512)               20480512  
_________________________________________________________________
activation_1 (Activation)    (None, 512)               0         
_________________________________________________________________
dropout_1 (Dropout)          (None, 512)               0         
_________________________________________________________________
dense_2 (Dense)              (None, 512)               262656    
_________________________________________________________________
activation_2 (Activation)    (None, 512)               0         
_________________________________________________________________
dropout_2 (Dropout)          (None, 512)               0         
_________________________________________________________________
dense_3 (Dense)              (None, 2)                 1026      
_________________________________________________________________
activation_3 (Activation)    (None, 2)                 0         
=================================================================


I used the below steps to train the model, for binary classification,

model = Sequential()

model.add(Dense(512, input_shape=(vocab_size,)))
model.add(Activation('relu'))
model.add(Dropout(0.3))

model.add(Dense(512))
model.add(Activation('relu'))

model.add(Dropout(0.3))
model.add(Dense(num_labels))
model.add(Activation('softmax'))


num_labels = 2 for the above code

The error is shown below.

ValueError: Error when checking target: expected activation_3 to have
shape (2,) but got array with shape (1,)
The problem is the shape of y_train. You're defining an output layer of 2 neurons, and only passing labels with a shape of (n_samples, 1). You need to convert this to shape (n_samples, num_labels) and can use keras.utils.to_categorical to do so easily.

The number of neurons in your output layer has to match the second dimension of the label array, so you transform it from one dimensional like this:

[0,1,0,0,0,1]

To two dimensional like this:

[[1,0],
[0,1],
[1,0],
[1,0],
[1,0],
[0,1]]


When you make your predictions, softmax activation will give you a 'probability' for each class like so:

[[0.97,0.03],
[0.85,0.15],
...
]]