{"about":{"site":"https://codewithpapers.app","non_affiliation":"Code with Papers and Syntology are not affiliated with, endorsed by, or sponsored by Papers with Code, Meta, or the pwc-archive mirror.","licence":"CC BY-SA 4.0","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","attribution":"https://codewithpapers.app/attribution","modified":"archive material modified by Syntology; see the attribution page"},"url":"/paper/causalm-causal-model-explanation-through","title":"CausaLM: Causal Model Explanation Through Counterfactual Language Models","arxiv_id":"2005.13407","date":"2020-05-27","proceeding":"CL (ACL) 2021 6","authors":["Amir Feder","Nadav Oved","Uri Shalit","Roi Reichart"],"abstract":"Understanding predictions made by deep neural networks is notoriously difficult, but also crucial to their dissemination. As all machine learning based methods, they are as good as their training data, and can also capture unwanted biases. While there are tools that can help understand whether such biases exist, they do not distinguish between correlation and causation, and might be ill-suited for text-based models and for reasoning about high level language concepts. A key problem of estimating the causal effect of a concept of interest on a given model is that this estimation requires the generation of counterfactual examples, which is challenging with existing generation technology. To bridge that gap, we propose CausaLM, a framework for producing causal model explanations using counterfactual language representation models. Our approach is based on fine-tuning of deep contextualized embedding models with auxiliary adversarial tasks derived from the causal graph of the problem. Concretely, we show that by carefully choosing auxiliary adversarial pre-training tasks, language representation models such as BERT can effectively learn a counterfactual representation for a given concept of interest, and be used to estimate its true causal effect on model performance. A byproduct of our method is a language representation model that is unaffected by the tested concept, which can be useful in mitigating unwanted bias ingrained in the data.","url_abs":"https://arxiv.org/abs/2005.13407v5","url_pdf":"https://arxiv.org/pdf/2005.13407v5.pdf","source":{"archive":"pwc-archive (Hugging Face), CC BY-SA 4.0","snapshot":"2025-07-28","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","row_kind":"abstracts"},"code_links":[{"paper_slug":"causalm-causal-model-explanation-through","repo_url":"https://github.com/amirfeder/causalm","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"pytorch","reach":{"status":"ok","spdx":"MIT"}}],"tasks":[{"task_slug":null,"task_name":"counterfactual"}],"methods":[{"method_slug":"adam","method_name":"Adam"},{"method_slug":"attention","method_name":"Attention"},{"method_slug":"attention-dropout","method_name":"Attention Dropout"},{"method_slug":"bert","method_name":"BERT"},{"method_slug":"dense-connections","method_name":"Dense Connections"},{"method_slug":"dropout","method_name":"Dropout"},{"method_slug":"layer-normalization","method_name":"Layer Normalization"},{"method_slug":"linear-layer","method_name":"Linear Layer"},{"method_slug":"linear-warmup-with-linear-decay","method_name":"Linear Warmup With Linear Decay"},{"method_slug":"multi-head-attention","method_name":"Multi-Head Attention"},{"method_slug":"residual-connection","method_name":"Residual Connection"},{"method_slug":"softmax","method_name":"Softmax"},{"method_slug":"weight-decay","method_name":"Weight Decay"},{"method_slug":"wordpiece","method_name":"WordPiece"}],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"atlas_url":"https://app.syntology.ai/?focus=2005.13407","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2005.13407"}},"developers":"https://syntology.ai/developers","read_at":"2026-09-24T18:15:14+00:00","read_at_is":"when the build read Syntology's graph, not when any sample ran","claim":"Per-sample execution status on synthesized fixtures; not a correctness claim about the paper. Samples come from repositories linked to the paper, official or community; repo_kind says which.","repos":[{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/amirfeder/causalm","reach":{"status":"ok","spdx":"MIT"}}],"summary":{"unverified":7},"by_repo_kind":{"listed":{"samples":7,"ran":0,"repositories":1}},"repo_kind_vocabulary":{"official":"The archive marks this repository official for the paper","named_in_paper":"The archive records that the paper mentions this repository; it is not marked official","listed":"In the archive's code links for this paper, not marked official and not recorded as mentioned in the paper","found_in_text":"Syntology found this repository in the paper's own text; whether it is the authors' implementation is not asserted","community":"Not in the archive's code links for this paper; a community repository Syntology harvested"},"n_pointer_only_for_licence":0,"samples":[{"code_sha256_prefix":"8ab4fa497a55a046","entry":"convert_example_to_features","repo":"amirfeder/causalm","repo_kind":"listed","path":"POMS_GendeRace/lm_finetune/mlm_finetune_on_pregenerated.py","file_url":"https://github.com/amirfeder/causalm/blob/HEAD/POMS_GendeRace/lm_finetune/mlm_finetune_on_pregenerated.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"8ab4fa497a55a046"}},{"code_sha256_prefix":"4c7fb231eb09ef4a","entry":"find_latest_model_checkpoint","repo":"amirfeder/causalm","repo_kind":"listed","path":"utils.py","file_url":"https://github.com/amirfeder/causalm/blob/HEAD/utils.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"4c7fb231eb09ef4a"}},{"code_sha256_prefix":"4642b12429332a66","entry":"get_checkpoint_file","repo":"amirfeder/causalm","repo_kind":"listed","path":"utils.py","file_url":"https://github.com/amirfeder/causalm/blob/HEAD/utils.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"4642b12429332a66"}},{"code_sha256_prefix":"ad89fcb2b2636278","entry":"init_logger","repo":"amirfeder/causalm","repo_kind":"listed","path":"utils.py","file_url":"https://github.com/amirfeder/causalm/blob/HEAD/utils.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"ad89fcb2b2636278"}},{"code_sha256_prefix":"30d161b10ae8efc7","entry":"truncate_seq","repo":"amirfeder/causalm","repo_kind":"listed","path":"POMS_GendeRace/lm_finetune/pregenerate_training_data.py","file_url":"https://github.com/amirfeder/causalm/blob/HEAD/POMS_GendeRace/lm_finetune/pregenerate_training_data.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"30d161b10ae8efc7"}},{"code_sha256_prefix":"9fee8bd9487f8035","entry":"truncate_seq_first","repo":"amirfeder/causalm","repo_kind":"listed","path":"BERT/bert_text_dataset.py","file_url":"https://github.com/amirfeder/causalm/blob/HEAD/BERT/bert_text_dataset.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"9fee8bd9487f8035"}},{"code_sha256_prefix":"a02e2bb7011c0296","entry":"truncate_seq_random_sub","repo":"amirfeder/causalm","repo_kind":"listed","path":"BERT/bert_text_dataset.py","file_url":"https://github.com/amirfeder/causalm/blob/HEAD/BERT/bert_text_dataset.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"a02e2bb7011c0296"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}