{"id":20469110,"url":"https://github.com/pfnet-research/bayesgrad","last_synced_at":"2025-04-13T10:30:28.560Z","repository":{"id":33144043,"uuid":"139135205","full_name":"pfnet-research/bayesgrad","owner":"pfnet-research","description":"BayesGrad: Explaining Predictions of Graph Convolutional Networks","archived":false,"fork":false,"pushed_at":"2022-01-21T19:51:26.000Z","size":281,"stargazers_count":63,"open_issues_count":2,"forks_count":9,"subscribers_count":17,"default_branch":"master","last_synced_at":"2025-03-27T01:51:27.672Z","etag":null,"topics":["chainer","chemistry","deep-learning","graph-convolutional-networks","interpretability","neural-network","python","saliency"],"latest_commit_sha":null,"homepage":null,"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/pfnet-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":"2018-06-29T10:16:42.000Z","updated_at":"2024-11-06T14:33:43.000Z","dependencies_parsed_at":"2022-08-07T20:01:05.789Z","dependency_job_id":null,"html_url":"https://github.com/pfnet-research/bayesgrad","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/pfnet-research%2Fbayesgrad","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pfnet-research%2Fbayesgrad/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pfnet-research%2Fbayesgrad/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pfnet-research%2Fbayesgrad/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pfnet-research","download_url":"https://codeload.github.com/pfnet-research/bayesgrad/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248698479,"owners_count":21147497,"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":["chainer","chemistry","deep-learning","graph-convolutional-networks","interpretability","neural-network","python","saliency"],"created_at":"2024-11-15T14:07:58.361Z","updated_at":"2025-04-13T10:30:28.517Z","avatar_url":"https://github.com/pfnet-research.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Bayesgrad\nBayesGrad: Explaining Predictions of Graph Convolutional Networks\n\nThe paper is available on arXiv, [https://arxiv.org/abs/1807.01985](https://arxiv.org/abs/1807.01985).\n\n\u003cp float=\"left\" align=\"middle\"\u003e\n  \u003cimg src=\"https://github.com/pfnet-research/bayesgrad/blob/master/assets/tox21_pyridine/6_bayes.png\" width=\"250\" /\u003e \n  \u003cimg src=\"https://github.com/pfnet-research/bayesgrad/blob/master/assets/tox21_srmmp/3_bayes.png\" width=\"250\" /\u003e\n  \u003cimg src=\"https://github.com/pfnet-research/bayesgrad/blob/master/assets/delaney_solubility/3.png\" width=\"250\" /\u003e\n\u003c/p\u003e\n\u003cp align=\"middle\"\u003e\n  From left: tox21 pyridine (C5H5N), tox21 SR-MMP, delaney solubility visualization.\n\u003c/p\u003e\n\n## Citation\nIf you find our work useful in your research, please consider citing:\n\n```\n@article{akita2018bayesgrad,\n  title={BayesGrad: Explaining Predictions of Graph Convolutional Networks},\n  author={Akita, Hirotaka and Nakago, Kosuke and Komatsu, Tomoki and Sugawara, Yohei and Maeda, Shin-ichi and Baba, Yukino and Kashima, Hisashi},\n  journal={arXiv preprint arXiv:1807.01985},\n  year={2018}\n}\n```\n\n## Setup\n\n[Chainer Chemistry](https://github.com/pfnet-research/chainer-chemistry) [1] is used in our code.\nIt is an extension library for deep learning framework [Chainer](https://github.com/chainer/chainer) [2],\nand it supports several graph-convolutional neural network together with chemical dataset management.\n\nThe experiment is executed under following environment:\n\n - OS: Linux\n - python: 3.6.1\n - conda version: 4.4.4\n\n```bash\nconda create -n bayesgrad python=3.6.1\nsource activate bayesgrad\npip install chainer==4.2.0\npip install chainer-chemistry==0.4.0\nconda install -c rdkit rdkit==2017.09.3.0\npip install matplotlib==2.2.2\npip install future==0.16.0\npip install cairosvg==2.1.3\npip install ipython==5.1.0\n```\n\n[Note]\nPlease install specified python version \u0026 rdkit version.\nLatest python version and rdkit may not work well as discussed [here](https://github.com/pfnet-research/chainer-chemistry/issues/138).\nIf you face error try\n```bash\nconda install libgcc\n```\n\nIf you want to use GPU, please install `cupy` as well.\n```bash\n# XX should be CUDA version (80, 90 or 91)\npip install cupy-cudaXX==4.2.0\n```\n\n## Experiments\n\nEach experiment can be executed as follows.\n\n### Tox21 Pyridine experiment\nExperiments described in Section 4.1 in the paper. Tox21 [3] dataset is used.\n\n```bash\ncd experiments/tox21\n```\n\n#### Training with all train data, plot precision-recall curve\n\nSet `-g -1` to use CPU, `-g 0` to use GPU. \n```bash\npython train_tox21.py --iterator-type=balanced --label=pyridine --method=ggnndrop --epoch=50 --unit-num=16 --n-layers=1 -b 32 --conv-layers=4 --num-train=-1 --dropout-ratio=0.25 --out=results/ggnndrop_pyridine -g 0\npython plot_precision_recall.py --dirpath=results/ggnndrop_pyridine\n```\n\n#### Visualization with trained model\nSee `visualize-saliency-pyrigine.ipynb`.\n\n\u003cp float=\"left\" align=\"middle\"\u003e\n  \u003cimg src=\"https://github.com/pfnet-research/bayesgrad/blob/master/assets/tox21_pyridine/6_bayes.png\" width=\"250\" /\u003e \n  \u003cimg src=\"https://github.com/pfnet-research/bayesgrad/blob/master/assets/tox21_pyridine/13_bayes.png\" width=\"250\" /\u003e \n  \u003cimg src=\"https://github.com/pfnet-research/bayesgrad/blob/master/assets/tox21_pyridine/21_bayes.png\" width=\"250\" /\u003e \n\u003c/p\u003e\n\nOur method successfully focuses on pyridine (C5H5N) substructures.\n \n#### Training 30 different models with few train data, calculate RPC-AUC score\nArgument: `-1` to use CPU, `0` to use GPU. \n\nNote that this experiment takes time (took around 2.5 hours with GPU in our environment),\nsince it trains 30 different models.\n\n```bash\nbash -x ./train_few_with_seeds.sh 0\nbash -x ./calc_prcauc_with_seeds.sh 0\n```\n\nThen see `results/ggnndrop_pyridin_numtrain1000-seed0-29/prcauc_stats_absolute_0.15.csv` for the results.\n\n### Tox21 SR-MMP experiment\nExperiments described in Section 4.2 in the paper.  Tox21 [3] dataset is used.\n\n```bash\ncd experiments/tox21\n```\n\n#### Training the model\nSet `-g -1` to use CPU, `-g 0` to use GPU.\n```bash\npython train_tox21.py --iterator-type=balanced --label=SR-MMP --method=nfpdrop --epoch=200 --unit-num=16 --n-layers=1 -b 32 --conv-layers=4 --num-train=-1 --dropout-ratio=0.25 --out=results/nfpdrop_srmmp -g 0\n```\n\n#### Visualization of tox21 data \u0026 Tyrphostin 9 with trained model\nSee `visualize-saliency-tox21.ipynb`.\n\nJupyter notebook interactive visualization:\n\u003cp float=\"left\" align=\"middle\"\u003e\n  \u003cimg src=\"https://user-images.githubusercontent.com/4609798/42087970-d47bb666-7bd2-11e8-8d75-5770ccfbdb3b.gif\" /\u003e\n\u003c/p\u003e\n\nSeveral picked images:\n\u003cp float=\"left\" align=\"middle\"\u003e\n  \u003cimg src=\"https://github.com/pfnet-research/bayesgrad/blob/master/assets/tox21_srmmp/2_bayes.png\" width=\"250\" /\u003e\n  \u003cimg src=\"https://github.com/pfnet-research/bayesgrad/blob/master/assets/tox21_srmmp/3_bayes.png\" width=\"250\" /\u003e\n  \u003cimg src=\"https://github.com/pfnet-research/bayesgrad/blob/master/assets/tox21_srmmp/27_bayes.png\" width=\"250\" /\u003e\n\u003c/p\u003e\n\nToxicity mechanism is still in an active research topic and it is difficult to quantitatively analyze its results.\nWe hope these visualization helps to analyze and establish further knowledge about toxicity.\n\n### Solubility experiment\nExperiment done in Section 4.3 in the paper. ESOL [4] dataset (provided by MoleculeNet [5]) is used.\n\n```bash\ncd experiments/delaney\n```\n\n#### Training the model\nSet `-g -1` to use CPU, `-g 0` to use GPU.\n\n```bash\npython train.py -e 100 -n 3 --method=nfpdrop -g 0\n```\n\n#### Visualization with trained model\n```bash\npython plot.py --dirpath=./results/nfpdrop_M30_conv3_unit32_b32\n```\n\n\u003cp float=\"left\" align=\"middle\"\u003e\n  \u003cimg src=\"https://github.com/pfnet-research/bayesgrad/blob/master/assets/delaney_solubility/3.png\" width=\"250\" /\u003e\n  \u003cimg src=\"https://github.com/pfnet-research/bayesgrad/blob/master/assets/delaney_solubility/19.png\" width=\"250\" /\u003e\n  \u003cimg src=\"https://github.com/pfnet-research/bayesgrad/blob/master/assets/delaney_solubility/54.png\" width=\"250\" /\u003e\n\u003c/p\u003e\n\nRed color represents these atoms are hydrophilic, and blue color represents hydrophobic.\nAbove figure is consistent with fundamental physicochemical knowledge as explained in the paper.\n\n## Saliency Calculation\n\nAlthough only results of gradient method [6, 7, 8] are reported in the paper, \nthis repository contains saliency calculation code for several other algorithms as well.\n\nWe can apply SmoothGrad [8] and/or BayesGrad (Ours) into following algorithms.\n\n- Vanilla Gradients [6, 7]\n- Integrated Gradients [9]\n- Occlusion [10]\n\nThe code design is inspired by [PAIR-code/saliency](https://github.com/PAIR-code/saliency).\n\n## License\n\nOur code is released under MIT License (see [LICENSE](https://github.com/pfnet-research/bayesgrad/blob/master/LICENSE) file for details).\n\n## Reference\n\n[1] pfnet research. chainer-chemistry https://github.com/pfnet-research/chainer-chemistry\n\n[2] Seiya Tokui, Kenta Oono, Shohei Hido, and Justin Clayton. Chainer: a next-generation open source framework for deep learning. In *Proceedings of Workshop on Machine Learning Systems (LearningSys) in Advances in Neural Information Processing System (NIPS) 28*, 2015.\n\n[3] Ruili Huang, Menghang Xia, Dac-Trung Nguyen, Tongan Zhao, Srilatha Sakamuru, Jinghua Zhao, Sampada A Shahane, Anna Rossoshek, and Anton Simeonov. Tox21challenge to build predictive models of nuclear receptor and stress response pathways as mediated by exposure to environmental chemicals and drugs. Frontiers in Environmental Science, 3:85, 2016.\n\n[4] John S. Delaney. Esol: Estimating aqueous solubility directly from molecular structure. Journal of Chemical Information and Computer Sciences, 44(3):1000{1005,2004. PMID: 15154768.\n\n[5] Zhenqin Wu, Bharath Ramsundar, Evan N. Feinberg, Joseph Gomes, Caleb Geniesse, Aneesh S. Pappu, Karl Leswing, Vijay Pande, MoleculeNet: A Benchmark for Molecular Machine Learning, arXiv preprint, arXiv: 1703.00564, 2017.\n\n[6] Dumitru Erhan, Yoshua Bengio, Aaron Courville, Pascal Vincent. Visualizing Higher-Layer Features of a Deep Network. 2009.\n\n[7] Karen Simonyan, Andrea Vedaldi, and Andrew Zisserman. Deep inside convolutional networks: Visualising image classication models and saliency maps. arXiv preprint arXiv:1312.6034, 2013.\n\n[8] Daniel Smilkov, Nikhil Thorat, Been Kim, Fernanda Viegas, and Martin Wattenberg. SmoothGrad: removing noise by adding noise. arXiv preprint arXiv:1706.03825, 2017.\n\n[9] Mukund Sundararajan, Ankur Taly, and Qiqi Yan. Axiomatic attribution for deep networks. In Doina Precup and Yee Whye Teh (eds.), \nProceedings of the 34th International Conference on Machine Learning, volume 70 of Proceedings of Machine Learning Research, pp. 3319–3328, International Convention Centre, Sydney, Australia, 06–11 Aug 2017. PMLR.\nURL http://proceedings.mlr.press/v70/sundararajan17a.html.\n\n[10] Matthew D Zeiler and Rob Fergus. Visualizing and understanding convolutional networks. In\nEuropean conference on computer vision, pp. 818–833. Springer, 2014.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpfnet-research%2Fbayesgrad","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpfnet-research%2Fbayesgrad","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpfnet-research%2Fbayesgrad/lists"}