Update README to be minimal
Browse files
README.md
CHANGED
|
@@ -1,281 +1,37 @@
|
|
| 1 |
-
#
|
| 2 |
|
|
|
|
| 3 |
|
|
|
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
| Task | Output | Model |
|
| 8 |
-
|------|--------|-------|
|
| 9 |
-
| Officer Routing | Most suitable officer from 8 officers | SVM (RBF) |
|
| 10 |
-
| Priority Prediction | High / Medium / Low | Random Forest |
|
| 11 |
-
| ETA Prediction | Estimated resolution time in days | Gradient Boosting Regressor |
|
| 12 |
-
| Similarity Search | Top-K past similar complaints | Cosine / FAISS vector search |
|
| 13 |
-
|
| 14 |
-
> ✅ **No external APIs. Fully offline. Multilingual.**
|
| 15 |
-
|
| 16 |
-
---
|
| 17 |
-
|
| 18 |
-
## 📁 Project Structure
|
| 19 |
-
|
| 20 |
-
```
|
| 21 |
-
complaint-routing-system/
|
| 22 |
-
├── data/
|
| 23 |
-
│ ├── generate_data.py # Synthetic multilingual complaint generator
|
| 24 |
-
│ └── synthetic_complaints.csv # 800 labelled complaints (auto-generated)
|
| 25 |
-
│
|
| 26 |
-
├── models/
|
| 27 |
-
│ ├── train.py # End-to-end training pipeline
|
| 28 |
-
│ └── saved/ # Trained model artifacts
|
| 29 |
-
│ ├── officer_classifier.pkl
|
| 30 |
-
│ ├── priority_classifier.pkl
|
| 31 |
-
│ ├── eta_regressor.pkl
|
| 32 |
-
│ ├── embedding_engine.pkl
|
| 33 |
-
│ ├── vector_store.pkl
|
| 34 |
-
│ ├── label_encoders.pkl
|
| 35 |
-
│ ├── metrics.json
|
| 36 |
-
│ └── evaluation_report.json
|
| 37 |
-
│
|
| 38 |
-
├── inference/
|
| 39 |
-
│ ├── embedding_engine.py # TF-IDF+SVD (offline) or sentence-transformers
|
| 40 |
-
│ ├── vector_store.py # NumPy cosine or FAISS IndexFlatIP
|
| 41 |
-
│ └── engine.py # Core inference engine (load + predict)
|
| 42 |
-
│
|
| 43 |
-
├── audio_video/
|
| 44 |
-
│ └── transcriber.py # Whisper-based offline ASR (audio + video)
|
| 45 |
-
│
|
| 46 |
-
├── app/
|
| 47 |
-
│ ├── cli.py # Command-line interface
|
| 48 |
-
│ └── web_app.py # Gradio web UI
|
| 49 |
-
│
|
| 50 |
-
├── evaluation/
|
| 51 |
-
│ └── evaluate.py # Full evaluation suite (all 4 tasks)
|
| 52 |
-
│
|
| 53 |
-
├── requirements.txt
|
| 54 |
-
└── README.md
|
| 55 |
-
```
|
| 56 |
-
|
| 57 |
-
---
|
| 58 |
-
|
| 59 |
-
## ⚡ Quick Start
|
| 60 |
-
|
| 61 |
-
### 1. Install dependencies
|
| 62 |
-
|
| 63 |
-
```bash
|
| 64 |
-
# Core (required)
|
| 65 |
-
pip install scikit-learn numpy pandas scipy joblib
|
| 66 |
-
|
| 67 |
-
# Embedding upgrade — multilingual, ~120 MB download (highly recommended)
|
| 68 |
-
pip install sentence-transformers
|
| 69 |
-
|
| 70 |
-
# Web UI (optional)
|
| 71 |
-
pip install gradio
|
| 72 |
-
|
| 73 |
-
# Audio/Video transcription (optional — local Whisper model, NOT the API)
|
| 74 |
-
pip install openai-whisper
|
| 75 |
-
sudo apt install ffmpeg # for video audio extraction
|
| 76 |
-
```
|
| 77 |
-
|
| 78 |
-
### 2. Generate training data
|
| 79 |
|
|
|
|
| 80 |
```bash
|
| 81 |
-
|
| 82 |
-
|
| 83 |
```
|
| 84 |
|
| 85 |
-
|
| 86 |
|
| 87 |
-
|
| 88 |
-
python models/train.py
|
| 89 |
-
# → trains SVM, Random Forest, GBR, builds vector store
|
| 90 |
-
# → saves all artifacts to models/saved/
|
| 91 |
-
```
|
| 92 |
-
|
| 93 |
-
### 4. Run inference
|
| 94 |
|
|
|
|
| 95 |
```bash
|
| 96 |
-
# Interactive CLI
|
| 97 |
-
python app/cli.py
|
| 98 |
-
|
| 99 |
-
# Direct text
|
| 100 |
-
python app/cli.py --text "Pothole on MG Road near hospital causing accidents. URGENT!"
|
| 101 |
-
|
| 102 |
-
# Audio file
|
| 103 |
-
python app/cli.py --audio path/to/complaint.mp3
|
| 104 |
-
|
| 105 |
-
# Video file
|
| 106 |
-
python app/cli.py --video path/to/complaint.mp4
|
| 107 |
-
|
| 108 |
-
# JSON output
|
| 109 |
-
python app/cli.py --text "Sewage overflow near park" --json
|
| 110 |
-
|
| 111 |
-
# Web UI (requires gradio)
|
| 112 |
python app/web_app.py
|
| 113 |
```
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
``
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
``
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
▼
|
| 130 |
-
┌──────────────────────┐
|
| 131 |
-
│ Modality Detection │
|
| 132 |
-
└──────────┬───────────┘
|
| 133 |
-
│
|
| 134 |
-
┌───────┴────────┐
|
| 135 |
-
│ │
|
| 136 |
-
[Audio/Video] [Text]
|
| 137 |
-
│ │
|
| 138 |
-
▼ │
|
| 139 |
-
Whisper (local) │ ← 99 languages, fully offline
|
| 140 |
-
│ │
|
| 141 |
-
└───────┬────────┘
|
| 142 |
-
│
|
| 143 |
-
▼
|
| 144 |
-
Normalised Text
|
| 145 |
-
│
|
| 146 |
-
▼
|
| 147 |
-
┌──────────────────────────────┐
|
| 148 |
-
│ EmbeddingEngine │
|
| 149 |
-
│ Option A: TF-IDF + SVD │ ← offline baseline (char n-grams)
|
| 150 |
-
│ Option B: sentence-trans. │ ← multilingual upgrade, ~120 MB
|
| 151 |
-
└──────────────┬───────────────┘
|
| 152 |
-
│
|
| 153 |
-
256-dim L2-normalised vector
|
| 154 |
-
│
|
| 155 |
-
┌───────────┼───────────────┐
|
| 156 |
-
│ │ │
|
| 157 |
-
▼ ▼ ▼
|
| 158 |
-
SVM clf RF clf GBR regressor
|
| 159 |
-
(officer) (priority) (ETA days)
|
| 160 |
-
│ │ │
|
| 161 |
-
▼ ▼ ▼
|
| 162 |
-
OFF001-8 H/M/L + conf ETA + conf
|
| 163 |
-
|
| 164 |
-
+ NumpyVectorStore / FAISS
|
| 165 |
-
→ top-K similar past complaints
|
| 166 |
-
```
|
| 167 |
-
|
| 168 |
-
---
|
| 169 |
-
|
| 170 |
-
## 🧪 Evaluation Results (5-fold Cross-Validation)
|
| 171 |
-
|
| 172 |
-
### T1 — Officer Routing (SVM)
|
| 173 |
-
| Metric | Value |
|
| 174 |
-
|--------|-------|
|
| 175 |
-
| CV Accuracy | 1.000 ± 0.000 |
|
| 176 |
-
| CV F1-macro | 1.000 ± 0.000 |
|
| 177 |
-
| Recall@5 Similarity | 1.000 |
|
| 178 |
-
|
| 179 |
-
> Officer routing achieves perfect CV scores because each department uses domain-specific vocabulary (e.g. "pothole" → Roads, "voltage" → Electricity). In production, expect 85–95% with real data and a multilingual transformer.
|
| 180 |
-
|
| 181 |
-
### T2 — Priority Prediction (Random Forest)
|
| 182 |
-
| Metric | Value |
|
| 183 |
-
|--------|-------|
|
| 184 |
-
| CV Accuracy | 0.686 ± 0.024 |
|
| 185 |
-
| CV F1-macro | 0.661 ± 0.041 |
|
| 186 |
-
|
| 187 |
-
> Priority signal comes from urgency language ("emergency", "life-threatening" vs "minor", "when convenient"). CV performance reflects realistic generalisation. With real complaint data, transformer fine-tuning typically reaches 80–90% F1.
|
| 188 |
-
|
| 189 |
-
### T3 — ETA Prediction (Gradient Boosting)
|
| 190 |
-
| Metric | Value |
|
| 191 |
-
|--------|-------|
|
| 192 |
-
| CV MAE | 5.47 days |
|
| 193 |
-
| CV RMSE | 7.69 days |
|
| 194 |
-
| CV R² | 0.529 |
|
| 195 |
-
|
| 196 |
-
> ETA is a noisy regression target in practice. Improvement paths: stratified sampling by department, priority-aware features, historical officer resolution data.
|
| 197 |
-
|
| 198 |
-
### T4 — Similarity Search
|
| 199 |
-
| Metric | Value |
|
| 200 |
-
|--------|-------|
|
| 201 |
-
| Recall@1 | 0.990 |
|
| 202 |
-
| Recall@5 | 1.000 |
|
| 203 |
-
| Recall@10 | 1.000 |
|
| 204 |
-
|
| 205 |
-
---
|
| 206 |
-
|
| 207 |
-
## 🌍 Multilingual Support
|
| 208 |
-
|
| 209 |
-
**Two-tier strategy:**
|
| 210 |
-
|
| 211 |
-
| Tier | Component | Languages |
|
| 212 |
-
|------|-----------|-----------|
|
| 213 |
-
| Embeddings | TF-IDF + char n-grams (offline baseline) | Any script via char-level tokenisation |
|
| 214 |
-
| Embeddings | `paraphrase-multilingual-MiniLM-L12-v2` (upgrade) | 50+ languages, proper semantics |
|
| 215 |
-
| ASR | Whisper (local) | 99 languages, automatic detection |
|
| 216 |
-
|
| 217 |
-
**Tested language mixes in synthetic data:**
|
| 218 |
-
- English
|
| 219 |
-
- Hinglish (Hindi + English): "Bahut bada problem hai. …"
|
| 220 |
-
- Hinglish (transliterated): "Mera complaint yeh hai ki …"
|
| 221 |
-
- Tamil-English: "Romba kastam aaguthu. …"
|
| 222 |
-
- Spanish-English: "Es urgente. … Por favor actúe rápidamente."
|
| 223 |
-
|
| 224 |
-
---
|
| 225 |
-
|
| 226 |
-
## 👮 Officer Registry
|
| 227 |
-
|
| 228 |
-
| ID | Name | Department |
|
| 229 |
-
|----|------|-----------|
|
| 230 |
-
| OFF001 | Rahul Sharma | Infrastructure & Roads |
|
| 231 |
-
| OFF002 | Priya Mehta | Water & Sanitation |
|
| 232 |
-
| OFF003 | Amit Verma | Electricity & Utilities |
|
| 233 |
-
| OFF004 | Sunita Patel | Public Safety & Security |
|
| 234 |
-
| OFF005 | Vijay Kumar | Health & Environment |
|
| 235 |
-
| OFF006 | Anjali Singh | Land & Property |
|
| 236 |
-
| OFF007 | Ravi Nair | Transport & Traffic |
|
| 237 |
-
| OFF008 | Meena Reddy | Administrative Services |
|
| 238 |
-
|
| 239 |
-
---
|
| 240 |
-
|
| 241 |
-
## ⚖️ Design Trade-offs
|
| 242 |
-
|
| 243 |
-
| Decision | Choice | Rationale |
|
| 244 |
-
|----------|--------|-----------|
|
| 245 |
-
| Embedding backbone | TF-IDF+SVD (offline) vs sentence-transformers | Zero-dependency baseline; drop-in upgrade path defined |
|
| 246 |
-
| Officer classifier | SVM (RBF) | Best generalisation on small corpora; probability calibration via `predict_proba` |
|
| 247 |
-
| Priority classifier | Random Forest | Handles class imbalance; interpretable feature importances |
|
| 248 |
-
| ETA model | Gradient Boosting Regressor | Captures non-linear ETA distributions per department/priority |
|
| 249 |
-
| Similarity search | NumPy cosine vs FAISS | NumPy for ≤50k docs (zero deps); FAISS for production scale |
|
| 250 |
-
| Audio/Video | openai-whisper (local) | 99 languages, 4 model sizes, runs on CPU, truly offline |
|
| 251 |
-
| Data | Synthetic (800 samples) | For demo; plug in real complaint CSV and retrain in 1 command |
|
| 252 |
-
|
| 253 |
-
---
|
| 254 |
-
|
| 255 |
-
## 🔄 Replacing Synthetic Data with Real Data
|
| 256 |
-
|
| 257 |
-
1. Prepare a CSV with columns: `text`, `officer_id`, `priority`, `eta_days`
|
| 258 |
-
2. Replace `data/synthetic_complaints.csv`
|
| 259 |
-
3. Run `python models/train.py`
|
| 260 |
-
|
| 261 |
-
The entire pipeline retrains in under 2 minutes on CPU.
|
| 262 |
-
|
| 263 |
-
---
|
| 264 |
-
|
| 265 |
-
## 🚀 Production Upgrade Path
|
| 266 |
-
|
| 267 |
-
```
|
| 268 |
-
Current (offline baseline) Production upgrade
|
| 269 |
-
───────────────────────────────── ───────────────────────────────────
|
| 270 |
-
TF-IDF + SVD (256-dim) → paraphrase-multilingual-MiniLM-L12-v2
|
| 271 |
-
NumPy cosine search → FAISS IndexFlatIP (millions of docs)
|
| 272 |
-
SVM / RF / GBR (sklearn) → Fine-tuned mBERT / XLM-RoBERTa
|
| 273 |
-
Whisper 'base' (74 MB) → Whisper 'medium' (769 MB) on GPU
|
| 274 |
-
Gradio (demo) → FastAPI + React frontend
|
| 275 |
-
```
|
| 276 |
-
|
| 277 |
-
---
|
| 278 |
-
|
| 279 |
-
## 📄 License
|
| 280 |
-
|
| 281 |
-
MIT License
|
|
|
|
| 1 |
+
# Complaint Routing System
|
| 2 |
|
| 3 |
+
This is a machine learning pipeline that automatically processes complaints submitted in text, audio, or video formats. The system uses local models to assign complaints to the correct officer, predict the priority level, estimate the resolution time (in days), and find similar past complaints.
|
| 4 |
|
| 5 |
+
All inference is done locally without external APIs.
|
| 6 |
|
| 7 |
+
## Setup
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
+
1. Install the required Python packages:
|
| 10 |
```bash
|
| 11 |
+
pip install -r requirements.txt
|
| 12 |
+
pip install openai-whisper gradio
|
| 13 |
```
|
| 14 |
|
| 15 |
+
2. To support audio/video extraction, ensure `ffmpeg` is installed on your system.
|
| 16 |
|
| 17 |
+
## Usage
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
+
You can launch the web interface by running:
|
| 20 |
```bash
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
python app/web_app.py
|
| 22 |
```
|
| 23 |
+
Then open `http://localhost:7860` in your browser.
|
| 24 |
+
|
| 25 |
+
## Project Structure
|
| 26 |
+
- `app/` - Contains the web app and CLI interfaces.
|
| 27 |
+
- `models/` - Contains the training scripts and saved ML models (SVM, Random Forest, Gradient Boosting).
|
| 28 |
+
- `inference/` - The core inference engine and vector store for semantic similarity.
|
| 29 |
+
- `audio_video/` - Wrappers for local Whisper transcription.
|
| 30 |
+
- `data/` - Training data.
|
| 31 |
+
|
| 32 |
+
## Models Used
|
| 33 |
+
- **Officer Routing**: Support Vector Classifier (SVC)
|
| 34 |
+
- **Priority Prediction**: Random Forest Classifier
|
| 35 |
+
- **ETA Prediction**: Gradient Boosting Regressor
|
| 36 |
+
- **Embeddings**: SentenceTransformers (paraphrase-multilingual-MiniLM-L12-v2)
|
| 37 |
+
- **Transcription**: Whisper (Offline)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|