Book Image

Hands-On Graph Neural Networks Using Python

By : Maxime Labonne
Book Image

Hands-On Graph Neural Networks Using Python

By: Maxime Labonne

Overview of this book

Graph neural networks are a highly effective tool for analyzing data that can be represented as a graph, such as networks, chemical compounds, or transportation networks. The past few years have seen an explosion in the use of graph neural networks, with their application ranging from natural language processing and computer vision to recommendation systems and drug discovery. Hands-On Graph Neural Networks Using Python begins with the fundamentals of graph theory and shows you how to create graph datasets from tabular data. As you advance, you’ll explore major graph neural network architectures and learn essential concepts such as graph convolution, self-attention, link prediction, and heterogeneous graphs. Finally, the book proposes applications to solve real-life problems, enabling you to build a professional portfolio. The code is readily available online and can be easily adapted to other datasets and apps. By the end of this book, you’ll have learned to create graph datasets, implement graph neural networks using Python and PyTorch Geometric, and apply them to solve real-world problems, along with building and training graph neural network models for node and graph classification, link prediction, and much more.
Table of Contents (25 chapters)
1
Part 1: Introduction to Graph Learning
5
Part 2: Fundamentals
10
Part 3: Advanced Techniques
18
Part 4: Applications
22
Chapter 18: Unlocking the Potential of Graph Neural Networks for Real-World Applications

Generating molecules with MolGAN

Deep graph generation is not well covered by PyTorch Geometric. Drug discovery is the main application of this subfield, which is why generative models can be found in specialized libraries. More specifically, there are two popular Python libraries for ML-based drug discovery: DeepChem and torchdrug. In this section, we will use DeepChem as it is more mature and directly implements MolGAN.

Let’s see how we can use it with DeepChem and tensorflow. The following procedure is based on DeepChem’s example:

  1. We install DeepChem (https://deepchem.io), which requires the following libraries: tensorflow, joblib, NumPy, pandas, scikit-learn, SciPy, and rdkit:
    !pip install deepchem==2.7.1
  2. Then, we import the required packages:
    import numpy as np
    import tensorflow as tf
    import pandas as pd
    from tensorflow import one_hot
    import deepchem as dc
    from deepchem.models.optimizers import ExponentialDecay
    from deepchem.models import BasicMolGANModel...