Skip to content

Latest commit

Β 

History

History
493 lines (373 loc) Β· 24.2 KB

README.md

File metadata and controls

493 lines (373 loc) Β· 24.2 KB

πŸ“¦ Deep Learning Module

This repository aims at hosting the Deep Learning modules to train Graph Representation Self-Supervised Learning (GRSSL) methods in order to compute graphs embeddings.

The general deep learning modules rely on PyTorch [3] and DGL [4] libraries.

Data used to (pre)train the graph representation methods come from Netzschleuder, hosted in graph-tool python library [5].

Table of Content

  1. πŸͺ© Features
  2. ⚑️ Quick start
    1. Installation
    2. Train a model
  3. 🌻 Graph Neural Networks
    1. Models' architecture
    2. Encoding Layers
  4. 🧳 Graphs Datasets
  5. βš™οΈ Implementation
  6. 🫧 Usage
    1. Configurations
    2. Results
    3. Visualisation
  7. 🌡 Folder Structure
  8. πŸ“š References
    1. Bibliography
    2. Acknoledgements

The Graph Neural Networks section wraps the theoretical grounding of the methods whose implementations are hosted in this repository. Details regarding the Graphs Datasets used and the Implementation are described afterwards. Detailed instructions on how to use the code and/or custom it to ones needs are given in the Usage section.

πŸͺ© 0. Features

This repository can be used to:

  • train GRL models;
  • evaluate performances of the models on selected tasks;
  • visualise the embeddings produced by the models.

⚑️ 1. Quick start

1.a Installation

pip install -r requirements.txt
conda install graph-tool

1.b Train a model

python train.py --c <config_file_path>.json

You can then visualise the learnt graphs representations with:

python viz.py --c <config_file_path>.json --n

Note You can also launch the companion notebook πŸ”— for a step-by-step tutorial.


🌻 2. Graph Neural Networks

πŸ”

2.a Self-Supervised models

Self-supervised learning is an attractive training paradigm in the big data era. It aims at mitigating the over-dependence of DL models on labeled data by devising training procedure from pretext tasks that don't require labels.

This repository shelters the implementation of two state-of-the-art self-supervised GRL models: GraphMAE [1] and PGCL [2]. These two models stem the two main subdomain of SSL: predictive and contrastive learning.

On one hand, Graph Masked Auto-Encoder (GraphMAE) is a generative method that aims at reconstructing node features (which are hidden during training).

On the other hand, Prototypical Graph Contrastive Learning (PGCL) is a contrastive learning model that was notably devised to alleviate the sampling bias harming contrastive methods.

2.b Encoding Layers

Most of GRL models (including GraphMAE and PGCL) rely on Graph Neural Networks (GNNs): adaptation of neural networks to handle graph-structured data. GNN layers are the backbone of these models and can often be used interchangeably.

GNNs implement message-passing methods that iteratively aggregate and combine information of nodes and their neighbours. They ultimately produce graphs of nodes' states with the same topology as the input graph.

Three of the most popular GNN instances are:

  • Graph Attention layer (GAT)
  • Graph Convolutional Network (GCN)
  • Graph Isomorphism Network (GIN)

Then, a pooling layer can be used to obtain whole-graph representation from the nodes states.

🧳 3. Graphs Datasets

πŸ”

The main goal of this repository is to enable the implementation of self-supervised methods. Those are meant to be general enough to tackle various tasks, while still being achieving high-performances.

With this in mind, a dataset containing graph from various domains and with different sizes is designed to train the models. Then the models are evaluated on standard graph classification baselines.

3.a Training

The training dataset is based on the Netzschleuder catalogue that references graphs hosted by graph-tool library [5]. The training dataset is obtained by setting a few constraints on the types of graphs (number of edges, balance, etc.). Thanks to graph-tool implementation, it can easily be loaded within python pipelines and used to train the models.

3.b Evaluation

The evaluation of the trained models is performed on the most common benchmark in the literature: graph classification on a subset of datasets from the TUDataset [6].

βš™οΈ 4. Implementation

πŸ”

