{"id":13737205,"url":"https://github.com/laura-rieger/deep-explanation-penalization","last_synced_at":"2025-05-08T13:33:20.357Z","repository":{"id":45627123,"uuid":"170393886","full_name":"laura-rieger/deep-explanation-penalization","owner":"laura-rieger","description":"Code for using CDEP from the paper \"Interpretations are useful: penalizing explanations to align neural networks with prior knowledge\" https://arxiv.org/abs/1909.13584","archived":false,"fork":false,"pushed_at":"2021-03-22T02:10:12.000Z","size":260569,"stargazers_count":127,"open_issues_count":1,"forks_count":14,"subscribers_count":9,"default_branch":"master","last_synced_at":"2024-11-15T05:32:24.135Z","etag":null,"topics":["ai","artificial-intelligence","cdep","convolutional-neural-network","data-science","deep-learning","explainability","explainable-ai","fairness","fairness-ml","feature-importance","interpretability","interpretable-deep-learning","jupyter-notebook","machine-learning","ml","neural-network","python","pytorch","recurrent-neural-network"],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","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/laura-rieger.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-02-12T21:26:08.000Z","updated_at":"2024-11-06T14:31:43.000Z","dependencies_parsed_at":"2022-08-27T20:50:57.124Z","dependency_job_id":null,"html_url":"https://github.com/laura-rieger/deep-explanation-penalization","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/laura-rieger%2Fdeep-explanation-penalization","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/laura-rieger%2Fdeep-explanation-penalization/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/laura-rieger%2Fdeep-explanation-penalization/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/laura-rieger%2Fdeep-explanation-penalization/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/laura-rieger","download_url":"https://codeload.github.com/laura-rieger/deep-explanation-penalization/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253077546,"owners_count":21850344,"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":["ai","artificial-intelligence","cdep","convolutional-neural-network","data-science","deep-learning","explainability","explainable-ai","fairness","fairness-ml","feature-importance","interpretability","interpretable-deep-learning","jupyter-notebook","machine-learning","ml","neural-network","python","pytorch","recurrent-neural-network"],"created_at":"2024-08-03T03:01:37.477Z","updated_at":"2025-05-08T13:33:20.333Z","avatar_url":"https://github.com/laura-rieger.png","language":"Jupyter Notebook","funding_links":[],"categories":["Jupyter Notebook"],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003e Making interpretations useful (CDEP) 🔨\u003c/h1\u003e\n\n\u003cp align=\"center\"\u003e Regularizes interpretations (computed via \u003ca href=\"https://github.com/csinva/hierarchical-dnn-interpretations\"\u003econtextual decomposition\u003c/a\u003e) to improve neural networks. Official code for \u003ci\u003eInterpretations are useful: penalizing explanations to align neural networks with prior knowledges\u003c/i\u003e (ICML 2020 \u003ca href=\"https://arxiv.org/abs/1909.13584\"\u003epdf\u003c/a\u003e). \u003c/p\u003e\n\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://img.shields.io/badge/python-3.6--3.9-blue\"\u003e\n  \u003cimg src=\"https://img.shields.io/badge/pytorch-1.0%2B-blue\"\u003e\n  \u003cimg src=\"https://img.shields.io/github/checks-status/laura-rieger/deep-explanation-penalization/master\"\u003e\n  \u003cimg src=\"https://img.shields.io/badge/license-mit-orange.svg\"\u003e\n\u003c/p\u003e  \n\n\u003cp align=\"center\"\u003e\n  \u003ci\u003eNote: this repo is actively maintained. For any questions please file an issue.\u003c/i\u003e\n\u003c/p\u003e  \n\n![fig_intro](fig_intro.png)\n\n# documentation\n\n- fully-contained data/models/code for reproducing and experimenting with CDEP\n- the [src](src) folder contains the core code for running and penalizing contextual decomposition\n- in addition, we run experiments on 4 datasets, each of which are located in their own folders\n  - notebooks in these folders show demos for different kinds of text\n\n# examples\n\n[ISIC skin-cancer classification](isic-skin-cancer) - using CDEP, we can learn to avoid spurious patches present in the training set, improving test performance!\n\n\u003cp align=\"center\"\u003e\n  \u003cimg width=\"60%\" src=\"isic-skin-cancer/results/gradCAM.png\"\u003e\u003c/img\u003e\n\u003c/p\u003e\n\nThe segmentation maps of the patches can be downloaded [here](https://drive.google.com/drive/folders/1Er2PQMwmDSmg3BThyeu-JKX442OkQJit?usp=sharing)\n\n[ColorMNIST](mnist) - penalizing the contributions of individual pixels allows us to teach a network to learn a digit's shape instead of its color, improving its test accuracy from 0.5% to 25.1%\n\n\u003cp align=\"center\"\u003e\n  \u003cimg width=\"80%\" src=\"mnist/results/ColorMNIST_examples.png\"\u003e\u003c/img\u003e\n\u003c/p\u003e\n\n[Fixing text gender biases](text) - CDEP can help to learn spurious biases in a dataset, such as gendered words\n\n\u003cp align=\"center\"\u003e\n  \u003cimg width=\"50%\" src=\"text/results/data_example.png\"\u003e\u003c/img\u003e\n\u003c/p\u003e\n\n# using CDEP on your own data\n\nusing CDEP requires two steps:\n1. run CD/ACD on your model. Specifically, 3 things must be altered:\n  - the pred_ims function must be replaced by a function you write using your own trained model. This function gets predictions from a model given a batch of examples.\n  - the model must be replaced with your model\n  - the current CD implementation doesn't always work for all types of networks. If you are getting an error inside of `cd.py`, you may need to write a custom function that iterates through the layers of your network (for examples see `cd.py`)\n2. add CD scores to the loss function (see notebooks)\n\n# related work\n\n- ACD (ICLR 2019 [pdf](https://openreview.net/pdf?id=SkEqro0ctQ), [github](https://github.com/csinva/hierarchical-dnn-interpretations)) - extends CD to CNNs / arbitrary DNNs, and aggregates explanations into a hierarchy\n- PDR framework (PNAS 2019 [pdf](https://arxiv.org/abs/1901.04592)) - an overarching framewwork for guiding and framing interpretable machine learning\n- TRIM (ICLR 2020 workshop [pdf](https://arxiv.org/abs/2003.01926), [github](https://github.com/csinva/transformation-importance)) - using simple reparameterizations, allows for calculating disentangled importances to transformations of the input (e.g. assigning importances to different frequencies)\n- DAC (arXiv 2019 [pdf](https://arxiv.org/abs/1905.07631), [github](https://github.com/csinva/disentangled-attribution-curves)) - finds disentangled interpretations for random forests\n\n\n# reference\n\n- feel free to use/share this code openly\n- if you find this code useful for your research, please cite the following:\n\n```r\n@inproceedings{rieger2020interpretations,\n  title={Interpretations are useful: penalizing explanations to align neural networks with prior knowledge},\n  author={Rieger, Laura and Singh, Chandan and Murdoch, William and Yu, Bin},\n  booktitle={International Conference on Machine Learning},\n  pages={8116--8126},\n  year={2020},\n  organization={PMLR}\n}\n```\n\n  \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flaura-rieger%2Fdeep-explanation-penalization","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flaura-rieger%2Fdeep-explanation-penalization","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flaura-rieger%2Fdeep-explanation-penalization/lists"}