How to implement hierarchical labeling classification?
For this problem, you need to develop three models:
Model 1- for two main categories
Model 2- for sub-category A
Model 3- For sub-category B

So when you want to predict the result for an unseen data, first you use the Model 1, to find the main category. Based on the prediction and by using an if-else statement, you decide to perform another prediction using Model 2 or Model 3.
Consequently, the Model 1 is a binary classification task, but Model 2&amp;3 are mutli-class classification task. Your networks may look like this:
Model 1:
model1 = Sequential()
model1.add(Dense(60, input_dim=X.shape[1], activation='relu'))
...
model1.add(Dense(1, activation='sigmoid'))
model1.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])

Model 2 &amp; 3:
model2 = Sequential()
model2.add(Dense(8, input_dim=X.shape[1], activation='relu'))
...
model2.add(Dense(n_subcats, activation='softmax'))
model2.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])

Just don't forget to use correct y (label) for main and sub-categories for each model.