Skip to content

mihirzoting/sentiment-analyzer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

SentimentAI β€” Final Year Project

A production-ready, deployable sentiment analysis system with ML backend, REST API, and React frontend.

Tests Python React FastAPI Docker


πŸ“‹ Project Overview

SentimentAI is a full-stack sentiment analysis application that classifies text as Positive, Negative, or Neutral and additionally detects 8 emotions (joy, anger, sadness, fear, surprise, disgust, trust, anticipation) with confidence scores and keyword extraction.

Tech Stack

Layer Technology
Backend API FastAPI (Python)
ML Model Hybrid Lexicon + Rule Engine
Frontend React 18 + Recharts
Containerization Docker + Docker Compose
CI/CD GitHub Actions
Deployment Render.com / Fly.io / Railway

πŸ—οΈ Project Structure

sentiment-analyzer/
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ main.py              # FastAPI application & routes
β”‚   └── requirements.txt
β”œβ”€β”€ model/
β”‚   └── predictor.py         # ML prediction engine
β”œβ”€β”€ frontend/
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ App.jsx           # Router & layout
β”‚   β”‚   β”œβ”€β”€ pages/
β”‚   β”‚   β”‚   β”œβ”€β”€ Analyze.jsx   # Single text analysis
β”‚   β”‚   β”‚   β”œβ”€β”€ BatchAnalyze.jsx  # Bulk analysis
β”‚   β”‚   β”‚   └── Dashboard.jsx # Charts & metrics
β”‚   β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”‚   β”œβ”€β”€ ResultCard.jsx
β”‚   β”‚   β”‚   └── HistoryPanel.jsx
β”‚   β”‚   └── utils/api.js      # API client
β”‚   β”œβ”€β”€ Dockerfile
β”‚   └── package.json
β”œβ”€β”€ tests/
β”‚   └── test_api.py           # 17 unit + integration tests
β”œβ”€β”€ .github/workflows/ci.yml  # GitHub Actions
β”œβ”€β”€ Dockerfile                # Backend Docker image
β”œβ”€β”€ docker-compose.yml        # Full stack orchestration
β”œβ”€β”€ render.yaml               # Render.com deployment
└── fly.toml                  # Fly.io deployment

πŸš€ Quick Start

Option A β€” Run locally (Python)

# Clone & install backend
git clone https://github.com/yourname/sentiment-analyzer
cd sentiment-analyzer
pip install -r backend/requirements.txt

# Start backend
uvicorn backend.main:app --reload --port 8000

# In a new terminal β€” start frontend
cd frontend
npm install --legacy-peer-deps
npm start

Open http://localhost:3000

Option B β€” Docker Compose (recommended)

docker-compose up --build

πŸ”Œ API Reference

POST /api/analyze

Analyze a single text.

Request:

{
  "text": "I absolutely love this product!",
  "include_details": true
}

Response:

{
  "text": "I absolutely love this product!",
  "sentiment": "Positive",
  "confidence": 0.912,
  "scores": { "positive": 0.87, "negative": 0.06, "neutral": 0.07 },
  "emotions": { "joy": 1.0, "anticipation": 0.5 },
  "keywords": ["love"],
  "processing_time_ms": 2.1,
  "timestamp": "2024-01-15T10:30:00"
}

POST /api/analyze/batch

Analyze up to 50 texts at once.

Request:

{ "texts": ["I love this!", "This is terrible.", "Okay I guess."] }

GET /health

Service health check.

GET /api/stats

Usage statistics.


🧠 Model Architecture

The prediction engine uses a hybrid approach:

  1. Tokenization β€” lowercasing, punctuation normalization
  2. Lexicon scoring β€” 100+ positive/negative words with sentiment weights
  3. Negation handling β€” detects NOT/NEVER patterns and inverts scores
  4. Intensifier amplification β€” "very", "extremely" etc. boost scores by 1.2–1.5Γ—
  5. Sigmoid normalization β€” maps raw scores to [0,1] probability distributions
  6. Emotion detection β€” matches against 8 emotion lexicons
  7. Keyword extraction β€” identifies top sentiment-bearing terms

Upgrade path: Replace predictor.py's predict() with HuggingFace cardiffnlp/twitter-roberta-base-sentiment for state-of-the-art accuracy with zero API changes.


πŸ§ͺ Testing

# Run full test suite (17 tests)
pytest tests/ -v

# With coverage
pytest tests/ --cov=backend --cov=model --cov-report=html

Test categories:

  • TestPredictor β€” 8 model unit tests (positive/negative/neutral/negation/intensifier)
  • TestAPI β€” 9 integration tests (all endpoints, validation, batch)

☁️ Deployment

Deploy to Render.com (FREE)

  1. Push to GitHub
  2. Go to render.com β†’ New β†’ Blueprint
  3. Connect your repo β€” Render will auto-detect render.yaml
  4. Set REACT_APP_API_URL in frontend env to your backend URL

Deploy to Fly.io

# Install flyctl
curl -L https://fly.io/install.sh | sh

# Deploy backend
fly launch
fly deploy

# Set env
fly secrets set ENV=production

Deploy to Railway

# Install Railway CLI
npm install -g @railway/cli

railway login
railway new
railway up

πŸ“Š Features

  • βœ… Single text sentiment analysis with confidence scores
  • βœ… Batch analysis (up to 50 texts) with CSV export
  • βœ… 8-category emotion detection
  • βœ… Sentiment keyword extraction
  • βœ… Real-time dashboard with charts (Recharts)
  • βœ… Request history panel
  • βœ… Interactive API docs (Swagger UI at /api/docs)
  • βœ… 17 automated tests (unit + integration)
  • βœ… Docker + Docker Compose support
  • βœ… GitHub Actions CI/CD pipeline
  • βœ… One-click deploy configs for Render, Fly.io, Railway
  • βœ… Sub-5ms response times
  • βœ… CORS-enabled for any frontend origin

πŸ“š Report Talking Points

Problem Statement

Sentiment analysis is critical for businesses to understand customer feedback at scale. Manual analysis of thousands of reviews or social posts is infeasible.

Methodology

Hybrid lexicon-based approach chosen for: zero training data requirement, interpretable decisions, sub-millisecond inference, and free deployment. Rule-based negation and intensifier handling addresses key weaknesses of pure bag-of-words models.

Results

  • 17/17 automated tests passing
  • Correct classification of positive, negative, and neutral examples
  • Proper negation inversion ("not good" β†’ Negative)
  • Emotion detection across 8 Plutchik-model categories

Future Work

  • Replace lexicon engine with fine-tuned RoBERTa transformer
  • Add user authentication + persistent history
  • Multilingual support
  • Browser extension for real-time page analysis

πŸŽ“ Academic References

  1. Taboada, M. et al. (2011). Lexicon-based methods for sentiment analysis. Computational Linguistics.
  2. Plutchik, R. (1980). A general psychoevolutionary theory of emotion. Academic Press.
  3. Hutto, C. & Gilbert, E. (2014). VADER: A parsimonious rule-based model for sentiment analysis. ICWSM.
  4. Liu, B. (2012). Sentiment analysis and opinion mining. Synthesis Lectures on HLT.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors