Coder Social home page Coder Social logo

politiclassify's Introduction

PolitiClassify

A Python package for classifying Twitter users' political orientation using two-step deep learning models.

In the first step, the model classifies the political orientation of individual tweets. In the second step, the model classifies the political orientation of individual users based on their multiple tweets and output the label (0 for liberal/democratic; 1 for conservative/republican) for each user. The accuracy of using this two-step method to classify non-politician Twitter users' political orientation based on their 200 tweets is around 96.33%.

Two trained models can be chosen for the first step of the method: LSTM and BERT. The trained BERT model is the default and will be automatically downloaded. The trained LSTM model needs to be downloaded from here. After downloading the trained LSTM model, you can store the model in the "trained_models" folder, or you can specify the path of the model in the function argument "step1_model_path.

To use this Python package, you can install it by using:

pip install PolitiClassify

Then you can import the functions from the package and use it as follows:

from PolitiClassify import two_step_BERT_predict
user_pred = two_step_BERT_predict(
    data_path="data/example_tweets.csv",
    text_variable="text",
    user_variable="user_id"
    )

If you prefer to use the trained LSTM model as the first-step model, you can do the following:

from PolitiClassify import two_step_LSTM_predict
user_pred = two_step_LSTM_predict(
    step1_model_path="trained_models/cong_politician_2020-3-12-2021-5-28_balanced_pre-w2v.h5",
    data_path="data/example_tweets.csv",
    text_variable="text",
    user_variable="user_id"
    )

Alternatively, you can download it from GitHub, store your dataset in the "data" folder, change the name of the dataset in the config.py file, and then run PolitiClassify.py in your terminal.

Please cite this paper:

@article{HuL,
     author = {Lingshu Hu},
     title = {A Two-Step Method for Classifying Political Partisanship Using Deep Learning Models},
     journal = {Social Science Computer Review},
     DOI = {10.1177/08944393231219685},
     year = {2023}
}

The training dataset can be obtained from kaggle.

politiclassify's People

Contributors

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