Skip to content

Hierarchical Classification

Hierarchical classification is a machine learning approach that involves organizing classes or categories into a hierarchical structure. It is particularly useful when dealing with complex classification problems that have a natural hierarchy or taxonomy, where classes can be grouped into broader categories and subcategories. In this example, we will demonstrate how to use Anote to perform hierarchical text classification on a dataset of Amazon reviews. Our goal is to classify each review into a hierarchical structure of categories: Category, Sub-Category, and Sub-Sub-Category.

Dataset

The dataset consists of Amazon reviews. Here are a few examples of the Amazon reviews:

Review
Great product, really enjoyed using it.
The quality was poor and it broke after a few uses.
Fast shipping, item as described. Would buy again.
Not as described. Very disappointed.
Excellent customer service.
The size was too small, even though I followed the size chart.
The color was not as shown in the picture.
Very comfortable and fits perfectly.
The sound quality is amazing.
The battery life is not as good as advertised.
It stopped working after a month.
It's a bit expensive, but worth every penny.
The fabric is soft and comfortable.
It's easy to use and setup.
The picture quality is excellent.
It's not worth the price.

These Amazon reviews represent different opinions expressed by customers. We will classify each review into the following hierarchical structure:

Category Sub-Category Sub-Sub-Category
Clothing Outerwear Jackets
Clothing Outerwear Coats
Clothing Outerwear Sweaters
Clothing Dresses Casual
Clothing Dresses Formal
Clothing Dresses Cocktail
Clothing Shirts T-Shirts
Clothing Shirts Jerseys
Clothing Shirts Polos
Clothing Shirts Suits
Clothing Pants Jeans
Clothing Pants Leggings
Clothing Shoes Sneakers
Clothing Shoes Boots
Clothing Shoes Cleats
Clothing Shoes Sandals
Electronics Computers Laptops
Electronics Computers Desktops
Electronics Computers Tablets
Electronics Audio Headphones
Electronics Audio Speakers
Electronics Audio Soundbars
Electronics Phone Android
Electronics Phone Pixel
Electronics Phone Galaxy
Electronics Camera DSLR
Electronics Camera Mirrorless
Electronics Camera Point and Shoot
Electronics TV LED
Electronics TV OLED
Electronics TV QLED

Using Anote

Watch the video

To perform hierarchical text classification on these Amazon reviews, we can follow these steps using Anote:

Upload Data: To initiate the process, we begin by uploading our text data, which comprises Amazon reviews, onto our platform, Anote. Anote conveniently accepts a range of file formats, including CSV, TXT, and JSON. It is recommended to prepare two separate files: one containing the complete set of reviews and another exclusively containing the taxonomy that are intended for classification by the model. When proceeding to the upload page, kindly ensure that you upload only the file containing the reviews. Upload the CSV in Unstructured format, choose the NLP task of Text Classification, and choose the per line decomposition.

tweets tweets tweets

Customize Categories: In the annotation interface, set up the hierarchical structure of categories based on the list provided above. Customize the category, sub-category, and sub-sub-category labels in Anote's configuration settings. To upload taxonomy, when you go to customize tag, you should initially see this page:

tweets

Now you can upload the taxonomy file that you preparied before. You can do this by clicking the Add From Taxonomy button:

tweets

After the taxonomy file is uploaded, click the Add Label Column button then choose the column of the categories. You can nest subcategories by adding additional labels below the initial selected label. Lastly, click the Create Categories button when finished.

tweets tweets

Annotate Reviews: Begin the annotation process. Anote provides an intuitive interface to view each movie review and select the appropriate category, sub-category, and sub-sub-category from the hierarchical structure. Go through the reviews, label a few rows by choosing a category and click the Confirm button, and assign the correct labels for each level of the hierarchy.

tweets

Export Results: Once the annotation process is complete, export the annotated results from Anote as a CSV.

tweets