The proposed implementation is flexible and provides ways to implement new models based on general modules. The implementation of the Deep Learning pipeline is composed of 4 main components meant to be customisable and adaptable to fit different frameworks. Each of the module can be modified or instanciated differently to render different models.

These four components allow to load graphs datasets, implement models and their backbone encoders and to train the models:

  • GraphDataset (see code)
  • GRSSLModel (see code)
    • Encoder (see code)
  • Trainer (see code)

🫧 5. Usage

πŸ”

The whole pipeline is illustrated in a notebook chaining the different steps of this project.

Models can be trained using the following command line:

python train.py --c <config_file_path>.json

The training and results can be replicated by running the .sh script:

./repro_training.sh <config_file>

This script will train 5 models instantiated from the same configuration file but with different seeds. The models are stored before training as model_untrained.pth and the models from the epoch achieving the lowest loss as model_best.pth.

Then the performances of each of the 5 models are assessed (both before and after training) on a selected set of TU Datasets. The results are stored in a .csv file, together with the models.

5.a Configurations

🫧

The configurations of the models are provided as .json files containing all the required parameters and hyperparameters from the loading of the training dataset to the model's architectures details and the training scheme to follow.

See example configuration files in this folder πŸ”—.

5.b Results

🫧

Results obtained through this pipeline are described below.

Expected runtimes

First note that all computation were undertaken on a MacBook Pro (M1, 2020).

The expected runtimes for the training are shown in the following table:

Model type Configuration Average training time Av. epoch time
GraphMAE config link 02:23:14 00:01:54
PGCL config link 07:01:16 00:04:49

Classification performances

The performances of the models are assessed on several graphs datasets selected from the TU datasets. Those datasets are widely used in the literature and provide common basis for models' comparison. The performances are computed by appending a SVC-classifier on top of the representations computed by the different models.

The outcome of the performance assessment are compiled in the table below. The average micro-F1 score upon 10-fold classification is reported for each dataset and each of the models.

Instructions to run tests

The evaluation procedure is implemented in Utils/performance_assessment.py. It can be run with the following command line:

python Utils/performance_assessment.py\
   -s <PATH_TO_SAVED_MODEL_FOLDER>\
	 -r <RUN_ID_0> <RUN_ID_1> ...\ # several possible
	 -d <DATASET_0> <DATASET_1> ...\

This script will store the results in a .csv file at the level of <PATH_TO_SAVED_MODEL_FOLDER>.

Model (config) Custom (Training) REDDIT-BINARY COLLAB IMDB-BINARY IMDB-MULTI PROTEINS DD
NodesEdges
[ config ]
84 (Β±1) 83 (Β±3) 68 (Β±2) 71 (Β±2) 48 (Β±4) 73 (Β±4) 75 (Β±4)
TradDegs
[ config ]
91.9 (Β±1.4) 82.7 (Β±2.4) 80.8 (Β±1.0) 73.1 (Β±3.0) 50.5 (Β±1.7) 74.9 (Β±3.4) 75.8 (Β±3.0)
GraphMAE
[ config ]
94.8 (Β±0.3) 90.0 (Β±0.5) 79.1 (Β±0.4) 73.3 (Β±1.0) 50.5 (Β±0.4) 74.3 (Β±0.8) 75.8 (Β±0.4)
PGCL
[ config ]
95.1 (Β±1.7) 91.4 (Β±0.7) 74.5 (Β±0.7) 71.3 (Β±0.6) 48.6 (Β±0.8) 70.5 (Β±0.9) 69.8 (Β±1.5)
Compare with performances BEFORE training
Model (config) Custom (Training) REDDIT-BINARY COLLAB IMDB-BINARY IMDB-MULTI PROTEINS DD
GraphMAE
[ config ]
Relative Change
94.0 (Β±0.2)
↓
- 0.8%
87.6 (Β±0.3)
↓
- 2.7%
78.2 (Β±0.3)
↓
- 1.7%
73.0 (Β±1.0)
=
- 0.4%
50.5 (Β±0.6)
=
+ 0.1%
74.0 (Β±0.7)
=
- 0.4%
76.2 (Β±0.6)
=
+ 0.5%
PGCL
[ config ]
Relative Change
95.0 (Β±0.7)
=
- 0.1%
89.5 (Β±1.3)
↓
-2.1%
69.8 (Β±0.3)
↓
-6.3%
71.1 (Β±0.4)
↓
-0.3%
48.1 (Β±0.3)
=
-1.0%
69.7 (Β±0.5)
=
-1.1%
66.1 (Β±0.8)
↓
-5.3%

