SentimentFlow
RNN and LSTM models compared head-to-head on tweet sentiment.
Trains a simple recurrent network and an LSTM on the same tweet corpus to classify sentiment as positive or negative, then compares them on accuracy, F1 and confusion matrices.
README · rendered from GitHub
SentimentFlow-RNN-and-LSTM-Powered-Tweet-Analysis
People share opinions on Twitter every second. Companies, governments, and researchers want to know what people feel about products, events, or topics in real time. Reading tweets manually is impossible at scale. SentimentFlow is a deep learning based sentiment analysis project for tweets. It trains two models like a basic RNN and an LSTM network. SentimentFlow is a deep learning based sentiment analysis project that uses two architectures
- a Simple RNN model
- an LSTM model
Both models classify tweets as positive or negative, allowing easy comparison of their performance.
Table of Contents
- Features
- Dataset
- Preprocessing
- Model Architectures
- Training Details
- Results
- Confusion Matrices
- Future Work
- License
Features
- Text sentiment classification for tweets
- Comparison between RNN and LSTM models
- Clean preprocessing pipeline
- Metrics including accuracy, F1 score, and confusion matrix
- Simple and clear notebooks for learning deep NLP
- Works in Jupyter Notebook environment
Dataset
This project uses a tweet sentiment dataset (negative vs positive).
Typical columns include:
text– tweet contentlabel– sentiment (0 = negative, 1 = positive)
You can replace this section with your exact dataset link.
Preprocessing
Both notebooks include standard NLP preprocessing steps:
- Lowercasing
- Removing URLs, mentions, hashtags and extra symbols
- Tokenization using Keras Tokenizer
- Padding sequences to fixed length
- Splitting into train, validation and test sets
Model Architectures
1. RNN Model
A simple Recurrent Neural Network that processes text word by word.
Components:
- Embedding layer
- Simple RNN layer
- Dense layer
- Softmax or sigmoid output layer
Strengths: easy to train, fewer parameters Weaknesses: struggles with long term dependencies
2. LSTM Model
A Long Short Term Memory model designed to retain long term information.
Components:
- Embedding layer
- LSTM layer
- Dense layer(s)
- Output layer
Strengths: handles long text patterns better, avoids vanishing gradients Weaknesses: higher computation cost
Training Details
- 10 epochs for both models
- Adam optimizer
- Binary cross entropy loss
- Validation performance monitored each epoch
Results
LSTM Model
- Train Accuracy: 86.12 percent
- Val Accuracy: 83.29 percent
- Val F1 Score: 0.8325
- Final Loss: 0.3211
RNN Model
- Train Accuracy: 81.06 percent
- Val Accuracy: 79.55 percent to 79.7 percent
- Val F1 Score: 0.7917 to 0.7935
- Final Loss: 0.4248
Summary
The LSTM model performs better in every metric. It learns long term dependencies in tweets more effectively and shows stronger generalization.
Confusion Matrices
LSTM Confusion Matrix
| True Label | Predicted Negative | Predicted Positive |
|---|---|---|
| Negative | 100225 | 19600 |
| Positive | 20501 | 99674 |
RNN Confusion Matrix
| True Label | Predicted Negative | Predicted Positive |
|---|---|---|
| Negative | 65046 | 15005 |
| Positive | 17727 | 62222 |
LSTM shows fewer misclassifications and more consistent predictions.
Future Work
- Add GRU or Bidirectional LSTM models
- Use pretrained embeddings like GloVe
- Add attention mechanism
- Extend project to 3 class sentiment (positive, negative, neutral)
- Use transformer models such as BERT for modern NLP performance
License
MIT License (Modify if needed)
More in AI / ML
Related projects
Private repoAI / MLSummer 2026Trans-Neptunian Object Detection
A spatiotemporal U-Net that finds faint moving objects in telescope image sequences.
- PyTorch
- Python
- HDF5
- CANFAR
AI / ML2023SkinSense: Skin Cancer Classifier
An ensemble of five models labels a lesion as benign or malignant from one RGB image.
- Python
- Scikit-learn
- XGBoost
- LightGBM
AI / ML2025RecycleVision
EfficientNetB0 transfer learning sorts waste into six recyclable categories.
- Python
- TensorFlow
- Keras
- EfficientNetB0