• Stars
    star
    1,216
  • Rank 37,110 (Top 0.8 %)
  • Language
    Python
  • License
    GNU General Publi...
  • Created over 5 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A PyTorch implementation of "Capsule Graph Neural Network" (ICLR 2019).

CapsGNN

PWC codebeat badge repo size benedekrozemberczki

A PyTorch implementation of Capsule Graph Neural Network (ICLR 2019).

Abstract

The high-quality node embeddings learned from the Graph Neural Networks (GNNs) have been applied to a wide range of node-based applications and some of them have achieved state-of-the-art (SOTA) performance. However, when applying node embeddings learned from GNNs to generate graph embeddings, the scalar node representation may not suffice to preserve the node/graph properties efficiently, resulting in sub-optimal graph embeddings. Inspired by the Capsule Neural Network (CapsNet), we propose the Capsule Graph Neural Network (CapsGNN), which adopts the concept of capsules to address the weakness in existing GNN-based graph embeddings algorithms. By extracting node features in the form of capsules, routing mechanism can be utilized to capture important information at the graph level. As a result, our model generates multiple embeddings for each graph to capture graph properties from different aspects. The attention module incorporated in CapsGNN is used to tackle graphs with various sizes which also enables the model to focus on critical parts of the graphs. Our extensive evaluations with 10 graph-structured datasets demonstrate that CapsGNN has a powerful mechanism that operates to capture macroscopic properties of the whole graph by data-driven. It outperforms other SOTA techniques on several graph classification tasks, by virtue of the new instrument.

This repository provides a PyTorch implementation of CapsGNN as described in the paper:

Capsule Graph Neural Network. Zhang Xinyi, Lihui Chen. ICLR, 2019. [Paper]

The core Capsule Neural Network implementation adapted is available [here].

Requirements

The codebase is implemented in Python 3.5.2. package versions used for development are just below.

networkx          2.4
tqdm              4.28.1
numpy             1.15.4
pandas            0.23.4
texttable         1.5.0
scipy             1.1.0
argparse          1.1.0
torch             1.1.0
torch-scatter     1.4.0
torch-sparse      0.4.3
torch-cluster     1.4.5
torch-geometric   1.3.2
torchvision       0.3.0

Datasets

The code takes graphs for training from an input folder where each graph is stored as a JSON. Graphs used for testing are also stored as JSON files. Every node id and node label has to be indexed from 0. Keys of dictionaries are stored strings in order to make JSON serialization possible.

Every JSON file has the following key-value structure:

{"edges": [[0, 1],[1, 2],[2, 3],[3, 4]],
 "labels": {"0": "A", "1": "B", "2": "C", "3": "A", "4": "B"},
 "target": 1}

The **edges** key has an edge list value which descibes the connectivity structure. The **labels** key has labels for each node which are stored as a dictionary -- within this nested dictionary labels are values, node identifiers are keys. The **target** key has an integer value which is the class membership.

Outputs

The predictions are saved in the `output/` directory. Each embedding has a header and a column with the graph identifiers. Finally, the predictions are sorted by the identifier column.

Options

Training a CapsGNN model is handled by the `src/main.py` script which provides the following command line arguments.

Input and output options

  --training-graphs   STR    Training graphs folder.      Default is `input/train/`.
  --testing-graphs    STR    Testing graphs folder.       Default is `input/test/`.
  --prediction-path   STR    Output predictions file.     Default is `output/watts_predictions.csv`.

Model options

  --epochs                      INT     Number of epochs.                  Default is 100.
  --batch-size                  INT     Number fo graphs per batch.        Default is 32.
  --gcn-filters                 INT     Number of filters in GCNs.         Default is 20.
  --gcn-layers                  INT     Number of GCNs chained together.   Default is 2.
  --inner-attention-dimension   INT     Number of neurons in attention.    Default is 20.  
  --capsule-dimensions          INT     Number of capsule neurons.         Default is 8.
  --number-of-capsules          INT     Number of capsules in layer.       Default is 8.
  --weight-decay                FLOAT   Weight decay of Adam.              Defatuls is 10^-6.
  --lambd                       FLOAT   Regularization parameter.          Default is 0.5.
  --theta                       FLOAT   Reconstruction loss weight.        Default is 0.1.
  --learning-rate               FLOAT   Adam learning rate.                Default is 0.01.

