Skip to content

Yossefmohammed/twitter-sentiment-analysis-with-lstm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

Twitter Sentiment Analysis with LSTM

This project implements a sentiment analysis model using LSTM (Long Short-Term Memory) neural networks to classify Twitter posts into different sentiment categories.

Overview

The model analyzes Twitter posts and classifies them into four sentiment categories:

  • Positive
  • Negative
  • Neutral
  • Irrelevant

Dataset

The project uses a Twitter entity sentiment analysis dataset containing:

  • Training data: 74,681 tweets
  • Testing data: 999 tweets

Each tweet is labeled with a sentiment category and includes the text content.

Model Architecture

The model uses a bidirectional LSTM architecture with the following components:

  • Embedding layer
  • Dropout layer (0.5)
  • Bidirectional LSTM layer (150 units)
  • Dense layer with ReLU activation (32 units)
  • Output layer with softmax activation (4 units)

Data Preprocessing

The text preprocessing pipeline includes:

  1. Removing extra whitespace
  2. Removing special characters
  3. Removing single characters
  4. Converting to lowercase
  5. Tokenization
  6. Lemmatization
  7. Stopword removal
  8. Removing words shorter than 3 characters
  9. Removing duplicates

Training

The model was trained with:

  • Learning rate: 0.0001
  • Optimizer: Adam
  • Loss function: Categorical crossentropy
  • Batch size: Default
  • Epochs: 40

Results

The model achieved:

  • Training accuracy: ~95%
  • Validation accuracy: ~88%

Requirements

  • Python 3.x
  • TensorFlow
  • Keras
  • NLTK
  • Pandas
  • NumPy
  • scikit-learn

Usage

  1. Install the required dependencies
  2. Prepare your dataset in the same format as the example
  3. Run the Jupyter notebook to train and evaluate the model
  4. Use the trained model to predict sentiment on new tweets

License

This project is open source and available under the MIT License.

Author

Created by Yossef Mohammed

Contact Information

About

analysis the sentences with nice of bad using LSTM

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published