Dual Model Architecture
Relevant source files
The following files were used as context for generating this wiki page:
The sentiment analysis system employs a dual-model architecture to provide both historical and real-time analysis, leveraging the distinct strengths of a Support Vector Machine (SVM) model and Google's Gemini AI. This hybrid approach ensures optimal performance, cost-effectiveness, and contextual accuracy across different use cases within the dashboard. The SVM model is used for analyzing a static, pre-labeled dataset, while the Gemini AI model is used for processing raw, live comments from YouTube.
This architecture was introduced in version 5.0.0 to provide a more robust and versatile analysis capability.
Sources: DUAL_MODEL_ARCHITECTURE.md, README.md, CHANGELOG.md:7-8
Architecture Overview
The system is logically divided into two parallel tracks: the Static Dashboard powered by the SVM model and the Live Dashboard powered by the Gemini AI. Each track is tailored to a specific type of data and user need.
This diagram illustrates the high-level separation of the two models and their respective data sources.
Static Dashboard - SVM Model
The static analysis component is designed for fast, consistent analysis of a large, historical dataset of over 19,000 comments. It is ideal for research, batch processing, and displaying aggregated performance metrics.
Sources: DUAL_MODEL_ARCHITECTURE.md:18-22, dashboard-next/app/model/page.tsx:135-138
Data Source & Preprocessing
The SVM model is trained on a pre-labeled and cleaned dataset. The preprocessing pipeline involves cleaning, tokenization, normalization, and stemming using the Sastrawi library to prepare the Indonesian text for feature extraction.
Sources: DUAL_MODEL_ARCHITECTURE.md:20-22, dashboard-next/app/model/page.tsx:153-156
Model & Implementation
The core of the static analysis is a Support Vector Machine (SVM) classifier. It uses Term Frequency-Inverse Document Frequency (TF-IDF) for vectorization, converting text into a numerical format.
Key model parameters are:
- Algorithm: Support Vector Machine (SVM)
- Vectorization: TF-IDF
- Features: 2,000 optimized features
- Kernel: Linear
- Regularization: C=1.0
Sources: dashboard-next/app/model/page.tsx:128-149, DUAL_MODEL_ARCHITECTURE.md:25-32
SVM Analysis Pipeline
The following diagram shows the data flow for the SVM model, from text input to sentiment prediction.
Sources: DUAL_MODEL_ARCHITECTURE.md:104-118
Performance
The model's performance is tracked on the Model Performance page of the dashboard, with the following key metrics derived from the 80/20 train/test split:
| Metric | Score |
|---|---|
| Accuracy | 89.4% |
| F1-Score (Weighted Avg) | 91% |
| Precision (Weighted Avg) | 0.89 |
| Recall (Weighted Avg) | 0.89 |
| Dataset Size | 19,228 comments |
Sources: dashboard-next/app/model/page.tsx:34-48, 89-93, DUAL_MODEL_ARCHITECTURE.md:86-92
Use Cases & Pages
The SVM model is primarily used for historical analysis where speed and consistency are paramount.
- Use Cases: Historical sentiment analysis, batch processing, research, performance benchmarking.
- Dashboard Pages:
/(Main Dashboard)/analytics(Analytics)/dataset(Dataset Analysis)/model(Model Performance)
Sources: DUAL_MODEL_ARCHITECTURE.md:41-54, dashboard-next/README.md:7-13
Live Dashboard - Gemini AI
The live analysis component is designed for contextual understanding of raw, real-time data. It uses Google's Gemini AI to handle nuanced language, slang, and provide reasoning for its predictions.
Sources: README.md:18-23, DUAL_MODEL_ARCHITECTURE.md:56-58
Data Source
The model processes raw, unprocessed comments fetched in real-time from the YouTube Data API. Before analysis, comments pass through a "Smart Comment Filter" to remove spam and irrelevant content.
Sources: DUAL_MODEL_ARCHITECTURE.md:60-62, dashboard-next/app/api/live-comments/route.ts:169-173
Model & Implementation
The system uses a Google Gemini model, accessed via a backend API running on http://localhost:8000. The frontend Next.js application makes requests to its own API route (/api/live-comments), which in turn calls the Gemini backend.
A key feature is the fallback mechanism. If the Gemini API is unavailable or times out, a local fallback function (analyzeSentimentFallback) is used. This function employs a unified lexicon to ensure scoring remains consistent with the primary model's logic.
Sources: dashboard-next/app/api/live-comments/route.ts:4-7, 202-225, README.md:40-42
Live Analysis Pipeline
This sequence diagram illustrates the complete flow from a user viewing the live comments page to seeing the AI-analyzed sentiment.
Use Cases & Pages
The Gemini AI model is used when contextual understanding of fresh, unstructured data is critical.
- Use Cases: Real-time sentiment monitoring, social media listening, live event tracking.
- Dashboard Pages:
/live-comments(Live Comments)/realtime(Live Analysis)
Sources: DUAL_MODEL_ARCHITECTURE.md:75-84, dashboard-next/README.md:38-47
Model Comparison
The two models are chosen to be complementary, with each excelling in different areas.
| Aspect | SVM Model | Gemini AI |
|---|---|---|
| Data Type | Pre-labeled, cleaned | Raw, real-time |
| Training | Custom dataset | Pre-trained LLM |
| Speed | <1ms per comment (local) | 1-2s per comment (API) |
| Accuracy | 87.5% (domain-specific) | 95%+ (general) |
| Context | Limited | Excellent |
| Reasoning | No | Yes |
| Cost | Free | API quota |
| Offline | Yes | No |
Sources: README.md:26-35, DUAL_MODEL_ARCHITECTURE.md:86-98
Conclusion
The dual-model architecture provides a flexible and robust sentiment analysis system. It combines the speed and consistency of a classic SVM model for historical data with the contextual intelligence and adaptability of a modern LLM like Gemini for live, unstructured data. This approach covers a wider range of use cases, mitigates risks such as API costs and downtime (via the fallback mechanism), and ultimately delivers more accurate and relevant insights for different analytical needs.
Sources: DUAL_MODEL_ARCHITECTURE.md:152-164