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
-
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 inserver/main
. Also, don't forget to change the loaded model name inserver/main/init.py
) -
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. -
Run
docker-compose up --build
in the terminal from the root folder
(Note: Ensure that you have Docker installed) -
Open
http://localhost:5000
in your browser to access the app
(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)
- Copy and run the Kaggle Notebook.
- Download the Kaggle Sentiment140 dataset and put it in the root folder as
sentiment140.csv
. - Run the code blocks given in the
Twitter Sentiment Analysis.ipynb