A gallery of state-of-the-arts deep learning graph models.
Implemented with Tensorflow 2.x.
This repo aims to achieve 4 goals:
- Similar (or higher) performance with the corresponding papers
- Faster implementation of training and testing
- Simple and convenient to use with high scalability
- Easy to read source codes
- python>=3.7
- tensorflow>=2.1
- networkx==2.3
- metis==0.2a4
- scipy>=1.4.1
- sklearn>=0.22
- numpy>=1.18.1
- numba>=0.48
- gensim>=3.8.1
adj: `scipy.sparse.csr_matrix` (or `csc_matrix`) with shape (N, N)
The input `symmetric` adjacency matrix, where `N` is the number of nodes
in graph.
features: `np.array` with shape (N, F)
The input node feature matrix, where `F` is the dimension of node features.
labels: `np.array` with shape (N,)
The ground-truth labels for all nodes in graph.
normalize_rate (Float scalar, optional):
The normalize rate for adjacency matrix `adj`. (default: :obj:`-0.5`,
i.e., math:: \hat{A} = D^{-\frac{1}{2}} A D^{-\frac{1}{2}})
normalize_features (Boolean, optional):
Whether to use row-normalize for node feature matrix.
(default :obj: `True`)
device (String, optional):
The device where the model is running on. You can specified `CPU` or `GPU`
for the model. (default: :obj: `CPU:0`, i.e., the model is running on
the 0-th device `CPU`)
seed (Positive integer, optional):
Used in combination with `tf.random.set_seed & np.random.seed & random.seed`
to create a reproducible sequence of tensors across multiple calls.
(default :obj: `None`, i.e., using random seed)
name (String, optional):
Name for the model. (default: name of class)
You can specified customized hyperparameters and training details by calling model.build(your_args)
and model.trian(your_args)
.
The usuage documents will be gradually added later.
- Semi-Supervised Classification with Graph Convolutional Networks
- Tensorflow 1.x implementation: https://github.com/tkipf/gcn
- Pytorch implementation: https://github.com/tkipf/pygcn
from graphgallery.nn.models import GCN
model = GCN(adj, features, labels, device='CPU', seed=123)
model.build()
his = model.train(idx_train, idx_val, verbose=True, epochs=100)
loss, accuracy = model.test(idx_test)
model.close
print(f'Test loss {loss:.5}, Test accuracy {accuracy:.2%}')
Dense version of GCN
, i.e., the adj
will be transformed to Tensor
instead of SparseTensor
.
from graphgallery.nn.models import DenseGCN
model = DenseGCN(adj, features, labels, device='CPU', seed=123)
model.build()
his = model.train(idx_train, idx_val, verbose=True, epochs=100)
loss, accuracy = model.test(idx_test)
model.close
print(f'Test loss {loss:.5}, Test accuracy {accuracy:.2%}')
- Convolutional Neural Networks on Graphs with Fast Localized Spectral Filtering
- Tensorflow 1.x implementation: https://github.com/mdeff/cnn_graph, https://github.com/tkipf/gcn
- Keras implementation: https://github.com/aclyde11/ChebyGCN
from graphgallery.nn.models import ChebyNet
model = ChebyNet(adj, features, labels, order=2, device='CPU', seed=123)
model.build()
his = model.train(idx_train, idx_val, verbose=True, epochs=100)
loss, accuracy = model.test(idx_test)
model.close
print(f'Test loss {loss:.5}, Test accuracy {accuracy:.2%}')
- FastGCN: Fast Learning with Graph Convolutional Networks via Importance Sampling
- Tensorflow 1.x implementation: https://github.com/matenure/FastGCN
from graphgallery.nn.models import FastGCN
model = FastGCN(adj, features, labels, device='CPU', seed=123)
model.build()
his = model.train(idx_train, idx_val, verbose=True, epochs=100)
loss, accuracy = model.test(idx_test)
model.close
print(f'Test loss {loss:.5}, Test accuracy {accuracy:.2%}')
- Inductive Representation Learning on Large Graphs
- Tensorflow 1.x implementation: https://github.com/williamleif/GraphSAGE
- Pytorch implementation: https://github.com/williamleif/graphsage-simple/
from graphgallery.nn.models import GraphSAGE
model = GraphSAGE(adj, features, labels, n_samples=[10, 5], device='CPU', seed=123)
model.build()
his = model.train(idx_train, idx_val, verbose=True, epochs=100, restore_best=False, validation=False)
loss, accuracy = model.test(idx_test)
model.close
print(f'Test loss {loss:.5}, Test accuracy {accuracy:.2%}')
- Robust Graph Convolutional Networks Against Adversarial Attacks
- Tensorflow 1.x implementation: https://github.com/thumanlab/nrlweb/blob/master/static/assets/download/RGCN.zip
from graphgallery.nn.models import RobustGCN
model = RobustGCN(adj, features, labels, device='CPU', seed=123)
model.build()
his = model.train(idx_train, idx_val, verbose=True, epochs=100)
loss, accuracy = model.test(idx_test)
model.close
print(f'Test loss {loss:.5}, Test accuracy {accuracy:.2%}')
- Simplifying Graph Convolutional Networks
- Pytorch implementation: https://github.com/Tiiiger/SGC
from graphgallery.nn.models import SGC
model = SGC(adj, features, labels, device='CPU', seed=123)
model.build()
his = model.train(idx_train, idx_val, verbose=True, epochs=100)
loss, accuracy = model.test(idx_test)
model.close
print(f'Test loss {loss:.5}, Test accuracy {accuracy:.2%}')
- Graph Wavelet Neural Network
- Tensorflow 1.x implementation: https://github.com/Eilene/GWNN
- Pytorch implementation: https://github.com/benedekrozemberczki/GraphWaveletNeuralNetwork
from graphgallery.nn.models import GWNN
model = GWNN(adj, features, labels, device='CPU', seed=123)
model.build()
his = model.train(idx_train, idx_val, verbose=True, epochs=100)
loss, accuracy = model.test(idx_test)
model.close
print(f'Test loss {loss:.5}, Test accuracy {accuracy:.2%}')
- Graph Attention Networks
- Tensorflow 1.x implementation: https://github.com/PetarV-/GAT
- Pytorch implementation: https://github.com/Diego999/pyGAT
- Keras implementation: https://github.com/danielegrattarola/keras-gat
from graphgallery.nn.models import GAT
model = GAT(adj, features, labels, device='CPU', seed=123)
model.build()
his = model.train(idx_train, idx_val, verbose=True, epochs=200)
loss, accuracy = model.test(idx_test)
model.close
print(f'Test loss {loss:.5}, Test accuracy {accuracy:.2%}')
- Cluster-GCN: An Efficient Algorithm for Training Deep and Large Graph Convolutional Networks
- Tensorflow 1.x implementation: https://github.com/google-research/google-research/tree/master/cluster_gcn
- Pytorch implementation: https://github.com/benedekrozemberczki/ClusterGCN
from graphgallery.nn.models import ClusterGCN
model = ClusterGCN(Data.adj, Data.features, data.labels, n_cluster=10, device='CPU', seed=123)
model.build()
his = model.train(idx_train, idx_val, verbose=True, epochs=100)
loss, accuracy = model.test(idx_test)
model.close
print(f'Test loss {loss:.5}, Test accuracy {accuracy:.2%}')
- Batch Virtual Adversarial Training for Graph Convolutional Networks
- Tensorflow 1.x implementation: https://github.com/thudzj/BVAT
from graphgallery.nn.models import SBVAT
model = GMNN(adj, features, labels, device='CPU', seed=123)
model.build()
his = model.train(idx_train, idx_val, verbose=True, epochs=100)
loss, accuracy = model.test(idx_test)
model.close
print(f'Test loss {loss:.5}, Test accuracy {accuracy:.2%}')
- Batch Virtual Adversarial Training for Graph Convolutional Networks
- Tensorflow 1.x implementation: https://github.com/thudzj/BVAT
from graphgallery.nn.models import OBVAT
model = OBVAT(adj, features, labels, device='CPU', seed=123)
model.build()
his = model.train(idx_train, idx_val, verbose=True, epochs=100)
loss, accuracy = model.test(idx_test)
model.close
print(f'Test loss {loss:.5}, Test accuracy {accuracy:.2%}')
- Graph Markov Neural Networks
- Pytorch implementation: https://github.com/DeepGraphLearning/GMNN
from graphgallery.nn.models import GMNN
model = GMNN(adj, features, labels, device='CPU', seed=123)
model.build()
his = model.train(idx_train, idx_val, verbose=True, epochs=100)
loss, accuracy = model.test(idx_test)
model.close
print(f'Test loss {loss:.5}, Test accuracy {accuracy:.2%}')
- Large-Scale Learnable Graph Convolutional Networks
- Tensorflow 1.x implementation: https://github.com/divelab/lgcn
from graphgallery.nn.models import LGCN
model = GMNN(adj, features, labels, device='CPU', seed=123)
model.build()
his = model.train(idx_train, idx_val, verbose=True, epochs=100)
loss, accuracy = model.test(idx_test)
model.close
print(f'Test loss {loss:.5}, Test accuracy {accuracy:.2%}')
- DeepWalk: Online Learning of Social Representations
- Implementation: https://github.com/phanein/deepwalk
from graphgallery.nn.models import Deepwalk
model = Deepwalk(adj, features, labels)
model.build()
model.train(idx_train)
accuracy = model.test(idx_test)
print(f'Test accuracy {accuracy:.2%}')
- node2vec: Scalable Feature Learning for Networks
- Implementation: https://github.com/aditya-grover/node2vec
- Cpp implementation: https://github.com/snap-stanford/snap/tree/master/examples/node2vec
from graphgallery.nn.models import Node2vec
model = Node2vec(adj, features, labels)
model.build()
model.train(idx_train)
accuracy = model.test(idx_test)
print(f'Test accuracy {accuracy:.2%}')