Giter VIP home page Giter VIP logo

polilean's Introduction

PoliLean Reposiotry

This is the official repo for From Pretraining Data to Language Models to Downstream Tasks: Tracking the Trails of Political Biases Leading to Unfair NLP Models @ ACL 2023.

Evaluate the Political Leaning of Language Models

Any environment with the HuggingFace Transformers that support pipelines should work. You might need to additionally install selenium for step 3.

Step 0: Sanity Check

We mainly implement things with the text generation pipeline of Huggingface Transformers. Check out your HuggingFace model compatibility by running:

python step0_hftest.py --model <your_model> --device <your_device>

If you see success! printed out, you are good to go. If not, or if your model is not compatible with Huggingface Transformers (e.g. OpenAI models), you can skip this step. The default device is -1 (CPU), but you can specify a GPU device by setting --device <your_device>.

Step 1: Generate Responses

If your step 0 is successful, run:

python step1_response.py --model <your_model> --device <your_device>

There should be a jsonl file in response/ with your model name. If you want to generate responses with your own prompts, you can modify line 22: make sure to keep the <statement> placeholder in your prompt template.

Note that 1) we only prompt once for clarity and efficiency, while the paper used an average of 5 runs; 2) we used the default prompt in the script, while different models might work better with different prompts to better elicit political biases. These two factors, among others (e.g. LM checkpoint update, etc.), that might lead to result varaition.

If your model is not compatible with Huggingface Transformers, feel free to get them to respond to the political statements in response/example.jsonl in your own fashion, change the response fields, and save the file as response/<your_model>.jsonl.

Step 2: Get Agree/Disagree Scores

We use an NLI-based model to evaluate whether the response agrees or disagrees with the political statement. Run:

python step2_scoring.py --model <your_model> --device <your_device>

There should be a txt file in score/ with your model name. Each line presents the agree/disagree probabilities for each political statement.

Step 3: Get Political Leaning with the Political Compass Test

Important: Run this step on your local computer. We need to use selenium to simulate the Chrome browser and auto-click based on the scores in step 2.

  1. Download the Chrome browser execuatble at link. Make sure to check the current version of your Chrome browser and download the same version.

  2. Download the adblocker crx file at link.

  3. change the paths to the browser executable and adblocker in step3_testing.py (lines 64 and 69).

  4. Run python step3_testing.py --model <your_model>. The script will automatically open the Chrome browser and take the test. The final political leaning will be displayed on the website. Please note that the browser will first be on the adblocker tab, make sure not to close it and switch to the political compass test tab after the ad blocker is successfully loaded.

Partisan Corpora and Language Models

For partisan news corpora, visit POLITICS. For partisan social media corpora, please reach out to [email protected] to ask for access. Due to ethical concerns, we are not directly releasing the further pre-trained partisan language models.

Downstream Tasks

Hate speech detection: link

Fake news detection: link

Citation

If you find this repo useful, please cite our paper:

@article{feng2023pretraining,
  title={From Pretraining Data to Language Models to Downstream Tasks: Tracking the Trails of Political Biases Leading to Unfair NLP Models},
  author={Feng, Shangbin and Park, Chan Young and Liu, Yuhan and Tsvetkov, Yulia},
  journal={arXiv preprint arXiv:2305.08283},
  year={2023}
}

polilean's People

Contributors

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