Git Product home page Git Product logo

twitter-real-time-sentiment-analysis's Introduction

Twitter real-time sentiment analysis

This project uses:

  • Tweepy
  • Kafka
  • Keras
  • Tensorflow
  • Dash
  • Plotly
  • NLTK
  • mySQL

This project has been launched! You can see it run at chauser.me.

You can find a quickstart guide to setting up Kafka here. You'll need two topics. One called "TwitterStream" and one called "FrontEnd". You will also need a set of Twitter API keys that can be obtained here. Save your keys in a txt file named 'twitterkeys.txt' with each key/token on a seperate line.

The neural network was trained using the sentiment140 dataset. The final trained neural network is too large to upload to GitHub so I've provided the program used to train it in this repo. You can either provide your own model or train one using my code. To train one with my code you'll need to first run datacleaner.py, then run TwittSentTrainer.py. You may need to alter datacleaner.py to point to the sentiment140 dataset on your machine.

About this project

The program reads a stream of tweets, replies, and mentions pertaining to a set of keywords or in response to tweets by specified Twitter accounts. TwitterStream.py then partially cleans the text before sending it to the master consumer using a Kafka stream. MasterConsumer.py then cleans the text further and preps it for analysis by a neural network, keyword extraction, and analysis of users being followed. Once the consumer is done it uploads the data to a mySQL server. The front end then selects the data it wants from the SQL server and displays it on the dashboard.

This is what the website looks like if you're unable to visit it for some reason:

Website dashboard

It's important to keep in mind that just because some tweets are labelled as negative does not mean they are hateful of the given topic. They may be expressing disappointment or sadness which the neural network considers to be a negative sentiment.

Reading the graphs

All of the graphs on the dashboard update every minute but the consumer only processes and pushes data every two minutes. It's highly recommended to leave the consumer processing time at two minutes to reduce dips and spikes in the stream.

Line graph

The line graph graphs the sentiment output from the neural network. The y-axis is the number of tweets/replies, the x-axis is a time series.

If you notice a large spike in any of the lines outside of normal trends it's probably because someone sent out a spicy tweet! Check the table!

Bar graph

The bar graph shows frequency of keywords that people are using in association with the keywords you're looking for.

It also shows the amount of tweets with each sentiment that are using those keywords. So not only are you able to see what people are talking about you're able to see how they feel about each of those words!

Table

The only tweets that show up here are the tweets sent by the users being followed. You can change who is followed by editing the target_users variable in TwitterStream.py. I'll add a better way to change it in the future

Date: yyyy-mm-dd HH:MM:SS

User: This is the twitter user who sent the tweet.

Text: What the user tweeted.

Sentiment Change: For each tweet the sentiment scores for two minute window prior to the tweet are saved. Every two minutes those sentiment scores are compared to the new sentiment scores and the percentage of change is reflected here. These numbers are updated for the next five minutes. After five minutes the percentage of change is no longer updated.

Activity Change: Same as sentiment change but this measures change in total number of keyword mentions, tweets, and replies.

How to run it

At the moment there is no main program that can be run to launch the entire program. In the future I hope to have a main file that launches each program in its own process, but for now you will need to run TwitterStream.py, MasterConsumer.py, and frontendDash.py in seperate terminals/interpreters.

twitter-real-time-sentiment-analysis's People

Contributors

cchauser avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.