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:
@app.route('/classify', methods=['POST'])
def classify():
try:
data = request.get_json()
text = data.get('text')
if not text:
return jsonify({'error': 'Text is required'}), 400
result = client.nlp.classify(
text=text,
categories=[
'Positive Feedback',
'Negative Feedback',
'Feature Request',
'Bug Report',
'Question'
]
)
return jsonify(result)
except Exception as e:
print(f"Classification error: {e}")
return jsonify({'error': 'Classification failed'}), 500
node app.js
python app.py
# For Positive Feedback
curl -X POST \
http://localhost:3000/classify \
-H 'Content-Type: application/json' \
-d '{"text": "I love your product! It has made my life so much easier."}'
# For Feature Request
curl -X POST \
http://localhost:3000/classify \
-H 'Content-Type: application/json' \
-d '{"text": "It would be great if you could add dark mode to the app."}'
# For Bug Report
curl -X POST \
http://localhost:3000/classify \
-H 'Content-Type: application/json' \
-d '{"text": "The app crashes whenever I try to upload an image."}'
const path = require('path');
// Add this before your routes
app.use(express.static(path.join(__dirname)));
// Add this after your routes
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, 'index.html'));
});
@app.route('/')
def index():
return app.send_static_file('index.html')
# Make sure to create a 'static' folder and put your index.html there