{"id":13958822,"url":"https://github.com/google-research/graph-attribution","last_synced_at":"2025-04-24T07:30:31.044Z","repository":{"id":54224166,"uuid":"312698676","full_name":"google-research/graph-attribution","owner":"google-research","description":"Codebase for Evaluating Attribution for Graph Neural Networks.","archived":false,"fork":false,"pushed_at":"2021-03-02T15:45:50.000Z","size":31811,"stargazers_count":76,"open_issues_count":2,"forks_count":16,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-04-03T00:51:55.312Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","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/google-research.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":"2020-11-13T22:35:26.000Z","updated_at":"2025-03-08T02:31:55.000Z","dependencies_parsed_at":"2022-08-13T09:31:15.584Z","dependency_job_id":null,"html_url":"https://github.com/google-research/graph-attribution","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/google-research%2Fgraph-attribution","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/google-research%2Fgraph-attribution/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/google-research%2Fgraph-attribution/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/google-research%2Fgraph-attribution/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/google-research","download_url":"https://codeload.github.com/google-research/graph-attribution/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250582773,"owners_count":21453911,"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":"2024-08-08T13:01:53.225Z","updated_at":"2025-04-24T07:30:27.952Z","avatar_url":"https://github.com/google-research.png","language":"Jupyter Notebook","funding_links":[],"categories":["其他_图神经网络GNN"],"sub_categories":["网络服务_其他"],"readme":"# Codebase for [_Evaluating Attribution for Graph Neural Networks_](https://papers.nips.cc/paper/2020/hash/417fbbf2e9d5a28a855a11894b2e795a-Abstract.html).\n\n![Schematic figure](media/TOC.png)\n\n\nAttribution is one tool in the interpretability toolkit that provides ranked importance values on an input (x) in relation to an output (y). You might care about using attribution techniques on models if you want to build credibility, if you want to debug a model, or want to create a hypothesis for scientific discovery. Not all attribution methods are created equal and practitioners should understand the strengths and weakness of these techniques. We can evaluate these techniques because graphs are a natural testbed: we can create synthetic graph tasks where we can generate labels and ground truth attributions.\n\n## Quickstart\n\nA code snippet that demonstrastes how to create an attribution on a graph:\n```python\nimport graph_attribution as gatt\n\ntask_type = 'benzene'\nblock_type = 'gcn'\nexp, task, methods = gatt.experiments.get_experiment_setup(task_type, block_type)\nhp = gatt.hparams.get_hparams({'block_type':block_type, 'task_type':task_type})\ngnn = experiments.GNN.from_hparams(hp, task)\ngnn(exp.x_test)\n# Train model here!\npred_att = methods['CAM'].attribute(exp.x_test, gnn)\nresult = task.evaluate_attributions(exp.att_test, pred_att)\nprint(result) # A dict of attribution statistics.\n```\n\n\nIf you want to get up and running with building graph attributions from scratch, we recommend you run [notebooks/train_and_evaluate.ipynb](https://github.com/google-research/graph-attribution/blob/main/notebooks/train_attribute_and_evaluate.ipynb), which sets up an attribution task, trains a GNN on a predictive task, and calculates attributions with several techniques, and finally evaluates the attributions. At the end of the notebook, you can visually compare graph attributions.\n\nYou can run code to replicate all results in the [paper][gnnatt]  using [notebooks/plot_evaluation_results.ipynb](https://github.com/google-research/graph-attribution/blob/main/notebooks/plot_evaluation_results.ipynb), which you can also [run live in Colab (no downloads required)](https://colab.sandbox.google.com/github/google-research/graph-attribution/blob/main/notebooks/plot_evaluation_results.ipynb).\n\nIf you'd like to run the code locally, or extend it, read on.\n\n## What's implemented?\nAttribution techniques:\n* [Grad * Input][grad_times_input]\n* [CAM (Class activation maps)][cam]\n* [GradCAM (Gradient CAM)][gradcam]\n* [SmoothGrad][smoothgrad]\n* [Integrated Gradients][ig]\n* [Attention weights][gat]\n\nWe test attribution quality on several GNN architectures:\n* [GCN (Graph Convolution Network)][gcn], where our learnt representations depend on learnt nodes.\n* [GAT (Graph Attention Network)][gat], where message passing happens via an attention mechanism.\n* [MPNN (Message Passing Neural Network)][mpnn], where our learnt representations depend on learnt nodes and edges.\n* [GraphNets][graphnets], learning node, edge and global embeddings and conditioning each based on these learnt attributes.\n\n## Have an idea you want to test?\n\nTo test out new ideas check out **graph_attribution/templates.py**, which has all main abstract classes in the codebase. In particular **AttributionTask** is useful for tasks, **TransparentModel** for GNN models, **AttributionTechnique** for new attribution techniques.\n\n\n## Code structure\nThe rest of the files are organized as:\n* **data/** holds all datasets, one folder per task.\n    * **data/dataset_bias** holds a folder for each spurious correlation task.\n    * **data/results** holds CSV files with results from the [main publication][gnnatt].\n    * **data/NOTICE** details properties of this data redistribution.\n* **notebooks/** holds Jupyter notebooks.\n* **scripts/** python scripts for generating datasets.\n* **graph_attribution/** holds the code for creating models, generating and evaluating attributions.\n\n\n## Installing\nThe codebase is primarily a [Tensorflow 2.0](https://www.tensorflow.org/install) based framework that uses [Sonnet](https://github.com/deepmind/sonnet) and\n[Graph Nets](https://github.com/deepmind/graph_nets) for building GNN models.\nIf you are using pre-generated datsets, you can git clone the repo and pip install it:\n```\npip install git+https://github.com/google-research/graph-attribution\n```\nIf you plan on generating datasets, we recommend using [Anaconda](https://www.anaconda.com/) for installing all dependencies. Requirements can be installed into a fresh conda environment as follows:\n\n```bash\n$ conda env create -f environment.yml -n graph_attribution\n```\n\nOnce installed you can run a notebook but running:\n```bash\n$ conda activate graph_attribution\n$ jupyter notebook *.ipynb\n```\n\n## Giving Credit\nIf you use this code in your work, we ask that you cite our work. Here is an example\nBibTex entry:\n\n```\n@article{NEURIPS2020_6054,\n  title     = {Evaluating Attribution for Graph Neural Networks},\n  author = {Benjamin Sanchez-Lengeling and Jennifer Wei and Brian Lee and Emily Reif and Wesley Qian and Yiliu Wang and Kevin James McCloskey and Lucy Colwell and Alexander B Wiltschko},\n  booktitle = {Advances in Neural Information Processing Systems 33},\n  year      = {2020},\n  url       = {https://papers.nips.cc/paper/2020/hash/417fbbf2e9d5a28a855a11894b2e795a-Abstract.html},\n}\n```\n\n## Related work\nIf you cite this work, you may also want to cite:\n\n* [McCloskey, K., Taly, A., Monti, F., Brenner, M. P. \u0026 Colwell, L. J. Using attribution to decode binding mechanism in neural network models for chemistry. Proc. Natl. Acad. Sci. U. S. A. 116, 11624–11629 (2019)][bias]\n* [Ying, Z., Bourgeois, D., You, J., Zitnik, M. \u0026 Leskovec, J. GNNExplainer: Generating Explanations for Graph Neural Networks. in Advances in Neural Information Processing Systems (eds. Wallach, H. et al.) vol. 32 9244–9255 (Curran Associates, Inc., 2019).][explainer]\n\n[bias]: https://www.pnas.org/content/116/24/11624\n[explainer]: https://arxiv.org/abs/1903.03894\n[gnnatt]: https://papers.nips.cc/paper/2020/file/417fbbf2e9d5a28a855a11894b2e795a-Paper.pdf\n[mpnn]: https://arxiv.org/abs/1704.01212\n[gcn]: https://arxiv.org/abs/1509.09292\n[graphnets]:arxiv.org/abs/1806.01261\n[gat]: https://arxiv.org/abs/1710.10903\n[grad_times_input]:https://arxiv.org/abs/1605.01713\n[cam]: https://arxiv.org/abs/1512.04150\n[gradcam]: https://arxiv.org/abs/1610.02391\n[smoothgrad]: https://arxiv.org/abs/1706.03825\n[ig]: https://arxiv.org/abs/1703.01365\n\nThis is not an official Google product.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoogle-research%2Fgraph-attribution","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgoogle-research%2Fgraph-attribution","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoogle-research%2Fgraph-attribution/lists"}