TransWikia.com

How to implement hierarchical labeling classification?

Data Science Asked by chacid on April 23, 2021

I am currently working on the task of eCommerce product name classification, so I have categories and subcategories in product data. I noticed that using subcategories as labels delivers worse results (84% acc) than categories (94% acc). But subcategories are more precise as labels, what’s important for the whole task. And then I got an idea to first do category classification and then based on the results continue with subcategories within the predicted category.

The problem here is that I do not know how to approach this problem/define network architecture. Any hints on the neural networks, how to deal with it?

Currently I defined network like this:

model = Sequential()
model.add(Dense(400, input_shape=(FEATURE_NUM,)))
model.add(Activation('relu'))
model.add(Dropout(0.5))
model.add(Dense(num_classes))
model.add(Activation('softmax'))

2 Answers

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&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 & 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.

Answered by Mehdi on April 23, 2021

What you are trying to address is a problem of hierarchical classification in contrast to the flat classification which we are very familiar with.

Some work has already been done to address such problems and it has been shown that single unified model outperforms layered architecure of multiple flat classifiers for individual tasks (e.g. in your case category and sub-category). While, I do not have any reference to share for the exact same problem you are dealing with, however, here is a link to a paper dealing with hierarchical classification of product images A Unified Model with Structured Output for Fashion Images Classification.

Answered by jdsuryap on April 23, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP