Next Step
Step 7: Adding Multi-Label Classification
Sometimes text could belong to multiple categories. Let's update our classifier to support multi-label classification:
For JavaScript
app.post('/classify-multi', async (req, res) => {
try {
const { text } = req.body;
if (!text) {
return res.status(400).json({ error: 'Text is required' });
}
const result = await client.nlp.classify({
text,
categories: [
'Positive Feedback',
'Negative Feedback',
'Feature Request',
'Bug Report',
'Question'
],
advanced: {
contextAwareness: true,
sensitivityLevel: 0.7,
minConfidence: 0.3,
multiLabel: true
}
});
return res.json(result);
} catch (error) {
console.error('Classification error:', error);
return res.status(500).json({ error: 'Classification failed' });
}
});For Python
Step 8: Batch Processing
For processing multiple texts at once:
For JavaScript
For Python
Conclusion
Congratulations! You've built a text classification system using Invictus AI. This system can automatically categorize customer feedback, which can help your team prioritize and respond to feedback more efficiently.
Next Steps
Explore Custom Models to train a classifier on your own data
Learn how to implement Sentiment Analysis alongside classification
Check out our API Reference for more advanced options# Text Classification Tutorial
Introduction
This tutorial will guide you through building a text classification system using Invictus AI. By the end, you'll have a working application that can automatically categorize text into predefined categories.
Prerequisites
An Invictus AI account with an API key
Basic understanding of JavaScript or Python
Installed the Invictus AI SDK (see Installation)
Step 1: Set Up Your Project
First, let's create a new project and install the required dependencies.
For JavaScript
Create a new file called app.js:
For Python
Create a new file called app.py:
Step 2: Define Your Categories
For this tutorial, we'll build a classifier that categorizes customer feedback into the following categories:
Positive Feedback
Negative Feedback
Feature Request
Bug Report
Question
Step 3: Create the Classification Endpoint
For JavaScript
Add the following code to your app.js file:
For Python
Add the following code to your app.py file:
Step 4: Test Your Classifier
Start your server:
For JavaScript
For Python
Now, let's test our classifier with some sample texts:
Step 5: Building a Simple Front-End (Optional)
Let's create a simple HTML form to test our classifier.
Create a new file called index.html:
For JavaScript
Update your app.js to serve the HTML file:
For Python
Update your app.py to serve the HTML file:
Step 6: Enhancing the Classifier
For more accurate classification, you can use Invictus AI's advanced configuration options: