|
| 1 | +# Leoplus AI – Conversational Sentiment Analysis Chatbot |
| 2 | + |
| 3 | +A production-ready chatbot built for the Leoplus AI internship assignment. This project implements **Tier 1 (mandatory)** and **Tier 2 (additional credit)** sentiment analysis, along with a lightweight **Rule-Based NLU system** for context-aware responses. |
| 4 | + |
| 5 | +--- |
| 6 | + |
| 7 | +## 📌 Features |
| 8 | + |
| 9 | +### ✅ Tier 1 — Overall Conversation Sentiment (Mandatory) |
| 10 | + |
| 11 | +At the end of the conversation, the chatbot generates: |
| 12 | + |
| 13 | +* Overall sentiment → *positive / neutral / negative* |
| 14 | +* Confidence score |
| 15 | +* Conversation summary |
| 16 | +* Mood shift detection (bonus feature) |
| 17 | + |
| 18 | +### ✅ Tier 2 — Message-Level Sentiment (Additional Credit) |
| 19 | + |
| 20 | +For **each user message**, the bot performs: |
| 21 | + |
| 22 | +* Sentiment detection |
| 23 | +* Confidence scoring |
| 24 | +* Sentiment-aware response tone |
| 25 | + |
| 26 | +Example: |
| 27 | + |
| 28 | +``` |
| 29 | +User: "Your service disappoints me" |
| 30 | +→ Sentiment: negative (confidence: 0.82) |
| 31 | +Bot: I'm sorry you're facing trouble. Let me help fix this. |
| 32 | +``` |
| 33 | + |
| 34 | +--- |
| 35 | + |
| 36 | +## 📌 Rule-Based NLU (Context Understanding) |
| 37 | + |
| 38 | +A lightweight NLU engine identifies user intent based on keywords. |
| 39 | + |
| 40 | +Supported intents: |
| 41 | + |
| 42 | +| Intent | Example Keywords | |
| 43 | +| --------------- | ---------------------------- | |
| 44 | +| greeting | hi, hello | |
| 45 | +| farewell | bye, thanks | |
| 46 | +| refund | refund, money back | |
| 47 | +| delivery_issue | late, package, not delivered | |
| 48 | +| technical_issue | error, crash, not working | |
| 49 | +| billing_issue | charge, bill, invoice | |
| 50 | +| account_issue | login, password | |
| 51 | +| general | fallback | |
| 52 | + |
| 53 | +This enables **context-specific responses**, e.g.: |
| 54 | + |
| 55 | +``` |
| 56 | +User: my package is late |
| 57 | +Bot: I'm sorry your package is delayed. Could you share your order ID? |
| 58 | +``` |
| 59 | + |
| 60 | +--- |
| 61 | + |
| 62 | +## 📂 Project Structure |
| 63 | + |
| 64 | +``` |
| 65 | +src/ |
| 66 | +├── chatbot/ |
| 67 | +│ ├── chatbot.py |
| 68 | +│ ├── conversation_manager.py |
| 69 | +│ ├── response_generator.py |
| 70 | +│ └── utils.py |
| 71 | +├── components/ |
| 72 | +│ ├── sentiment_component.py |
| 73 | +│ ├── text_cleaner.py |
| 74 | +│ └── intent_classifier.py |
| 75 | +├── services/ |
| 76 | +│ ├── sentiment_service.py |
| 77 | +│ └── conversation_service.py |
| 78 | +├── repository/ |
| 79 | +│ └── conversation_repository.py |
| 80 | +├── analytics/ |
| 81 | +│ └── mood_shift_detector.py |
| 82 | +├── utils/ |
| 83 | +│ ├── logger.py |
| 84 | +│ └── formatters.py |
| 85 | +main.py |
| 86 | +``` |
| 87 | + |
| 88 | +--- |
| 89 | + |
| 90 | +# 🚀 How to Run the Project |
| 91 | + |
| 92 | +### 1️⃣ Create virtual environment |
| 93 | + |
| 94 | +```bash |
| 95 | +python -m venv venv |
| 96 | +source venv/bin/activate # Windows → venv\Scripts\activate |
| 97 | +``` |
| 98 | + |
| 99 | +### 2️⃣ Install dependencies |
| 100 | + |
| 101 | +```bash |
| 102 | +pip install -r requirements.txt |
| 103 | +``` |
| 104 | + |
| 105 | +### 3️⃣ Run the chatbot |
| 106 | + |
| 107 | +```bash |
| 108 | +python main.py |
| 109 | +``` |
| 110 | + |
| 111 | +### 4️⃣ End the conversation |
| 112 | + |
| 113 | +Type: |
| 114 | + |
| 115 | +``` |
| 116 | +quit |
| 117 | +exit |
| 118 | +bye |
| 119 | +``` |
| 120 | + |
| 121 | +You will see a final sentiment summary. |
| 122 | + |
| 123 | +--- |
| 124 | + |
| 125 | +# 🧠 Sentiment Logic Explained |
| 126 | + |
| 127 | +## ✔ Tier 2: Single Message Sentiment |
| 128 | + |
| 129 | +Each message is cleaned and analyzed using: |
| 130 | + |
| 131 | +1. **Transformers (DistilBERT)** → main model |
| 132 | +2. **VADER** → fallback |
| 133 | +3. **Keyword polarity** → final fallback |
| 134 | + |
| 135 | +Each prediction returns: |
| 136 | + |
| 137 | +* label: positive / negative / neutral |
| 138 | +* confidence score |
| 139 | +* raw scores |
| 140 | + |
| 141 | +--- |
| 142 | + |
| 143 | +## ✔ Tier 1: Conversation-Level Sentiment |
| 144 | + |
| 145 | +All user messages → aggregated using weighted average: |
| 146 | + |
| 147 | +* Positive sentiment → +score |
| 148 | +* Negative → -score |
| 149 | +* Neutral → 0 |
| 150 | + |
| 151 | +Weights depend on message length + confidence. |
| 152 | + |
| 153 | +Output includes: |
| 154 | + |
| 155 | +* Overall sentiment |
| 156 | +* Confidence |
| 157 | +* Trend (improving/worsening/stable) |
| 158 | + |
| 159 | +--- |
| 160 | + |
| 161 | +# 🟦 Technologies Used |
| 162 | + |
| 163 | +### **NLP** |
| 164 | + |
| 165 | +* Transformers (DistilBERT) |
| 166 | +* VADER sentiment analyzer |
| 167 | +* Rule-Based NLU |
| 168 | +* Text cleaning utilities |
| 169 | + |
| 170 | +### **Software Architecture** |
| 171 | + |
| 172 | +* Modular service-component design |
| 173 | +* Logging utilities |
| 174 | +* Repository layer |
| 175 | +* Conversation analytics |
| 176 | + |
| 177 | +### **Testing** |
| 178 | + |
| 179 | +* pytest |
| 180 | +* Unit tests for text cleaning, sentiment, and conversation handling |
| 181 | + |
| 182 | +--- |
| 183 | + |
| 184 | +# 🏆 Status of Tier 2 Implementation |
| 185 | + |
| 186 | +| Feature | Status | |
| 187 | +| ----------------------------- | ----------------- | |
| 188 | +| Single-message sentiment | ✅ Completed | |
| 189 | +| Confidence scoring | ✅ Completed | |
| 190 | +| Per-message sentiment output | ✅ Completed | |
| 191 | +| Conversation flow integration | ✅ Completed | |
| 192 | +| Sentiment-aware tone | ✅ Completed | |
| 193 | +| Mood shift detection | ⭐ Bonus Completed | |
| 194 | + |
| 195 | +Your bot **meets and exceeds** Tier 2 expectations. |
| 196 | + |
| 197 | +--- |
| 198 | + |
| 199 | +# 💬 Example Chat Output |
| 200 | + |
| 201 | +``` |
| 202 | +Bot: Hello! I'm Leoplus Assistant. How can I help? |
| 203 | +
|
| 204 | +You: My package is not delivered yet. |
| 205 | +→ Sentiment: negative (0.81) |
| 206 | +Bot: I'm sorry your package is delayed. Could you share your order ID? |
| 207 | +
|
| 208 | +You: Also the billing was wrong. |
| 209 | +→ Sentiment: negative (0.73) |
| 210 | +Bot: I apologize for the billing trouble. What seems incorrect? |
| 211 | +
|
| 212 | +quit |
| 213 | +
|
| 214 | +=== Conversation Summary === |
| 215 | +Overall Sentiment: negative (0.77) |
| 216 | +Trend: worsening |
| 217 | +``` |
| 218 | + |
| 219 | +--- |
| 220 | + |
| 221 | +# 🎯 Why This Project Is Strong for the Internship |
| 222 | + |
| 223 | +* Professional architecture |
| 224 | +* Tier 1 & Tier 2 fully implemented |
| 225 | +* Clean and scalable codebase |
| 226 | +* Context-aware responses via Rule-Based NLU |
| 227 | +* Multiple fallback strategies for robustness |
| 228 | +* Clear documentation and readability |
| 229 | +* No unnecessary ML complexity |
| 230 | + |
| 231 | +This showcases strong engineering fundamentals and practical NLP understanding. |
| 232 | + |
| 233 | +--- |
| 234 | + |
| 235 | +If you want additional sections (deployment, limitations, future work), I can add them too! |
0 commit comments