{"id":13526330,"url":"https://github.com/google-deepmind/graph_nets","last_synced_at":"2025-05-14T14:08:31.661Z","repository":{"id":40658341,"uuid":"146863062","full_name":"google-deepmind/graph_nets","owner":"google-deepmind","description":"Build Graph Nets in Tensorflow","archived":false,"fork":false,"pushed_at":"2022-12-12T11:28:07.000Z","size":1504,"stargazers_count":5380,"open_issues_count":9,"forks_count":784,"subscribers_count":223,"default_branch":"master","last_synced_at":"2025-04-25T20:02:42.434Z","etag":null,"topics":["artificial-intelligence","deep-learning","graph-networks","graphs","neural-networks","sonnet","tensorflow"],"latest_commit_sha":null,"homepage":"https://arxiv.org/abs/1806.01261","language":"Python","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-deepmind.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-08-31T08:19:28.000Z","updated_at":"2025-04-23T10:29:09.000Z","dependencies_parsed_at":"2023-01-27T18:46:17.859Z","dependency_job_id":null,"html_url":"https://github.com/google-deepmind/graph_nets","commit_stats":null,"previous_names":["deepmind/graph-nets","google-deepmind/graph_nets","deepmind/graph_nets"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/google-deepmind%2Fgraph_nets","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/google-deepmind%2Fgraph_nets/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/google-deepmind%2Fgraph_nets/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/google-deepmind%2Fgraph_nets/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/google-deepmind","download_url":"https://codeload.github.com/google-deepmind/graph_nets/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254159804,"owners_count":22024564,"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":["artificial-intelligence","deep-learning","graph-networks","graphs","neural-networks","sonnet","tensorflow"],"created_at":"2024-08-01T06:01:28.143Z","updated_at":"2025-05-14T14:08:31.642Z","avatar_url":"https://github.com/google-deepmind.png","language":"Python","readme":"![Graph Nets DeepMind shortest path](https://github.com/deepmind/graph_nets/raw/master/images/graph-nets-deepmind-shortest-path0.gif)\n\n# Graph Nets library\n\n[Graph Nets](https://github.com/deepmind/graph_nets) is DeepMind's library for\nbuilding graph networks in Tensorflow and Sonnet.\n\nContact graph-nets@google.com for comments and questions.\n\n#### What are graph networks?\n\nA graph network takes a graph as input and returns a graph as output. The input\ngraph has edge- (*E* ), node- (*V* ), and global-level (**u**) attributes. The\noutput graph has the same structure, but updated attributes. Graph networks are\npart of the broader family of \"graph neural networks\" (Scarselli et al., 2009).\n\nTo learn more about graph networks, see our arXiv paper: [Relational inductive\nbiases, deep learning, and graph networks](https://arxiv.org/abs/1806.01261).\n\n![Graph network](https://github.com/deepmind/graph_nets/raw/master/images/graph-network.png)\n\n## Installation\n\nThe Graph Nets library can be installed from pip.\n\nThis installation is compatible with Linux/Mac OS X, and Python 2.7 and 3.4+.\n\nThe library will work with both the CPU and GPU version of TensorFlow, but to\nallow for that it does not list Tensorflow as a requirement, so you need to\ninstall Tensorflow separately if you haven't already done so.\n\nTo install the Graph Nets library and use it with TensorFlow 1 and Sonnet 1, run:\n\n(CPU)\n```shell\n$ pip install graph_nets \"tensorflow\u003e=1.15,\u003c2\" \"dm-sonnet\u003c2\" \"tensorflow_probability\u003c0.9\"\n```\n\n(GPU)\n```shell\n$ pip install graph_nets \"tensorflow_gpu\u003e=1.15,\u003c2\" \"dm-sonnet\u003c2\" \"tensorflow_probability\u003c0.9\"\n```\n\nTo install the Graph Nets library and use it with TensorFlow 2 and Sonnet 2, run:\n\n(CPU)\n```shell\n$ pip install graph_nets \"tensorflow\u003e=2.1.0-rc1\" \"dm-sonnet\u003e=2.0.0b0\" tensorflow_probability\n```\n\n(GPU)\n```shell\n$ pip install graph_nets \"tensorflow_gpu\u003e=2.1.0-rc1\" \"dm-sonnet\u003e=2.0.0b0\" tensorflow_probability\n```\n\nThe latest version of the library requires TensorFlow \u003e=1.15. For compatibility with earlier versions of TensorFlow, please install v1.0.4 of the Graph Nets library.\n\n## Usage example\n\nThe following code constructs a simple graph net module and connects it to data.\n\n```python\nimport graph_nets as gn\nimport sonnet as snt\n\n# Provide your own functions to generate graph-structured data.\ninput_graphs = get_graphs()\n\n# Create the graph network.\ngraph_net_module = gn.modules.GraphNetwork(\n    edge_model_fn=lambda: snt.nets.MLP([32, 32]),\n    node_model_fn=lambda: snt.nets.MLP([32, 32]),\n    global_model_fn=lambda: snt.nets.MLP([32, 32]))\n\n# Pass the input graphs to the graph network, and return the output graphs.\noutput_graphs = graph_net_module(input_graphs)\n```\n\n## Demo Jupyter notebooks\n\nThe library includes demos which show how to create, manipulate, and\ntrain graph networks to reason about graph-structured data, on a\nshortest path-finding task, a sorting task, and a physical prediction task.\nEach demo uses the same graph network architecture, which highlights the\nflexibility of the approach.\n\n### Try the demos in your browser in [Colaboratory](https://colab.research.google.com)\n\nTo try out the demos without installing anything locally, you can run the demos\nin your browser (even on your phone) via a cloud Colaboratory backend. Click a\ndemo link below, and follow the instructions in the notebook.\n\n----------------\n\n#### [Run \"shortest path demo\" in browser](https://colab.research.google.com/github/deepmind/graph_nets/blob/master/graph_nets/demos/shortest_path.ipynb)\n\nThe \"shortest path demo\" creates random graphs, and trains a graph network to\nlabel the nodes and edges on the shortest path between any two nodes. Over a\nsequence of message-passing steps (as depicted by each step's plot), the\nmodel refines its prediction of the shortest path.\n\n![Shortest path](https://github.com/deepmind/graph_nets/raw/master/images/shortest-path.png)\n\n----------------\n\n#### [Run \"sort demo\" in browser](https://colab.research.google.com/github/deepmind/graph_nets/blob/master/graph_nets/demos/sort.ipynb)  [(Run TF2 version)](https://colab.research.google.com/github/deepmind/graph_nets/blob/master/graph_nets/demos_tf2/sort.ipynb)\n\nThe \"sort demo\" creates lists of random numbers, and trains a graph network to\nsort the list. After a sequence of message-passing steps, the model makes an\naccurate prediction of which elements (columns in the figure) come next after\neach other (rows).\n\n![Sort](https://github.com/deepmind/graph_nets/raw/master/images/sort.png)\n\n----------------\n\n#### [Run \"physics demo\" in browser](https://colab.research.google.com/github/deepmind/graph_nets/blob/master/graph_nets/demos/physics.ipynb)\n\nThe \"physics demo\" creates random mass-spring physical systems, and trains a\ngraph network to predict the state of the system on the next timestep. The\nmodel's next-step predictions can be fed back in as input to create a rollout of\na future trajectory. Each subplot below shows the true and predicted mass-spring\nsystem states over 50 steps. This is similar to the model and experiments in\nBattaglia et al. (2016)'s \"interaction networks\".\n\n![Physics](https://github.com/deepmind/graph_nets/raw/master/images/physics.png)\n\n----------------\n\n#### [Run \"graph nets basics demo\" in browser](https://colab.research.google.com/github/deepmind/graph_nets/blob/master/graph_nets/demos/graph_nets_basics.ipynb)  [(Run TF2 version)](https://colab.research.google.com/github/deepmind/graph_nets/blob/master/graph_nets/demos_tf2/graph_nets_basics.ipynb)\n\nThe \"graph nets basics demo\" is a tutorial containing step by step examples\nabout how to create and manipulate graphs, how to feed them into\ngraph networks and how to build custom graph network modules.\n\n----------------\n\n### Run the demos on your local machine\n\nTo install the necessary dependencies, run:\n\n```shell\n$ pip install jupyter matplotlib scipy\n```\n\nTo try the demos, run:\n\n```shell\n$ cd \u003cpath-to-graph-nets-library\u003e/demos\n$ jupyter notebook\n```\nthen open a demo through the Jupyter notebook interface.\n\n\n## Other graph neural network libraries\n\nCheck out these high-quality open-source libraries for graph neural networks:\n\n* [jraph](https://github.com/deepmind/jraph): DeepMind's GNNs/GraphNets library\nfor [JAX](https://github.com/google/jax).\n\n* [pytorch_geometric](https://github.com/rusty1s/pytorch_geometric): See\n[MetaLayer](https://pytorch-geometric.readthedocs.io/en/latest/modules/nn.html#torch_geometric.nn.meta.MetaLayer)\nfor an analog of our Graph Nets interface.\n\n* [Deep Graph Library (DGL)](https://github.com/dmlc/dgl).\n","funding_links":[],"categories":["Library","Graph Machine Learning","Python"],"sub_categories":["Others"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoogle-deepmind%2Fgraph_nets","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgoogle-deepmind%2Fgraph_nets","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoogle-deepmind%2Fgraph_nets/lists"}