1
$\begingroup$

I have a Pandas DataFrame which consists of a body of text in 1 row. Each body of text is assigned labels for Category (in 1 row) and a Topic (in a separate row). Example of DataFrame below:

Text Category Topic
cognitive training ... Category A Topic 2
correlation between ... Category F Topic 56

There are 8 Categories with a total of 60 unique Topics. These Topics are not equally shared amongst the Categories, for example Category A can have Topics 1-18 and Category B can have Topics 19-27. A basic diagram has been added below demonstrating the levels.

                     <ROOT>
            ____________|______________________
           /            |        \          \ ...
        Cat A         Cat B      Cat C
      / / | \ \        |  \        | 
     1 2  3  4 5 ...  19  20 ...   28

I would like to know the best approach(s) for generating a Hierarchical Classification where both the Category and Topic are generated in the prediction. So if a new body of text is received both levels can be predicted e.g. Category and Topic.

I have been using TfIdf on the body of text and how next to proceed is troubling me.

from sklearn_hierarchical_classification.classifier import HierarchicalClassifier

Attempting to use this library isnt providing me with both levels as a prediction.

Any help or ideas in implementing such a model would be really appreciated :) Many thanks!

$\endgroup$
2
  • $\begingroup$ In other words, do you want to classify according to the topic's meaning? For instance: "insect" or "bug" goes to "Insect category" and "keyboard" or "computer bug" go to "IT category"? $\endgroup$ Commented Oct 27, 2022 at 17:59
  • $\begingroup$ Hi @NicolasMartin , thanks for your reply. I would like to get both levels of the classification and see the path. So I want to see both the Category and Topic classified. If classifying animals for example and the model predicts "snake" I also want to see the level above that "reptile". To ensure the upper level is correct as well. Does that make sense? $\endgroup$
    – user142080
    Commented Oct 28, 2022 at 7:05

1 Answer 1

1
$\begingroup$

Bert is a model that is able to extract meaning from text and make good classifications, even if the text hasn't been learned before.

That's why you can train a Bert model with many sentences that cover all classes, and then you should be able to classify any text.

https://www.analyticsvidhya.com/blog/2021/12/text-classification-using-bert-and-tensorflow/

https://www.kaggle.com/code/merishnasuwal/document-classification-using-bert

This is the most universal solution adapted to any text.

Here are all text classification models:

https://huggingface.co/models?pipeline_tag=text-classification&sort=downloads

They are mostly built to classify sentiment, but they could classify anything, like this one:

https://huggingface.co/cardiffnlp/roberta-large-tweet-topic-multi-all?text=I%27m+sure+the+%7B%40Tampa+Bay+Lightning%40%7D+would%E2%80%99ve+rather+faced+the+Flyers+but+man+does+their+experience+versus+the+Blue+Jackets+this+year+and+last+help+them+a+lot+versus+this+Islanders+team.+Another+meat+grinder+upcoming+for+the+good+guys

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.