Multi-label text classification / cheat sheet

Use this cheat sheet

If the text samples in your dataset can belong to multiple classes.

Example use case

Text emotions

A piece of text can be both positive and caring.
Another piece of text can be both sad and disgusted.

Data preparation

Structure of imported csv

Datasets with text for text classification need to include:

  • 1 column with text to be used as input

  • 1 one-hot encoded column for each Feature, also named label, used as target. That is, either the text sample contains the label or not.

Example:
Each row contains a 1 if the label is present in the text sample and a 0 if it is not.

Text sample Label 1 Label 2 Label 3

Lorem ipsum dolor sit amet, consectetur adipiscing elit.

0

1

1

Uis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.

1

1

0

Dataset view

In the Datasets view, make sure that:

  • The encoding of the Text feature to Text

  • Each Label feature to Binary.
    The 1 is the Positive class.

Create feature set

Create a Feature set with all the label columns to use as the target in your model.

Modeling

Use the Experiment wizard to build a model.

  • Select the Text feature as Input.

  • Select the Feature set as Target.

  • Select Multi-label text classification as Problem type.

Run experiment

When you’ve created an experiment with the Experiment wizard, a ready-to-run model will populate the Modeling canvas.

The only thing left to do is to click Run. You can change the settings but yiu don’t have to.

Run button

Evaluate experiment

In the Evaluation view, you can see how the loss gets lower for each epoch.

Predictions inspection

By default, the predictions from the validation subset at the best epoch are shown.

Select the class Label that you want to inspect. The prediction table, the Confusion matrix, and the ROC Curve will show the performance of the model on the selected Label.

The threshold value allows you to control how the errors made by the model distribute between false positive and false negative.

Deployment

Click New deployment. Select experiment and epoch for deployment.

Click Enable to make the deployment accessible through the Peltarion Deployment API for forward pass queries.

Enable button

Text classifier web app

To make it easier to test your model, we have provided a web app.

Click Open web app and test your deployed model.

Open web app button
Was this page helpful?
YesNo