In order to use Twitter’s API, we have to create a developer account on the Twitter apps site.
-
Log in or make a Twitter account at Twitter.com
-
Apply for a twitter developer account here
-
Make sure you select a student account
-
Add account details. Click on continue.
-
Describe in your own words what you are building. Click on continue.
-
Submit application.
-
Check your email associated with your twitter and click Confirm your email.
-
On the welcome screen, click on Create an app.
-
Fill out your App details and click on Create (its at the bottom of the page). Make sure you don’t try to make a appName that is already taken.
-
First, click on Keys and tokens. Second, click on create to get access token and access token secret.
Save your API key, API secret key, Access token, and Access token secret somewhere safe.
-
Replace the keys in the keys.py
keys = dict(consumer_key="<consumer key>", consumer_secret="<consumer secret>", access_token='<access token>', access_token_secret='<access token secret>' )
- A decent Multi-Core CPU (4+ cores)
- macOS or any Linux Distros
- Python 3.7
$ git clone https://github.com/shivchander/political-alignment-prediction.git
Download the dataset from kaggle.com using your kaggle account
Save the CSV files under a new directory dataset/
All the required libraries are in requirements.txt, simply run this file to install all the requirements
$ pip3 install -r requirements.txt
There is a pre-trained model, one could just use that to make the predictions. Or you could train your own model using you own dataset
The model config and weights are saved under model/
To use these models, make sure the path to the file is correct under src/main.py
json_file = open('model/model.json', 'r')
loaded_model.load_weights("model/model.h5")
Use the ipynb notebook and the intructions from it to train your own model
Download the .h5 file and .json file and save them under model/
To make final predictions, run the following commands. The code takes twitter handle as an input and outputs the results in form of:
[tweet_score, tweet_prediction, retweet_score, rt_prediction, favtweet_score, ft_prediction, weighted_score, final_prediction]
To run the program, use this:
$ python3 main.py <twitter handle>
Sample Result:
$ python3 main.py RepMarkTakai
...
User RepMarkTakai
tweet_score 0.874494
tweet_prediction democrat
retweet_score 0.939216
retweet prediction democrat
liked_tweet_score 0.841564
liked_tweet_prediction democrat
weighted_score 0.892207
final_prediction democrat
If you need assistance using Deep Pollster or have any further questions:
Contact us:
If there is a bug in our code, raise an issue on our Github Repo