5.c Visualisation

🫧

The class GRVisualiser (see code) is implemented to ease the visualisation and exploration of Graph Representations computed with the models.

The visualisation module makes use of matplotlib [7] and seaborn [8] libraries. The interactive module is implemented with plotly [9].

Usage (and possible visualisation outputs) are also showcased in the demonstration notebook. Visualisations can be obtained by running the following command line:

python viz.py -m <path_to_model> -d <dataset_name>

The following options can be given to the program:

  • -m or --model: the path to the model
  • -d or --dataset: dataset's name
  • -s or --save_path: save figure at this path if given
  • -f or --force_save: save figure with automatically generated name based on model and dataset, in illustrations/ folder
  • -i or --interactive: output interactive plot (default at port http://0.0.0.0:8060/)

Then, the program can be executed with the following command line:

python viz.py -m <model_path> -r <reducer> -d <dataset_id> -f -i

For example, the following allows to visualise the embeddings of the "REDDIT-BINARY" dataset, generated with the best saved PGCL model (it needs to be saved at ./saved/best_models/PGCL/), reduced with TSNE; save the figure and output the interactive plot:

python viz.py -d "REDDIT-BINARY"\
   -m './saved/best_models/PGCL/'\
   -s 'illustrations/pgcl_rdtb_tsne.png'\
   -i
Gallery
TradDegs PGCL GraphMAE
Netzschleuder catalogue Degs-Netz PGCL-Netz GraphMAE-Netz
REDDIT-BINARY Degs-RDB PGCL-RDB GrMAE-RDB
Interactive visualisation demonstration
GIF of an interactive visualisation (zoom + visualise instances + move + ...)

drafty plotly demo

🌡 6. Folder Structure

πŸ”

DL_module/
β”œβ”€β”€ __init__.py
β”œβ”€β”€ Configs/
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ config_files/
β”‚   β”‚   └── <CONFIG_NAME>.json
β”‚   β”œβ”€β”€ configs_parser.py
β”‚   └── inspector.py # deprecated
β”œβ”€β”€ DataLoader/
β”‚   β”œβ”€β”€ data_loader.py
β”‚   β”œβ”€β”€ data_util.py
β”‚   └── test.ipynb # deprecated
β”œβ”€β”€ illustrations/
β”‚   └── ...
β”œβ”€β”€ Logger/
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ logger.py
β”‚   β”œβ”€β”€ logger_config.json
β”‚   └── visualization.py
β”œβ”€β”€ Models/
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ encoders.py
β”‚   β”œβ”€β”€ from_pretrained.py
β”‚   β”œβ”€β”€ model_grssl.py
β”‚   β”œβ”€β”€ model_util.py
β”‚   β”œβ”€β”€ README.md # deprecated ?
β”‚   └── test.ipynb # deprecated
β”œβ”€β”€ PGCL_pipe_tests.ipynb # deprecated
β”œβ”€β”€ pipe_tests.ipynb
β”œβ”€β”€ README.md
β”œβ”€β”€ repro_training.sh
β”œβ”€β”€ requirements.txt
β”œβ”€β”€ saved/
β”‚   β”œβ”€β”€ best_models/
β”‚   β”‚   β”œβ”€β”€ <MODEL_NAME>/
β”‚   β”‚   β”‚   β”œβ”€β”€ config.json
β”‚   β”‚   β”‚   └── model_best.pth
β”‚   β”‚   └── trad_degs/
β”‚   β”‚       └── config.json
β”‚   β”œβ”€β”€ log/
β”‚   β”‚   └── <MODEL_NAME>/
β”‚   β”‚       └── <RUN_ID>/
β”‚   β”‚           └── info.log
β”‚   β”œβ”€β”€ models/
β”‚   β”‚   └── <MODEL_NAME>/
β”‚   β”‚       └── <RUN_ID>/
β”‚   β”‚           β”œβ”€β”€ config.json
β”‚   β”‚           β”œβ”€β”€ model_untrained.json
β”‚   β”‚           β”œβ”€β”€ model_best.pth
β”‚   β”‚           └── config.json
β”‚   └── repro/
β”‚       β”œβ”€β”€ log/
β”‚       β”‚   └── ...
β”‚       └── models/
β”‚           └── ...
β”œβ”€β”€ showcase_pretrained.ipynb
β”œβ”€β”€ tests.ipynb # deprecated
β”œβ”€β”€ train.py
β”œβ”€β”€ Trainers/
β”‚   β”œβ”€β”€ loss.py
β”‚   β”œβ”€β”€ trainer.py
β”‚   └── trainer_util.py
β”œβ”€β”€ Utils/
β”‚   β”œβ”€β”€ misc.py
β”‚   β”œβ”€β”€ performance_assessment.py
β”‚   └── tasks.py
β”œβ”€β”€ Visualisers/
β”‚   β”œβ”€β”€ visualiser.py
β”‚   └── viz_util.py
└── viz.py

πŸ“š 7. References

πŸ”

Bibliography

[1] (^back to: 0.; 2.a) [ paperΒ | code ]
Hou, Z., Liu, X., Dong, Y., Wang, C., & Tang, J. (2022). GraphMAE: Self-Supervised Masked Graph Autoencoders. arXiv preprint arXiv:2205.10803.

[2] (^back to: 0.; 2.a) [ paperΒ | code ] Lin, S., Liu, C., Zhou, P., Hu, Z. Y., Wang, S., Zhao, R., ... & Liang, X. (2022). Prototypical Graph Contrastive Learning. IEEE Transactions on Neural Networks and Learning Systems.

[3] (^back to: 1) [ paper |Β code]
Paszke, A., Gross, S., Massa, F., Lerer, A., Bradbury, J., Chanan, G., … Chintala, S. (2019). PyTorch: An Imperative Style, High-Performance Deep Learning Library. In Advances in Neural Information Processing Systems 32 (pp. 8024–8035). Curran Associates, Inc.

[4] (^back to: 1) [ paper |Β code ]
Minjie Wang, Da Zheng, Zihao Ye, Quan Gan, Mufei Li, Xiang Song, Jinjing Zhou, Chao Ma, Lingfan Yu, Yu Gai, Tianjun Xiao, Tong He, George Karypis, Jinyang Li, & Zheng Zhang (2019). Deep Graph Library: A Graph-Centric, Highly-Performant Package for Graph Neural Networks. arXiv preprint arXiv:1909.01315.

[5] (^back to: 1, 3.a) [ website | figshare ]
Tiago P. Peixoto. (2014). The graph-tool python library. figshare.

[6] (^back to: 3.b) [ website | paper ]
Christopher Morris, Nils M. Kriege, Franka Bause, Kristian Kersting, Petra Mutzel, & Marion Neumann (2020). TUDataset: A collection of benchmark datasets for learning with graphs. In ICML 2020 Workshop on Graph Representation Learning and Beyond (GRL+ 2020).

[7] (^back to: 5.c) [ website ]
Hunter, J. (2007). Matplotlib: A 2D graphics environment. Computing in Science & Engineering, 9(3), 90–95.

[8] (^back to: 5.c) [ website ]
Michael L. Waskom (2021). seaborn: statistical data visualization. Journal of Open Source Software, 6(60), 3021.

[9] (^back to: 5.c) [ website ]
Inc., P. T. (2015). Collaborative data science. Montreal, QC: Plotly Technologies Inc. Retrieved from https://plot.ly.

Acknoledgements

  • The general organisation of this repository, as well as some general implementations are taken from the project pytorch-template.

  • The code of the different GRSSL methods are slight adjustments of the original implementations to fit the general framework used here.


[ πŸͺ© | ⚑️ | 🌻 | 🧳 |Β βš™οΈ | 🫧 | 🌡 |Β πŸ“š ]