A high-performance REST API for Aspect-Based Sentiment Analysis that processes both individual texts and large-scale CSV datasets using fine-tuned BERT models.
- 🧠 Fine-Tuned BERT trained on MAMS dataset + SpaCy for aspect extraction
- ⚡ Async Processing with Celery workers for bulk CSV analysis
- 🔐 JWT Authentication for secure API access
- 📊 Unified Session System handles both sync text and async file uploads
- 📑 Swagger UI for interactive API testing
graph LR
A[Client] -->|Text/CSV| B[Django API]
B -->|Sync| C[BERT Model]
B -->|Async| D[Redis Queue]
D --> E[Celery Worker]
E --> C
C -->|Results| F[(Database)]
F --> A
Workflow: Text requests → instant analysis | CSV uploads → background processing with progress tracking
| Layer | Technology |
|---|---|
| API | Django REST Framework |
| Queue | Celery + Redis |
| ML | PyTorch + Transformers + SpaCy |
| Auth | JWT (simplejwt) |
| DB | SQLite (dev) / PostgreSQL (prod) |
- Python 3.11+
- Redis 7.x+
- Git
# 1. Clone and navigate
git clone https://github.com/yourusername/absa-api.git
cd absa-api
# 2. Setup virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# 3. Install dependencies
pip install -r requirements.txt
python -m spacy download en_core_web_sm
# 4. Setup database
python manage.py migrate
python manage.py createsuperuser
# 5. Start Redis (in separate terminal)
redis-serverOpen 3 terminals:
# Terminal 1 - API Server
python manage.py runserver
# Terminal 2 - Celery Worker
## Windows
celery -A ABSAapi worker --pool=solo -l info
## Mac/Linux
celery -A ABSAapi worker -l info
# Terminal 3 - Celery Beat (optional)
celery -A ABSAapi beat -l info✅ API Ready: http://127.0.0.1:8000/api
📖 Docs: http://127.0.0.1:8000/api/docs/
The fine-tuned BERT model is required for sentiment analysis. Choose one option:
-
Run train Notebook
jupyter notebook Notebooks/train.ipynb
-
Fine-tune BERT for aspect-based sentiment analysis
-
Save the model to
./models/bert_absa/
- Open the Kaggle notebook ABSA BERT Training and run it
- Enable GPU accelerator in notebook settings
- Run all cells to train the model
- Download the trained model from Kaggle output
- Place in
./models/bert_absa/directory
Model Directory Structure:
models/
└── bert_absa/
├── config.json
├── pytorch_model.bin
└── vocab.txt
Interactive Docs: http://127.0.0.1:8000/api/docs/
| Endpoint | Method | Description | Auth |
|---|---|---|---|
/api/register |
POST | Register a new user | ❌ |
/api/login/ |
POST | Get JWT Bearer Token (for code/apps) | ❌ |
/api-auth/login/ |
GET | Browser Login (Standard HTML Page) | ❌ |
/api/sessions/ |
POST | Analyze text/CSV | ✅ |
/api/sessions/ |
GET | List sessions | ✅ |
/api/sessions/{id}/ |
GET | Get results | ✅ |
/api/sessions/{id}/ |
GET | Get results | ✅ |