Examples

The following commands learn a model and save the predictions. Training a model on the default dataset:

$ python src/main.py

Training a CapsGNNN model for a 100 epochs.

$ python src/main.py --epochs 100

Changing the batch size.

$ python src/main.py --batch-size 128

License

More Repositories

1

awesome-graph-classification

A collection of important graph embedding, classification and representation learning papers with implementations.
Python
4,666
star
2

pytorch_geometric_temporal

PyTorch Geometric Temporal: Spatiotemporal Signal Processing with Neural Machine Learning Models (CIKM 2021)
Python
2,455
star
3

awesome-decision-tree-papers

A collection of research papers on decision, classification and regression trees with implementations.
Python
2,248
star
4

awesome-community-detection

A curated list of community detection research papers with implementations.
Python
2,224
star
5

karateclub

Karate Club: An API Oriented Open-source Python Framework for Unsupervised Learning on Graphs (CIKM 2020)
Python
2,065
star
6

awesome-fraud-detection-papers

A curated list of data mining papers about fraud detection.
Python
1,481
star
7

awesome-gradient-boosting-papers

A curated list of gradient boosting research papers with implementations.
Python
966
star
8

graph2vec

A parallel implementation of "graph2vec: Learning Distributed Representations of Graphs" (MLGWorkshop 2017).
Python
860
star
9

ClusterGCN

A PyTorch implementation of "Cluster-GCN: An Efficient Algorithm for Training Deep and Large Graph Convolutional Networks" (KDD 2019).
Python
757
star
10

littleballoffur

Little Ball of Fur - A graph sampling extension library for NetworKit and NetworkX (CIKM 2020)
Python
676
star
11

SimGNN

A PyTorch implementation of "SimGNN: A Neural Network Approach to Fast Graph Similarity Computation" (WSDM 2019).
Python
657
star
12

awesome-monte-carlo-tree-search-papers

A curated list of Monte Carlo tree search papers with implementations.
Python
565
star
13

datasets

A repository of pretty cool datasets that I collected for network science and machine learning research.
551
star
14

GraphWaveletNeuralNetwork

A PyTorch implementation of "Graph Wavelet Neural Network" (ICLR 2019)
Python
548
star
15

MixHop-and-N-GCN

An implementation of "MixHop: Higher-Order Graph Convolutional Architectures via Sparsified Neighborhood Mixing" (ICML 2019).
Python
395
star
16

APPNP

A PyTorch implementation of "Predict then Propagate: Graph Neural Networks meet Personalized PageRank" (ICLR 2019).
Python
351
star
17

AttentionWalk

A PyTorch Implementation of "Watch Your Step: Learning Node Embeddings via Graph Attention" (NeurIPS 2018).
Python
309
star
18

SGCN

A PyTorch implementation of "Signed Graph Convolutional Network" (ICDM 2018).
Python
262
star
19

GAM

A PyTorch implementation of "Graph Classification Using Structural Attention" (KDD 2018).
Python
261
star
20

GEMSEC

The TensorFlow reference implementation of 'GEMSEC: Graph Embedding with Self Clustering' (ASONAM 2019).
Python
244
star
21

SEAL-CI

A PyTorch implementation of "Semi-Supervised Graph Classification: A Hierarchical Graph Perspective" (WWW 2019)
Python
204
star
22

shapley

The official implementation of "The Shapley Value of Classifiers in Ensemble Games" (CIKM 2021).
Python
203
star
23

Splitter

A Pytorch implementation of "Splitter: Learning Node Representations that Capture Multiple Social Contexts" (WWW 2019).
Python
203
star
24

DANMF

A sparsity aware implementation of "Deep Autoencoder-like Nonnegative Matrix Factorization for Community Detection" (CIKM 2018).
Python
194
star
25

GraphWaveMachine

A scalable implementation of "Learning Structural Node Embeddings Via Diffusion Wavelets (KDD 2018)".
Python
176
star
26

role2vec

A scalable Gensim implementation of "Learning Role-based Graph Embeddings" (IJCAI 2018).
Python
158
star
27

