Intent & Sentiment Analysis
Relevant source files
The following files were used as context for generating this wiki page:
The Intent & Sentiment Analysis system provides the AI Assistant with the ability to understand user goals and emotional context from natural language input. This system is a core component of the Python AI Service, utilizing specialized machine learning models to classify user messages into specific categories (e.g., command, question, note, greeting) and emotional states (positive, negative, neutral).
This module enables the platform to provide context-aware responses and tag conversation history with analytical metadata, which is subsequently persisted in the database for long-term user profile management.
Sources: README.md:38-42, backend/services/ml_service.py:7-15
System Architecture
The analysis follows a multi-tier flow where the Node.js orchestration service receives user input, proxies the request to the Python Flask backend, and receives enriched metadata along with the AI response.
Data Flow Overview
The following diagram illustrates how intent and sentiment data move from the user interface through the various backend services.
The Node.js service calls the Python /generate endpoint, which internally triggers the ML services to analyze the prompt before returning the final response.
Sources: Ai-Assistant-v2/auth-service/server.js:241-255, backend/services/ml_service.py:75-85
Intent Detection
The IntentDetector is responsible for identifying the user's primary goal. It categorizes input into predefined classes to help the system determine if the user is asking a question, giving a command, or simply greeting the assistant.
Key Components
- IntentDetector Class: Orchestrates the prediction and confidence scoring for text classification.
- Predict Function: Returns the classified label (e.g., 'question', 'command').
- Confidence Scoring: Provides a numerical value indicating the reliability of the classification.
| Feature | Description |
|---|---|
| Supported Categories | Command, Question, Note, Greeting |
| Input | Raw text string from user |
| Output | Object containing intent, confidence, and original text |
Sources: backend/services/ml_service.py:12-25, README.md:38-42
Sentiment Analysis
The SentimentAnalyzer evaluates the emotional tone of user messages. It utilizes a specialized model configuration to map text to three primary labels: positive, negative, and neutral.
Model Configuration
The sentiment system is configured via SENTIMENT_CONFIG, which points to a specific RoBERTa-based model optimized for social media and conversational text.
| Setting | Value |
|---|---|
| Model Name | cardiffnlp/twitter-roberta-base-sentiment-latest |
| Labels | negative, neutral, positive |
| Max Length | 512 tokens |
| Device | CPU (Default) |
Sources: backend/ml_config/model_config.py:31-37
Analysis Logic
The MLService wraps the analyzer to provide a consistent interface for the REST API.
def analyze_sentiment(self, text):
result = self.sentiment_analyzer.analyze(text)
return {
'sentiment': result['label'],
'score': result['confidence'],
'text': text
}
Sources: backend/services/ml_service.py:27-41
Integration and API Endpoints
The Intent and Sentiment analysis features are exposed through both dedicated endpoints for batch processing and as part of the primary chat orchestration.
Python ML Routes
The backend/modules/ml/routes.py file defines specialized endpoints for standalone analysis:
| Endpoint | Method | Description |
|---|---|---|
/intent | POST | Takes {"text": "..."} and returns intent classification. |
/sentiment | POST | Takes {"text": "..."} and returns sentiment score. |
/analyze | POST | Performs comprehensive analysis on a list of messages. |
/batch | POST | Processes multiple text strings in a single request. |
Sources: backend/modules/ml/routes.py:8-106
Orchestration and Persistence
When a user sends a message through the chat interface, the Node.js service performs the following sequence:
The analyzed metadata is stored within the Conversation model in MongoDB, allowing the UI to display intent and sentiment tags (e.g., a green "positive" tag or a purple "question" tag) next to user messages.
Sources: ai-assistant-react/src/components/Chat/ChatInterface.jsx:114-118, Ai-Assistant-v2/auth-service/server.js:259-265
Summary
The Intent & Sentiment Analysis module transforms raw text into structured data. By leveraging a combination of local ML models (Intent) and pre-trained RoBERTa models (Sentiment), the platform provides deep insight into user behavior. This data is critical for the assistant's ability to maintain contextually appropriate conversations and for the system to track user satisfaction over time.