{"id":15691063,"url":"https://github.com/csinva/transformation-importance","last_synced_at":"2025-05-08T00:51:25.542Z","repository":{"id":97069848,"uuid":"222606958","full_name":"csinva/transformation-importance","owner":"csinva","description":"Using / reproducing TRIM from the paper \"Transformation Importance with Applications to Cosmology\" 🌌 (ICLR Workshop 2020)","archived":false,"fork":false,"pushed_at":"2020-12-16T18:07:35.000Z","size":79312,"stargazers_count":9,"open_issues_count":1,"forks_count":1,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-05-08T00:51:24.709Z","etag":null,"topics":["ai","artificial-intelligence","attribution","data-science","deep-learning","deep-neural-networks","explainability","explainable-ai","feature-engineering","feature-importance","frequency-domain","interpretability","interpretation","machine-learning","ml","neural-network","pytorch","transform","transformation","wavelet-analysis"],"latest_commit_sha":null,"homepage":"https://arxiv.org/abs/2003.01926","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/csinva.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-11-19T04:17:42.000Z","updated_at":"2024-11-06T14:43:49.000Z","dependencies_parsed_at":"2023-03-22T18:33:58.556Z","dependency_job_id":null,"html_url":"https://github.com/csinva/transformation-importance","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/csinva%2Ftransformation-importance","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/csinva%2Ftransformation-importance/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/csinva%2Ftransformation-importance/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/csinva%2Ftransformation-importance/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/csinva","download_url":"https://codeload.github.com/csinva/transformation-importance/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252978690,"owners_count":21834913,"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","attribution","data-science","deep-learning","deep-neural-networks","explainability","explainable-ai","feature-engineering","feature-importance","frequency-domain","interpretability","interpretation","machine-learning","ml","neural-network","pytorch","transform","transformation","wavelet-analysis"],"created_at":"2024-10-03T18:19:45.610Z","updated_at":"2025-05-08T00:51:25.518Z","avatar_url":"https://github.com/csinva.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"Official code for using / reproducing TRIM from the paper [Transformation Importance with Applications to Cosmology](https://arxiv.org/abs/2003.01926) (ICLR 2020 Workshop). This code shows examples and provides useful wrappers for calculating importance in a transformed feature space.\n\n*This repo is actively maintained. For any questions please file an issue.*\n\n![trim](trim/trim.png)\n\n# examples/documentation\n\n- **dependencies**: depends on the pip-installable [acd package](https://github.com/csinva/hierarchical-dnn-interpretations)\n- **examples**: different folders (e.g. [ex_cosmology](ex_cosmology), [ex_fake_news](ex_fake_news), [ex_mnist](ex_mnist), [ex_urban_sound](ex_urban_sound) contain examples for using TRIM in different settings)\n- **src**: the core code is in the [trim](trim) folder, containing wrappers and code for different transformations\n- **requirements**: tested with python 3.7 and pytorch \u003e 1.0\n\n\n| Attribution to different scales in cosmological images | Fake news attribution to different topics |\n| ------------------------------------------------------ | ----------------------------------------- |\n| ![](ex_cosmology/fig_omegam_curves.png)                | ![](ex_fake_news/fig_fakenews.png)        |\n\n| Attribution to different NMF components in MNIST classification | Attribution to different frequencies in audio classification |\n| ------------------------------------------------------------ | ------------------------------------------------------------ |\n| ![](ex_mnist/fig_nmf.png)                                    | ![](ex_urban_sound/fig_audio.png)                            |\n\n# sample usage\n\n```python\nimport torch\nimport torch.nn as nn\nfrom trim import TrimModel\nfrom functools import partial\n\n# setup a trim model\nmodel = nn.Sequential(nn.Linear(10, 10), nn.ReLU(), nn.Linear(10, 1)) # orig model\ntransform = partial(torch.rfft, signal_ndim=1, onesided=False) # fft\ninv_transform = partial(torch.irfft, signal_ndim=1, onesided=False) # inverse fft\nmodel_trim = TrimModel(model=model, inv_transform=inv_transform) # trim model\n\n# get a data point\nx = torch.randn(1, 10)\ns = transform(x)\n\n# can now use any attribution method on the trim model\n# get (input_x_gradient) attribution in the fft space\ns.requires_grad = True\nmodel_trim(s).backward()\ninput_x_gradient = s.grad * s\n```\n- see notebooks for more detailed usage\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- CDEP (ICML 2020 [pdf](https://arxiv.org/abs/1909.13584), [github](https://github.com/laura-rieger/deep-explanation-penalization)) - penalizes CD / ACD scores during training to make models generalize better\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- PDR framework (PNAS 2019 [pdf](https://arxiv.org/abs/1901.04592)) - an overarching framewwork for guiding and framing interpretable machine learning\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@article{singh2020transformation,\n    title={Transformation Importance with Applications to Cosmology},\n    author={Singh, Chandan and Ha, Wooseok and Lanusse, Francois, and Boehm, Vanessa, and Liu, Jia and Yu, Bin},\n    journal={arXiv preprint arXiv:2003.01926},\n    year={2020},\n    url={https://arxiv.org/abs/2003.01926},\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcsinva%2Ftransformation-importance","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcsinva%2Ftransformation-importance","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcsinva%2Ftransformation-importance/lists"}