Instructions to use Sudheer17/sentiment_lstm with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Keras
How to use Sudheer17/sentiment_lstm with Keras:
# Available backend options are: "jax", "torch", "tensorflow". import os os.environ["KERAS_BACKEND"] = "jax" import keras model = keras.saving.load_model("hf://Sudheer17/sentiment_lstm") - Notebooks
- Google Colab
- Kaggle
YAML Metadata Warning:empty or missing yaml metadata in repo card
Check out the documentation for more information.
- ๐ง Sentiment Analysis Using Deep Learning (LSTM)
- ๐ Overview
- โจ Features
- ๐ง Deep Learning Architecture
- ๐ Dataset
- โ๏ธ NLP Preprocessing Pipeline
- ๐ท Label Generation
- ๐ค Tokenization
- ๐ Sequence Padding
- ๐ง Model Summary
- โ๏ธ Training Configuration
- ๐ Model Evaluation
- ๐ฎ Sample Predictions
- ๐พ Saved Files
- ๐ Repository Structure
- ๐ Future Improvements
- ๐ Tech Stack
- ๐ฆ Installation
- โถ๏ธ Run
- ๐ฏ Applications
- ๐จโ๐ป Author
- โญ Support
๐ง Sentiment Analysis Using Deep Learning (LSTM)
๐ Deep Learning Based Twitter Sentiment Analysis using LSTM Neural Networks
Predict whether a tweet expresses Positive, Negative, or Neutral sentiment with a trained LSTM model.
๐ Overview
This project implements an End-to-End Sentiment Analysis System using Long Short-Term Memory (LSTM) networks.
The model learns contextual information from tweets after performing extensive Natural Language Processing (NLP) preprocessing.
Unlike traditional Machine Learning models, LSTM captures sequential dependencies between words, making it highly effective for sentiment classification.
The trained model predicts one of the following sentiments:
- ๐ Positive
- ๐ Neutral
- ๐ Negative
โจ Features
โ English Tweet Filtering
โ Advanced Text Cleaning
โ HTML Entity Decoding
โ URL Removal
โ Stopword Removal
โ Negation Word Preservation
โ Lemmatization
โ Tokenization
โ Sequence Padding
โ Deep LSTM Network
โ Automatic Label Generation using TextBlob
โ Confidence Score Prediction
โ Save & Reload Model
โ Ready for Web Deployment
๐ง Deep Learning Architecture
Input Tweets
โ
โผ
Text Cleaning
โ
โผ
Tokenization
โ
โผ
Padding Sequences
โ
โผ
Embedding Layer
โ
โผ
LSTM (128)
โ
โผ
Dropout
โ
โผ
LSTM (64)
โ
โผ
Dropout
โ
โผ
LSTM (32)
โ
โผ
Global Max Pooling
โ
โผ
Dense (64)
โ
โผ
Dropout
โ
โผ
Dense (Softmax)
โ
โผ
Prediction
๐ Dataset
The project uses a Twitter sentiment dataset.
Dataset includes:
- User ID
- Tweet
- Language
Only English Tweets are used for training.
โ๏ธ NLP Preprocessing Pipeline
The preprocessing pipeline performs:
- Convert text to lowercase
- Decode HTML entities
- Remove URLs
- Remove HTML tags
- Remove punctuation
- Remove numbers
- Remove extra spaces
- Preserve negation words
- Remove stopwords
- Lemmatization
- Clean sentence generation
Example
Original Tweet
I absolutely LOVE this phone!! ๐๐
https://abc.com
Clean Tweet
absolutely love phone
๐ท Label Generation
Instead of manually labeling data, the project automatically generates sentiment labels using TextBlob Polarity.
| Polarity | Sentiment |
|---|---|
| < 0 | Negative |
| = 0 | Neutral |
| > 0 | Positive |
๐ค Tokenization
Tokenizer Configuration
- Vocabulary Size : 10,000
- OOV Token :
<OOV>
Each cleaned tweet is converted into integer sequences.
Example
I love AI
โ
[15, 41, 280]
๐ Sequence Padding
Every tweet is padded to a fixed length.
Maximum Length = 30
Padding Type
Post Padding
Truncation
Post Truncation
๐ง Model Summary
Embedding Layer
โ
LSTM (128)
โ
Dropout (0.2)
โ
LSTM (64)
โ
Dropout (0.2)
โ
LSTM (32)
โ
Dropout (0.2)
โ
GlobalMaxPooling1D
โ
Dense (64)
โ
Dropout (0.2)
โ
Dense (3)
โ
Softmax
โ๏ธ Training Configuration
| Parameter | Value |
|---|---|
| Optimizer | Adam |
| Loss | Sparse Categorical Crossentropy |
| Epochs | 20 |
| Batch Size | 32 |
| Validation Split | 20% |
Callbacks
- EarlyStopping
- ModelCheckpoint
- ReduceLROnPlateau
๐ Model Evaluation
Evaluation Metrics
- Accuracy
- Loss
- Classification Report
- Precision
- Recall
- F1 Score
- Confusion Matrix
๐ฎ Sample Predictions
| Tweet | Prediction |
|---|---|
| I absolutely love this phone! | ๐ Positive |
| This is the worst service ever. | ๐ Negative |
| The meeting starts at 10 AM tomorrow. | ๐ Neutral |
| India won the cricket match! | ๐ Positive |
| Russia attacked Ukraine today. | ๐ Negative |
๐พ Saved Files
best_model.keras
Best model saved during training.
sentiment_lstm.keras
Final trained model.
tokenizer.pkl
Tokenizer object.
label_encoder.pkl
Label encoder.
๐ Repository Structure
sentiment_lstm/
โโโ best_model.keras
โโโ sentiment_lstm.keras
โโโ tokenizer.pkl
โโโ label_encoder.pkl
โโโ sentiment.csv
โโโ README.md
๐ Future Improvements
- Streamlit Web Application
- Hugging Face Deployment
- REST API using FastAPI
- Docker Containerization
- ONNX Model Conversion
- Attention-based Bi-LSTM
- Transformer Comparison (BERT)
- Live Twitter/X Sentiment Prediction
- Batch Prediction Support
- Explainable AI (LIME/SHAP)
๐ Tech Stack
- Python
- TensorFlow
- Keras
- NumPy
- Pandas
- NLTK
- TextBlob
- Scikit-Learn
- Matplotlib
- Seaborn
๐ฆ Installation
git clone https://github.com/YOUR_USERNAME/sentiment_lstm.git
cd sentiment_lstm
pip install -r requirements.txt
โถ๏ธ Run
python app.py
or
jupyter notebook
๐ฏ Applications
- Social Media Monitoring
- Customer Feedback Analysis
- Product Reviews
- Political Opinion Mining
- Brand Reputation Analysis
- Market Research
- Public Opinion Analysis
๐จโ๐ป Author
Sudheer Muthyala
๐ B.Tech - Electronics & Communication Engineering
๐ป Python Developer | Machine Learning Enthusiast | Data Science Aspirant
GitHub: https://github.com/M-Sudheer18
โญ Support
If you found this project useful, consider giving it a โญ on GitHub.
It helps others discover the project and motivates future improvements.
- Downloads last month
- -