tweet-sense icon indicating copy to clipboard operation
tweet-sense copied to clipboard

Sentiment analysis dashboard for Twitter hashtags

twitter-sentiment-analysis-web-app


App

This is a web app which can be used to analyze users' sentiments across Twitter hashtags/terms. Its created using React and Django and uses an LSTM model trained on the Kaggle Sentiment140 dataset and served as a REST API to the ReactJS frontend.

The server pulls tweets using tweepy and performs inference using Keras. It also pulls data from the Wikipedia API based the hashtag chosen to display a short description. As part of the analysis, I also added few examples of the tweets and their predicted sentiments. A kernel for another sentiment classification using a CNN + 1D pooling can be found here

Untitled Diagram (6)

How to Use

Running the application

  1. Download the trained model and put into the server/main folder
    (Note: This is the CNN model. f you want use the LSTM model, you'll need to follow the training steps below and put the saved model in server/main. Also, don't forget to change the loaded model name in server/main/init.py )

  2. Get your Twitter API credentials through Keys and Tokens tab under the Twitter Developer Portal Projects & Apps page and add them to the /server/main/config.py file.

  3. Run docker-compose up --build in the terminal from the root folder
    (Note: Ensure that you have Docker installed)

  4. Open http://localhost:5000 in your browser to access the app

Training the model

(Note: If you have a GPU in your system, I suggest that you train the CNN model. The LSTM model takes longer to train due to its sequential nature, and offer relatively similar performance)

CNN Model

  1. Copy and run the Kaggle Notebook.

LSTM Model

  1. Download the Kaggle Sentiment140 dataset and put it in the root folder as sentiment140.csv.
  2. Run the code blocks given in the Twitter Sentiment Analysis.ipynb