Skip to content
Awais Asghar.
AI & Machine Learning2025

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.

SentimentFlow thumbnail

README · rendered from GitHub

SentimentFlow-RNN-and-LSTM-Powered-Tweet-Analysis

Project Status Models Framework Language License

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.

Image Image

Table of Contents

  1. Features
  2. Dataset
  3. Preprocessing
  4. Model Architectures
  5. Training Details
  6. Results
  7. Confusion Matrices
  8. Future Work
  9. 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 content
  • label – 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

Image

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

Image Image

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
Image

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 LabelPredicted NegativePredicted Positive
Negative10022519600
Positive2050199674

RNN Confusion Matrix

True LabelPredicted NegativePredicted Positive
Negative6504615005
Positive1772762222

LSTM shows fewer misclassifications and more consistent predictions.

Image Image Image

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
Image

License

MIT License (Modify if needed)


More in AI / ML

Related projects

See all
  • AI / ML2025

    RecycleVision

    EfficientNetB0 transfer learning sorts waste into six recyclable categories.

    • Python
    • TensorFlow
    • Keras
    • EfficientNetB0