Coder Social home page Coder Social logo

edwardelson / graph-attribution Goto Github PK

View Code? Open in Web Editor NEW

This project forked from google-research/graph-attribution

0.0 0.0 0.0 31.08 MB

Codebase for Evaluating Attribution for Graph Neural Networks.

License: Apache License 2.0

Python 6.93% Jupyter Notebook 93.07%

graph-attribution's Introduction

Schematic figure

Attribution 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.

Quickstart

A code snippet that demonstrastes how to create an attribution on a graph:

import graph_attribution as gatt

task_type = 'benzene'
block_type = 'gcn'
exp, task, methods = gatt.experiments.get_experiment_setup(task_type, block_type)
hp = gatt.hparams.get_hparams({'block_type':block_type, 'task_type':task_type})
gnn = experiments.GNN.from_hparams(hp, task)
gnn(exp.x_test)
# Train model here!
pred_att = methods['CAM'].attribute(exp.x_test, gnn)
result = task.evaluate_attributions(exp.att_test, pred_att)
print(result) # A dict of attribution statistics.

If you want to get up and running with building graph attributions from scratch, we recommend you run notebooks/train_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.

You can run code to replicate all results in the paper using notebooks/plot_evaluation_results.ipynb, which you can also run live in Colab (no downloads required).

If you'd like to run the code locally, or extend it, read on.

What's implemented?

Attribution techniques:

We test attribution quality on several GNN architectures:

Have an idea you want to test?

To 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.

Code structure

The rest of the files are organized as:

  • data/ holds all datasets, one folder per task.
    • data/dataset_bias holds a folder for each spurious correlation task.
    • data/results holds CSV files with results from the main publication.
    • data/NOTICE details properties of this data redistribution.
  • notebooks/ holds Jupyter notebooks.
  • scripts/ python scripts for generating datasets.
  • graph_attribution/ holds the code for creating models, generating and evaluating attributions.

Installing

The codebase is primarily a Tensorflow 2.0 based framework that uses Sonnet and Graph Nets for building GNN models. If you are using pre-generated datsets, you can git clone the repo and pip install it:

pip install git+https://github.com/google-research/graph-attribution

If you plan on generating datasets, we recommend using Anaconda for installing all dependencies. Requirements can be installed into a fresh conda environment as follows:

$ conda env create -f environment.yml -n graph_attribution

Once installed you can run a notebook but running:

$ conda activate graph_attribution
$ jupyter notebook *.ipynb

Giving Credit

If you use this code in your work, we ask that you cite our work. Here is an example BibTex entry:

@article{NEURIPS2020_6054,
  title     = {Evaluating Attribution for Graph Neural Networks},
  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},
  booktitle = {Advances in Neural Information Processing Systems 33},
  year      = {2020},
  url       = {https://papers.nips.cc/paper/2020/hash/417fbbf2e9d5a28a855a11894b2e795a-Abstract.html},
}

Related work

If you cite this work, you may also want to cite:

This is not an official Google product.

graph-attribution's People

Contributors

alexbw avatar beangoben avatar edwardelson avatar wesleyyc avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.