Using Tensorflow for GNNs

Hello, I’ve been using networkx ( to help learn about graph data structures. I read Introduction to graphs and tf.function  |  TensorFlow Core but this doesn’t seem to help with GNNs.

Are there any resources for implementing / learning how to build GNNs using Tensorflow?

I was thinking about using networkx and then maybe using tf.GradientTape to update weights between nodes.


Have you already take a look at:

1 Like

Nope! Looks like these are good resources. Thanks!

Stellar Graph library can be used to model graph structures like social networks and other with TensorFlow:

1 Like

+1 Spektral.

There’s a TensorFlow talk on YouTube about GNNs by Petar Veličković (DeepMind) with a demo that uses Spektral:

Note that since the library has changed since the video was created, there’re some code changes too (check the comments under the YouTube video). For example, in the beginning this could work in v1.0.x:

import spektral

dataset = spektral.datasets.citation.Citation(name='cora')
graph = dataset[0]
adj, features, labels = graph.a, graph.x, graph.y
train_mask, val_mask, test_mask = dataset.mask_tr, dataset.mask_va, dataset.mask_te

@JMG There’s another external library in TF Keras called kgcnn

"The focus of the graph package presented here is on a neat integration of graphs into the TensorFlow-Keras framework in the most straightforward way. Thereby, we hope to provide Keras graph layers which can be quickly rearranged, changed and extended to build custom graph models with little effort. This implementation is focused on the new TensorFlow’s RaggedTensor class which is most suited for flexible data structures such as graphs and natural language.”

Last year, there was a Google Graph Mining and Learning workshop at NeurIPS 2020: - there were some insightful talks, check out the link.

If you’re trying to keep up with the latest GNN research and events, this GitHub may be useful:


MNIST with GNNs using Keras and Spektral:

1 Like

The examples in are usually the fastest way for me to learn something.

Run them on Colab.

1 Like

We really appreciate the community contributions in GNNs listed above, thanks! Today we released a TF GNN library which is available on the TensorFlow GItHub repo here, and explained the background of this library in a blog post.

If you have any questions for the team, please reply to the announcement thread, here: Announcements - TensorFlow Forum