Twitter Sentiment Analysis

Warning

The Wikipedia API might not work all the time depending on the entered search term.

App

This is a web app which can be used to analyze users' sentiments across Twitter hashtags. 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. Run python -m venv venv in the terminal from the server folder to create a Python virtual environment
    (Note: Ensure that you have Python version 3.7 or higher)

  3. Run venv/scripts/activate and pip install -r requirements.txt while still being in server folder to switch to virtual env & install all the required packages

  4. Start the Flask server by running python app.py

  5. Open http://localhost:8000 in your browser to access the app

Updating front-end app

  1. Run npm install in client folder to download all the dependent noad modules

  2. Make the changes in client/src folder as required

  3. Check the front-end related changes by running npm start & open http://localhost:5000 in your browser

  4. Run npm run build after all the changes are made to create optimized production build

Training the 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 Jupyter Notebook