Giter Club home page Giter Club logo

twitter_sentiment's Introduction

CircleCI

Sentiment Analysis on Tweets

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.

How to use

  1. Clone this repository to your local.

    git clone https://github.com/boblef/twitter_sentiment.git
    
  2. Create a Twitter developer account
    In order to run the Flask application, we need to create a Twitter developer account.

  3. 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. Copy twitter.txt and put it into the config folder with the information you need to set up. What you need is as follows:

    • API KEY
    • SECRET API KEY

    APIKEYS

    • ACCESS TOKEN
    • SECRET ACCESS TOKEN

    TOKENS


    Copy all of them from your Twitter developer dashboard and paste them to config/twitter.txt

    Twitter_config

  4. 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
    docker build -t twitter_sentiment:latest .
    
    Run the image
    docker run -d -p 5000:5000 twitter_sentiment:latest
    
    Open up your browser, and copy and paste the link below. The application is supposed to start.
    http://localhost:5000/
    
  • Conda Create a conda env whose name is going to be finbert
    conda env create -f environment.yml
    
    Activate the conda env you just created
    source activate finbert
    or
    conda activate finbert
    
    Run the application
    python app.py
    

Further Work

  • 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.

Reference

twitter_sentiment's People

Contributors

boblef avatar

Stargazers

Anastasia Kinanti Putri avatar Antonios Mavridis avatar Rairo Mukamuri avatar

Watchers

paper2code - bot avatar

Forkers

kalmax

twitter_sentiment's Issues

ran into this issue while running the app

(base) young@young-1:~/Desktop/code/trading/twitter_sentiment$ python3 app.py
[nltk_data] Downloading package punkt to /home/young/nltk_data...
[nltk_data] Package punkt is already up-to-date!
05/14/2021 09:18:33 - INFO - pytorch_pretrained_bert.modeling - loading archive file model/sentiment/finbert
05/14/2021 09:18:33 - INFO - pytorch_pretrained_bert.modeling - Model config {
"attention_probs_dropout_prob": 0.1,
"hidden_act": "gelu",
"hidden_dropout_prob": 0.1,
"hidden_size": 768,
"initializer_range": 0.02,
"intermediate_size": 3072,
"max_position_embeddings": 512,
"num_attention_heads": 12,
"num_hidden_layers": 12,
"type_vocab_size": 2,
"vocab_size": 30522
}

Traceback (most recent call last):
File "app.py", line 36, in
model = BertForSequenceClassification.from_pretrained(
File "/home/young/.local/lib/python3.8/site-packages/pytorch_pretrained_bert/modeling.py", line 603, in from_pretrained
state_dict = torch.load(weights_path, map_location='cpu')
File "/home/young/anaconda3/lib/python3.8/site-packages/torch/serialization.py", line 595, in load
return _legacy_load(opened_file, map_location, pickle_module, **pickle_load_args)
File "/home/young/anaconda3/lib/python3.8/site-packages/torch/serialization.py", line 764, in _legacy_load
magic_number = pickle_module.load(f, **pickle_load_args)
_pickle.UnpicklingError: invalid load key, 'v'.

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.