A Flask application where we can enter hashtags and keywords related to tweets we want to stream and in which an NLP model, FinBERT which is a pre-trained NLP model to analyze the sentiment of the financial text, does sentiment analysis on the tweets in real-time. We can see the results of the tweets collected containing the hashtags or keywords and their sentiment scores given by FinBERT via Pandas dataFrame.
-
Clone this repository to your local.
git clone https://github.com/boblef/twitter_sentiment.git
-
Create a Twitter developer account
In order to run the Flask application, we need to create a Twitter developer account. -
Set up the cinfig file
Once you have created a developer account, the next thing you need to do is to set up the config file. Copytwitter.txt
and put it into theconfig
folder with the information you need to set up. What you need is as follows:- API KEY
- SECRET API KEY
- ACCESS TOKEN
- SECRET ACCESS TOKEN
Copy all of them from your Twitter developer dashboard and paste them to
config/twitter.txt
-
Set up the environment, and run the application
You can set up the environment in which we run the Flask application either by using Docker or by creating a conda or pip env by yourself.
- Docker
Build a container
Run the image
docker build -t twitter_sentiment:latest .
Open up your browser, and copy and paste the link below. The application is supposed to start.docker run -d -p 5000:5000 twitter_sentiment:latest
http://localhost:5000/
- Conda
Create a conda env whose name is going to be
finbert
Activate the conda env you just createdconda env create -f environment.yml
Run the applicationsource activate finbert or conda activate finbert
python app.py
- Some of the functionality used in this application can also be used in the Automated Forex Trading Strategy which I have been working on in order to create new features.
- We change the Deep Learning model which gives sentiment scores to tweets to another NLP model which trained on different dataset, if we want to switch the domain we want to use for.