MUSAE

The reference implementation of "Multi-scale Attributed Node Embedding". (Journal of Complex Networks 2021)
Python
136
star
28

EdMot

An implementation of "EdMot: An Edge Enhancement Approach for Motif-aware Community Detection" (KDD 2019)
Python
128
star
29

M-NMF

An implementation of "Community Preserving Network Embedding" (AAAI 2017)
Python
119
star
30

diff2vec

Reference implementation of Diffusion2Vec (Complenet 2018) built on Gensim and NetworkX.
Python
117
star
31

LabelPropagation

A NetworkX implementation of Label Propagation from a "Near Linear Time Algorithm to Detect Community Structures in Large-Scale Networks" (Physical Review E 2008).
Python
111
star
32

walklets

A lightweight implementation of Walklets from "Don't Walk Skip! Online Learning of Multi-scale Network Embeddings" (ASONAM 2017).
Python
98
star
33

tigerlily

TigerLily: Finding drug interactions in silico with the Graph.
Jupyter Notebook
95
star
34

BANE

A sparsity aware implementation of "Binarized Attributed Network Embedding" (ICDM 2018).
Python
85
star
35

EgoSplitting

A NetworkX implementation of "Ego-splitting Framework: from Non-Overlapping to Overlapping Clusters" (KDD 2017).
Python
80
star
36

ASNE

A sparsity aware and memory efficient implementation of "Attributed Social Network Embedding" (TKDE 2018).
Python
77
star
37

TENE

A sparsity aware implementation of "Enhanced Network Embedding with Text Information" (ICPR 2018).
Python
71
star
38

SINE

A PyTorch Implementation of "SINE: Scalable Incomplete Network Embedding" (ICDM 2018).
Python
69
star
39

RolX

An alternative implementation of Recursive Feature and Role Extraction (KDD11 & KDD12)
Python
58
star
40

GraRep

A SciPy implementation of "GraRep: Learning Graph Representations with Global Structural Information" (WWW 2015).
Python
58
star
41

PDN

The official PyTorch implementation of "Pathfinder Discovery Networks for Neural Message Passing" (WebConf '21)
Python
55
star
42

TADW

An implementation of "Network Representation Learning with Rich Text Information" (IJCAI '15).
Python
54
star
43

spatiotemporal_datasets

Spatiotemporal datasets collected for network science, deep learning and general machine learning research.
43
star
44

NMFADMM

A sparsity aware implementation of "Alternating Direction Method of Multipliers for Non-Negative Matrix Factorization with the Beta-Divergence" (ICASSP 2014).
Python
40
star
45

FEATHER

The reference implementation of FEATHER from the CIKM '20 paper "Characteristic Functions on Graphs: Birds of a Feather, from Statistical Descriptors to Parametric Models".
Python
40
star
46

BoostedFactorization

An implementation of "Multi-Level Network Embedding with Boosted Low-Rank Matrix Approximation" (ASONAM 2019).
Python
33
star
47

resolutions-2019

A list of data mining and machine learning papers that I implemented in 2019.
20
star
48

OrbitalFeatures

A sparsity aware implementation of "Biological Network Comparison Using Graphlet Degree Distribution" (Bioinformatics 2007)
Python
19
star
49

FSCNMF

An implementation of "Fusing Structure and Content via Non-negative Matrix Factorization for Embedding Information Networks".
Python
18
star
50

GRAF

Inner product natural graph factorization machine used in 'GEMSEC: Graph Embedding with Self Clustering' .
Python
10
star
51

HullCoverConditionedUnitDiskGraph

A generator for unit disk graphs conditioned on concave hull cover.
Python
8
star
52

AV_Ultimate_Student_Hunt

Solution for the Ultimate Student Hunt Challenge (1st place).
R
8
star
53

NestedSubtreeHash

A distributed implementation of "Nested Subtree Hash Kernels for Large-Scale Graph Classification Over Streams" (ICDM 2012).
Python
7
star
54

Societe-General

Solution for ENS - Societe Generale Challenge (1st place).
R
5
star
55

resolutions-2020

4
star
56

graphmining.ai

Benedek Rozemberczki Personal Webpage
4
star
57

benedekrozemberczki

3
star