File size: 2,763 Bytes
9edefb0 29deaf7 5eebab1 f53d8be 9edefb0 1c4bb04 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
---
title: Tweets Sentiment Analyzer
emoji: π
colorFrom: indigo
colorTo: gray
sdk: gradio
sdk_version: 5.34.2
app_file: app.py
pinned: false
license: mit
short_description: Real-Time Tweet Sentiment Analyzer
---
# π§ Sentiment Analysis from Scratch (BiLSTM + Attention)
Welcome to this live interactive demo of a sentiment analysis model trained completely from scratch using a **Deep Bidirectional LSTM** architecture enhanced with a **custom attention mechanism**. This project is designed to classify short texts or tweets into **Positive** or **Negative** sentiments with a confidence score.
---
## π Project Highlights
- β
**Trained from scratch**: The embedding layer is trained on the dataset itself (not using pretrained embeddings).
- π§ **Model Architecture**:
- Bidirectional LSTM layers
- Custom attention layer (`BetterAttention`)
- Final dense ANN for binary classification
- π **Output**: Label (Positive/Negative) and confidence score (0β1)
- π **Tokenizer**: Also trained from scratch and saved as `tokenizer.joblib`
- π **Model Format**: Saved as `.keras` and loaded efficiently during inference
---
## π Try it Out
Enter a tweet or short sentence below and see real-time prediction:
π *Example*:
`"I absolutely loved the performance!"`
**Output**: Positive (0.91)
---
## π Model Files
You can also explore/download the trained artifacts here:
- [`sentiment_model.keras`](https://huggingface.co/MasterShomya/Sentiment_Analysis-Tweets/blob/main/sentiment_model.keras)
- [`tokenizer.joblib`](https://huggingface.co/MasterShomya/Sentiment_Analysis-Tweets/blob/main/tokenizer.joblib)
---
## π§ͺ How It Works
1. The input text is tokenized using the trained tokenizer (`joblib`).
2. The padded sequence is passed through:
- `Embedding β BiLSTM β BiLSTM β Attention β Dense Layers`
3. The final sigmoid-activated output represents the **probability of positivity**.
4. A confidence-aware label is returned using Gradioβs `Label` component.
---
## π Model Performance
Despite training from scratch without pretrained embeddings (like GloVe or FastText), the model performs comparably well. Experiments with `glove.27B.200d` embeddings yielded **similar accuracy**, and hence were excluded for clarity.
Training plots and confusion matrix are available in the original [Kaggle Notebook](https://www.kaggle.com/code/mastershomya/sentiment-analysis-deep-bilstm).
---
## π§βπ» Author
**Shomya Soneji**
Machine Learning & Deep Learning Enthusiast
Connect on [Kaggle](https://www.kaggle.com/mastershomya)
---
## π€ Support
If you find this project helpful, please consider giving it a π and sharing it!
Your feedback and suggestions are always welcome π¬ |