Advertisement

Now You Can Build Graph Neural Networks With Spektral Based On Keras

Recently, a PhD researcher, Daniele Grattarola built a framework known as Spektral for mapping relational representation learning which is built in Python and is based on the Keras API. Spektral contains a comprehensive set of tools to build graph neural networks as well as implement some of the popular layers for graph Deep Learning.

How It Works

Spektral is built with semi-supervised deep learning methods for graph data, Graph Neural Network (GNN). According to this paper, the idea of GNN is simple: to encode structural information of the graph, each node v_i can be represented by a low-dimensional state vector s_i , 1 ≤ i ≤ N. The categorisation of  deep learning methods on the graph is shown below

The core GNN modules of Spektral are mainly based on Keras and it works with all the different backends offered by Keras in order to promptly start experimenting with the Relational Representation Learning (RRL) which consists of developing models that are able to deal with graphs natively without having to deal with the distracting low-level details. The accessory modules of Spectral are built in Numpy/Scipy and for which everything should work at the speed of almost-C-like and without compatibility issues.

Data Representation

Spektral uses a matrix-based representation of manipulating graphs and feeding them to neural networks. This is one of the most commonly used approaches in the theory of GNN and it is also perfect to perform effective computations on GPU.

In this framework, some layers and functions are implemented to work on a single graph and while the others are considered as a set of graphs. The framework also distinguishes between three main modes of operations mentioned below

  • Single, where a single graph is considered with its topology and attributes
  • Batch, where a collection of graphs are considered, each with its own topology and attributes
  • Mixed, where a graph with a fixed topology is considered but a collection of different attributes. This can be considered as a particular case of the batch mode (i.e. the case where all adjacency matrices are the same) but is treated separately for computational reasons.

Installation

Spektral is developed by keeping Python in mind so Python versions 2 and 3 are recommended. Python 3 is heavily recommended and for those who are using Python 2 version are suggested to switch into Python 3 for a smooth workflow.

There are some features  of Spectral which require the following optional dependencies

  • RDKit, a library for cheminformatics and molecule manipulation (available through Anaconda);
  • Dyfunconn, a library to build functional connectivity networks (available through PyPi);
  • CDG, a library implementing several change detection algorithms, as well as an engine for Riemannian geometry (available on Github);

The framework is tested for Ubuntu 16.04 and 18.04 and should also work on other Linux distros and MacOS.

To install the required dependencies on Ubuntu, run the following code

$ sudo apt install graphviz libgraphviz-dev libcgraph6

The simplest way to install Spektral is with PyPi; just run:

$ pip install spektral

To install the framework from source, run the following code in the terminal:

$ git clone https://github.com/danielegrattarola/spektral.git

$ cd spektral

$ python setup.py install  # Or ‘pip install .’

Bottom Line

However, this project comes with a little warning for the work which is still in progress and may change before the proper release. Also, if you are interested in contributing your ideas for further development, you can easily do it just by dropping an email.

Download our Mobile App

Ambika Choudhury
A Technical Journalist who loves writing about Machine Learning and Artificial Intelligence. A lover of music, writing and learning something out of the box.

Subscribe to our newsletter

Join our editors every weekday evening as they steer you through the most significant news of the day.
Your newsletter subscriptions are subject to AIM Privacy Policy and Terms and Conditions.

Our Upcoming Events

15th June | Online

Building LLM powered applications using LangChain

17th June | Online

Mastering LangChain: A Hands-on Workshop for Building Generative AI Applications

Jun 23, 2023 | Bangalore

MachineCon 2023 India

26th June | Online

Accelerating inference for every workload with TensorRT

MachineCon 2023 USA

Jul 21, 2023 | New York

Cypher 2023

Oct 11-13, 2023 | Bangalore

3 Ways to Join our Community

Telegram group

Discover special offers, top stories, upcoming events, and more.

Discord Server

Stay Connected with a larger ecosystem of data science and ML Professionals

Subscribe to our Daily newsletter

Get our daily awesome stories & videos in your inbox
MOST POPULAR