Last updated on July 21st, 2023 at 09:01 pm
Twitter can be a very convoluted place. That is why we have developed this Crypto Twitter Sentiment Analysis Python app to help you search for the current sentiment for any crypto.
Requirements
- A computer with an Nvidia GPU (required to run CUDA)
- A Twitter Developer account (free to sign up)
- A News API key (free to sign up)
- Python installed
Twitter-roBERTa-base for Sentiment Analysis
The algorithm we will be using for our sentiment analysis is Twitter-roBERTa-base. It is trained on ~58M tweets and finetuned with the TweetEval benchmark. In short, this algorithm recognises and classifies tweets based on emotion, emojis, hate, irony, offensive, sentiment, and stance. You can read a paper on TweetEval here.
How to Setup Crypto Twitter Sentiment Analysis
- Download the ‘crypto-sentiment-analysis’ folder from https://github.com/rlm42/crypto-sentiment-analysis. (Click Code then Download ZIP). Unzip the downloaded folder
- Create a new app on the Twitter Developer portal. Copy your API Key and API Key Secret and paste them inside ‘tweepy.0AuthHandler’ in the app.py file. Also generate and copy and paste your Access Token and Access Token Secret and paste inside ‘auth.set_access_token’
- Do the same inside the appWordCloud.py file.
- Replace the News API key with your own inside app.py
- Install the latest version of CUDA from: https://developer.nvidia.com/cuda-downloads
- Open Command Prompt
- Browse to the extracted folder, click and copy the folder location
- Type ‘cd’ in Command Prompt, paste the folder location and press enter
- Install the appropriate version of PyTorch from: https://pytorch.org/get-started/previous-versions/
- In my case, I have Windows and CUDA 11 so I copy and run the following in CMD ‘pip install torch==1.12.1+cu116 torchvision==0.13.1+cu116 torchaudio==0.12.1 –extra-index-url https://download.pytorch.org/whl/cu116’
- Run ‘pip install flask pandas transformers numpy scipy matplotlib’ to install all the required python libraries
- Run ‘python app.py’
- If everything is installed correctly it should return no errors and start downloading the language model, it will take a few minutes
- You should get ‘Running on http://127.0.0.1:5000’ when it is finished
- Open your internet browser and navigate to ‘localhost:5000/tweets‘. You should see the following:
How to Update the Word Cloud Image
- Open another Command Prompt window
- ‘cd’ into the app folder again
- Run ‘pip install nltk’
- Run ‘python’ to start a python environment
- In the python environment run ‘nltk.download(‘stopwords’)’
- When it has finished downloading, type ‘exit()’ and press enter to exit the python environment
- Run ‘appWordCloud.py’. After a minute or two an image should pop up. This is updating the app’s trending word cloud image
- Refresh your ‘localhost:5000/tweets‘ page it should have the new updated word cloud image
How to Search for a Ticker
Type the ticker you want to search for and click search. After a minute or two, you will see the following screen. It shows the user, tweet content, sentiment, weight, number of Favorites, and the number of retweets for each tweet. Navigating to the Sentiment Analysis tab will split the tweets between norma and news tweets, showing corresponding sentiment bar charts.