{"id":26246006,"url":"https://github.com/blei-lab/causal-text-embeddings","last_synced_at":"2025-10-18T01:09:59.926Z","repository":{"id":58987871,"uuid":"189052931","full_name":"blei-lab/causal-text-embeddings","owner":"blei-lab","description":"Software and data for \"Using Text Embeddings for Causal Inference\"","archived":false,"fork":false,"pushed_at":"2020-09-23T17:32:00.000Z","size":4325,"stargazers_count":124,"open_issues_count":3,"forks_count":18,"subscribers_count":28,"default_branch":"master","last_synced_at":"2025-03-30T03:11:46.002Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/blei-lab.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":"2019-05-28T15:15:15.000Z","updated_at":"2025-01-31T11:09:07.000Z","dependencies_parsed_at":"2022-09-25T08:23:45.269Z","dependency_job_id":null,"html_url":"https://github.com/blei-lab/causal-text-embeddings","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/blei-lab%2Fcausal-text-embeddings","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blei-lab%2Fcausal-text-embeddings/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blei-lab%2Fcausal-text-embeddings/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/blei-lab%2Fcausal-text-embeddings/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/blei-lab","download_url":"https://codeload.github.com/blei-lab/causal-text-embeddings/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250507832,"owners_count":21442108,"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-13T13:17:08.186Z","updated_at":"2025-10-18T01:09:54.870Z","avatar_url":"https://github.com/blei-lab.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Introduction\n\nThis repository contains software and data for \"Using Text Embeddings for Causal Inference\" ([arxiv.org/abs/1905.12741](https://arxiv.org/abs/1905.12741)).\nThe paper describes a method for causal inference with text documents. For example, does adding a\ntheorem to a paper affect its chance of acceptance? The method adapts deep language models to address the causal problem. \n\nThis software builds on\n1. Bert: [github.com/google-research/bert](https://github.com/google-research/bert), and on\n2. PeerRead: [github.com/allenai/PeerRead](https://github.com/allenai/PeerRead)\n\nWe include pre-processed PeerRead arxiv data for convenience.\n\nThere is also a [reference implementation in pytorch.](https://github.com/rpryzant/causal-bert-pytorch)\n\n# Tensorflow 2\nFor new projects, we recommend building on the [reference tensorflow 2 implementation](https://github.com/vveitch/causal-text-embeddings-tf2).\n\n# Requirements and setup\n\n1. You'll need to download a pre-trained BERT model (following the above github link). We use `uncased_L-12_H-768_A-12`.\n2. Install Tensorflow 1.12\n\n# Data\n\n1. We include a pre-processed copy of PeerRead data for convenience.\nThis data is a collection of arXiv papers submitted to computer science conferences, the accept/reject decisions for these papers,\nand their abstracts.\nThe raw PeerRead data contains significantly more information.\nYou can get the raw data by following instructions at [github.com/allenai/PeerRead](https://github.com/allenai/PeerRead). \nRunning the included pre-processing scripts in the PeerRead folder will recreate the included tfrecord file. \n\n2. The reddit data can be downloaded at [archive.org/details/reddit_posts_2018](https://archive.org/details/reddit_posts_2018).\nThis data includes all top-level reddit comments where the gender of the poster was annotated in some fashion.\nEach post has meta information (score, date, username, etc.) and includes the text for the first reply.\nThe processed data used in the paper can be recreated by running the pre-processing scripts in the `reddit` folder.\n\nYou can also re-collect the data from Google BigQuery.\nThe SQL command to do this is in `reddit/data_cleaning/BigQuery_get_data`.\nModifying this script will allow you to change collection parameters (e.g., the year, which responses are included)\n\n\n# Reproducing the PeerRead experiments\n\nThe default settings for the code match the settings used in the software.\nThese match the default settings used by BERT, except\n1. we reduce batch size to allow training on a Titan X, and\n2. we adjust the learning rate to account for this.\n\nYou'll run the from `src` code as \n`./PeerRead/submit_scripts/run_model.sh`\nBefore doing this, you'll need to edit `run_classifier.sh` to change \n`BERT_BASE_DIR=../../bert/pre-trained/uncased_L-12_H-768_A-12`\nto\n`BERT_BASE_DIR=[path to BERT_pre-trained]/uncased_L-12_H-768_A-12`.\n\nThe flag \n`--treatment=theorem_referenced`\ncontrols the experiment. \nThe flag \n`--simulated=real`\ncontrols whether to use the real effect or one of the semi-synthetic modes.\n\nThe effect estimates can be reproduced by running `python -m result_processing.compute_ate`.\nThis takes in the predictions of the bert model (in tsv format) and passes them into downstream estimators\nof the causal effect.\n\nTo reproduce the baselines, you'll need to produce a tsv for each simulated dataset you want to test on. To do this, you can run `python -m PeerRead.dataset.array_from_dataset` from src. The flag `--beta1=1.0` controls the strength of the confounding. (The other flags control other simulation parameters not used in the paper.)\n\n# Misc.\n\nThe experiments in the paper use a version of BERT that was further pre-trained on the PeerRead corpus\nusing an unsupervised objective. \nThis can be replicated with `./PeerRead/submit_scripts/run_classifier.sh`.\nThis takes about 24 hours on a single Titan Xp.\nTo use a pre-trained BERT, uncomment the `INIT_DIR` options in `run_classifier.sh`.\n\n# Reproducing the Reddit experiment\n\n1. First, get the data following instructions above and save it as `dat/reddit/2018.json`\n2. Run data pre-processing with `python -m reddit.data_cleaning.process_reddit`\n3. Once the data is processed, instructions for running the experiments are essentially the same as for PeerRead\n\n# Maintainers\n[Dhanya Sridhar](https://github.com/dsridhar91`) and [Victor Veitch](`github.com/vveitch`)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblei-lab%2Fcausal-text-embeddings","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fblei-lab%2Fcausal-text-embeddings","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblei-lab%2Fcausal-text-embeddings/lists"}