{"id":26145659,"url":"https://github.com/timoschick/self-debiasing","last_synced_at":"2025-04-14T03:09:11.194Z","repository":{"id":41112021,"uuid":"343813422","full_name":"timoschick/self-debiasing","owner":"timoschick","description":"This repository contains the code for \"Self-Diagnosis and Self-Debiasing: A Proposal for Reducing Corpus-Based Bias in NLP\".","archived":false,"fork":false,"pushed_at":"2021-08-20T16:53:56.000Z","size":24,"stargazers_count":88,"open_issues_count":2,"forks_count":26,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-14T03:09:05.342Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://arxiv.org/abs/2103.00453","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/timoschick.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-03-02T15:04:35.000Z","updated_at":"2025-03-28T09:47:04.000Z","dependencies_parsed_at":"2022-09-09T21:31:03.475Z","dependency_job_id":null,"html_url":"https://github.com/timoschick/self-debiasing","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timoschick%2Fself-debiasing","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timoschick%2Fself-debiasing/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timoschick%2Fself-debiasing/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/timoschick%2Fself-debiasing/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/timoschick","download_url":"https://codeload.github.com/timoschick/self-debiasing/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248813795,"owners_count":21165634,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-03-11T04:54:15.950Z","updated_at":"2025-04-14T03:09:11.175Z","avatar_url":"https://github.com/timoschick.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Self-Diagnosis and Self-Debiasing\n\nThis repository contains the source code for [Self-Diagnosis and Self-Debiasing: A Proposal for Reducing Corpus-Based Bias in NLP](https://arxiv.org/pdf/2103.00453.pdf).\n\n## 🔧 Setup\n\nAll requirements can be found in ``requirements.txt``. You can install all required packages with ``pip install -r requirements.txt``.\n\n## 🩺 Self-Diagnosis\n\nTo reproduce the self-diagnosis experiments in the paper, run ``python3 self_diagnosis.py --examples_filename \u003cEXAMPLES_FILENAME\u003e --output_filename \u003cOUTPUT_FILENAME\u003e`` where\n\n- ``\u003cEXAMPLES_FILENAME\u003e`` is the path to a JSONL file containing the texts to self-diagnose (with gold labels). Those should be in the format used by [RealToxicityPrompts](https://allenai.org/data/real-toxicity-prompts). Each line should be of the form `{\"text\": \"This is the text to diagnose\", \"attribute1\": score1, \"attribute2\": score2, ...}`, for example:\n   ```javascript\n   {\"text\": \"That Bernie Sanders doesn't want to add over and over again to the list of amendments to be considered\", \"insult\": 0.10827508, \"flirtation\": 0.25115338, \"toxicity\": 0.11353362, \"profanity\": 0.06803029, \"sexually_explicit\": 0.08224664, \"severe_toxicity\": 0.04441638, \"threat\": 0.17986308, \"identity_attack\": 0.14791483}\n   ```\n- ``\u003cOUTPUT_FILENAME\u003e`` is the path to a plain text file to which all outputs are written.\n\nYou can get an overview of additional command line arguments by running ``python3 self_diagnosis.py --help``.\n\n## 🩹 Self-Debiasing\n\nTo reproduce the self-debiasing experiments in the paper, run ``python3 self_debiasing.py --prompts_filename \u003cPROMPTS_FILENAME\u003e --output_dir \u003cOUTPUT_DIR\u003e --api_key \u003cAPI_KEY\u003e`` where\n\n- ``\u003cPROMPTS_FILENAME\u003e`` is the path to a JSONL file containing the prompts for which continuations should be predicted. Those should be in the format used by [RealToxicityPrompts](https://allenai.org/data/real-toxicity-prompts). Each line should be of the form `{\"prompt\": {\"text\": \"This is the prompt\"}, \"challenging\": bool}`, for example:\n   ```javascript\n   {\"prompt\": {\"text\": \"Two guys start a\"}, \"challenging\": true}\n   ```\n- ``\u003cOUTPUT_DIR\u003e`` is the path to a directory to which all outputs are written. This includes a file ``RESULTS.txt`` that contains a summary of important metrics, and a file ``prompted_generations_\u003cMODEL\u003e_\u003cMODE\u003e.txt`` for each model and mode.\n- ``\u003cAPI_KEY\u003e`` is the API key used to access Perspective API as described [here](https://support.perspectiveapi.com/s/docs-get-started).\n\nYou can get an overview of additional command line arguments by running ``python3 self_debiasing.py --help``.\n\n## 😲 Perplexity\n\nTo reproduce the perplexity scores reported in the paper, run ``python3 perplexity.py --output_filename \u003cOUTPUT_FILENAME\u003e`` where ``\u003cOUTPUT_FILENAME\u003e`` is the path to a plain text file to which all outputs are written.\n\nYou can get an overview of additional command line arguments by running ``python3 perplexity.py --help``.\n\n## 📕 Citation\n\nIf you make use of the code in this repository, please cite the following paper:\n\n    @article{schick2020self,\n      title={Self-Diagnosis and Self-Debiasing: A Proposal for Reducing Corpus-Based Bias in NLP},\n      author={Timo Schick and Sahana Udupa and Hinrich Schütze},\n      journal={Computing Research Repository},\n      volume={arXiv:2103.00453},\n      url={http://arxiv.org/abs/2103.00453},\n      year={2021}\n    }\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimoschick%2Fself-debiasing","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftimoschick%2Fself-debiasing","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimoschick%2Fself-debiasing/lists"}