A PyTorch Implementation of Gated Graph Sequence Neural Networks (GGNN)

Overview

A PyTorch Implementation of GGNN

This is a PyTorch implementation of the Gated Graph Sequence Neural Networks (GGNN) as described in the paper Gated Graph Sequence Neural Networks by Y. Li, D. Tarlow, M. Brockschmidt, and R. Zemel. This implementation gets 100% accuracy on node-selection bAbI task 4, 15, and 16. Their official implementation are available in the yujiali/ggnn repo on GitHub.

What is GGNN?

  • Solve graph-structured data and problems
  • A gated propagation model to compute node representations
  • Unroll recurrence for a fixed number of steps and use backpropogation through time
  • An output model to make predictions on nodes

Requirements

  • python==2.7
  • PyTorch>=0.2

Run

Train and test the GGNN:

python main.py --cuda (use GPUs or not)

Suggesting configurations for each task:

# task 4
python main.py --task_id 4 --state_dim 4 --niter 10
# task 15
python main.py --task_id 15 --state_dim 5 --niter 10
# task 16
python main.py --task_id 16 --state_dim 10 --niter 150

Results

I followed the paper, randomly picking only 50 training examples for training. Performances are evaluated on 50 random validation examples.

bAbI Task Performance
4 100%
15 100%
16 100%

Here's an example of bAbI deduction task (task 15)

Disclaimer

The data processing codes are from official implementation yujiali/ggnn.

TODO

  • GraphLevel Output

References

Comments
  • Question about Graph-Level output

    Question about Graph-Level output

    In your todo list, you list out the task : GraphLevel Output, then I assume that you haven't implemented this task in the current code set.

    But so far when I read the source code, I can see that you nearly finish it. This line: https://github.com/JamesChuanggg/ggnn.pytorch/blob/0c7897fe9b05e9b4f9a963ff55bd3ad917ea734e/model.py#L123 is to compute the vector representation of the graph that will use to predict the target class and compute the CrossEntropy loss in the latter step. In the current Babi tasks, the prediction target is the label of the node (in most of the task). But for the graph-level output, e.g graph classification, I guess what we need to do is instead of predicting the label of the node, we predict the label of the whole graph, and with the current set of code, we have 99% of the code ready, no need to do more. Not sure If I understand this correctly, please help me to clarify.

    opened by bdqnghi 3
  • Creating adjacency matrix

    Creating adjacency matrix

    For the part to create the adjacency matrix, it's not clear to me.

    For example, we have 2 edges: 2 1 3 1 1 2

    Then from the code implementation here: https://github.com/JamesChuanggg/ggnn.pytorch/blob/master/utils/data/dataset.py#L79

    Supposed there are 4 node types and 2 edges types, then Row = 4 , Column = 4 X 2 X 2 = 16 Then we get the 4 X 16 Matrix M : [[0. 0. 0. 0. 0. 0. 0. 0. 0. 1. 0. 0. 0. 0. 0. 0.] [1. 0. 0. 0. 0. 0. 0. 0. 0. 0. 1. 0. 0. 0. 0. 0.] [0. 1. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.] [0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]]

    Where: M[2][1] = 1 M[1][10] = 1 M[1][0] = 1 M[0][9] = 1

    What kind of adjacency matrix like this? I've checked the paper, it doesn't mention anything similar to this. I suspect that this is the matrix from Figure 1, section 3.2 of the paper that illustrates how nodes in the graph communicate with each other, in this case, it should be a 4 X 8 Matrix, not 4 X 16.

    Please help me to enlighten my understanding. Thanks!!!

    opened by bdqnghi 1
  • Removing these code and then it become origin GNN?

    Removing these code and then it become origin GNN?

    https://github.com/JamesChuanggg/ggnn.pytorch/blob/master/model.py#L29-L40

            self.reset_gate = nn.Sequential(
                nn.Linear(state_dim*3, state_dim),
                nn.Sigmoid()
            )
            self.update_gate = nn.Sequential(
                nn.Linear(state_dim*3, state_dim),
                nn.Sigmoid()
            )
            self.tansform = nn.Sequential(
                nn.Linear(state_dim*3, state_dim),
                nn.Tanh()
            )
    

    @JamesChuanggg Thank you very much!

    opened by guotong1988 1
  • have trouble to figure out what is task_type?

    have trouble to figure out what is task_type?

    https://github.com/JamesChuanggg/ggnn.pytorch/blob/master/utils/data/dataset.py#L72

        for item in data_list:
            edge_list = item[0]
            target_list = item[1]
            for target in target_list:
                task_type = target[0]
    

    Thank you very much!! @JamesChuanggg

    opened by guotong1988 1
  • What is the meaning of annotation? Have trouble to figure it out..

    What is the meaning of annotation? Have trouble to figure it out..

    https://github.com/JamesChuanggg/ggnn.pytorch/blob/master/utils/data/dataset.py#L74-L75

    annotation = np.zeros([n_nodes, n_annotation_dim])
    annotation[target[1]-1][0] = 1
    

    @JamesChuanggg Thank you!

    opened by guotong1988 1
  • Bug fix for indexing 0-dim tensor in utils/test.py

    Bug fix for indexing 0-dim tensor in utils/test.py

    Error Message

    Error message when running main.py:

    Traceback (most recent call last):
      File "main.py", line 72, in <module>
        main(opt)
      File "main.py", line 68, in main
        test(test_dataloader, net, criterion, optimizer, opt)
      File ".../ggnn.pytorch/utils/test.py", line 24, in test
        test_loss += criterion(output, target).data[0]
    IndexError: invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to a Python number
    

    Steps to reproduce:

    1. Create a new virtualenv with python2.7.
    2. pip install torch numpy
    3. python main.py

    Suggested Reason

    I believe the bug occured due to a depreciating of indexing 0-dim tensors in an update to PyTorch.

    I have implemented the fix.

    opened by lharries 0
Owner
Ching-Yao Chuang
Ching-Yao Chuang
An implementation of a sequence to sequence neural network using an encoder-decoder

Keras implementation of a sequence to sequence model for time series prediction using an encoder-decoder architecture. I created this post to share a

Luke Tonin 195 Dec 17, 2022
Pervasive Attention: 2D Convolutional Networks for Sequence-to-Sequence Prediction

This is a fork of Fairseq(-py) with implementations of the following models: Pervasive Attention - 2D Convolutional Neural Networks for Sequence-to-Se

Maha 490 Dec 15, 2022
Sequence to Sequence Models with PyTorch

Sequence to Sequence models with PyTorch This repository contains implementations of Sequence to Sequence (Seq2Seq) models in PyTorch At present it ha

Sandeep Subramanian 708 Dec 19, 2022
Sequence-to-Sequence learning using PyTorch

Seq2Seq in PyTorch This is a complete suite for training sequence-to-sequence models in PyTorch. It consists of several models and code to both train

Elad Hoffer 514 Nov 17, 2022
Implementation of SETR model, Original paper: Rethinking Semantic Segmentation from a Sequence-to-Sequence Perspective with Transformers.

SETR - Pytorch Since the original paper (Rethinking Semantic Segmentation from a Sequence-to-Sequence Perspective with Transformers.) has no official

zhaohu xing 112 Dec 16, 2022
Pytorch Code for "Medical Transformer: Gated Axial-Attention for Medical Image Segmentation"

Medical-Transformer Pytorch Code for the paper "Medical Transformer: Gated Axial-Attention for Medical Image Segmentation" About this repo: This repo

Jeya Maria Jose 615 Dec 25, 2022
Rethinking Semantic Segmentation from a Sequence-to-Sequence Perspective with Transformers

Segmentation Transformer Implementation of Segmentation Transformer in PyTorch, a new model to achieve SOTA in semantic segmentation while using trans

Abhay Gupta 161 Dec 8, 2022
Understanding and Improving Encoder Layer Fusion in Sequence-to-Sequence Learning (ICLR 2021)

Understanding and Improving Encoder Layer Fusion in Sequence-to-Sequence Learning (ICLR 2021) Citation Please cite as: @inproceedings{liu2020understan

Sunbow Liu 22 Nov 25, 2022
[CVPR 2021] Rethinking Semantic Segmentation from a Sequence-to-Sequence Perspective with Transformers

[CVPR 2021] Rethinking Semantic Segmentation from a Sequence-to-Sequence Perspective with Transformers

Fudan Zhang Vision Group 897 Jan 5, 2023
Sequence lineage information extracted from RKI sequence data repo

Pango lineage information for German SARS-CoV-2 sequences This repository contains a join of the metadata and pango lineage tables of all German SARS-

Cornelius Roemer 24 Oct 26, 2022
Official repository of OFA. Paper: Unifying Architectures, Tasks, and Modalities Through a Simple Sequence-to-Sequence Learning Framework

Paper | Blog OFA is a unified multimodal pretrained model that unifies modalities (i.e., cross-modality, vision, language) and tasks (e.g., image gene

OFA Sys 1.4k Jan 8, 2023
Source Code for our paper: Understand me, if you refer to Aspect Knowledge: Knowledge-aware Gated Recurrent Memory Network

KaGRMN-DSG_ABSA This repository contains the PyTorch source Code for our paper: Understand me, if you refer to Aspect Knowledge: Knowledge-aware Gated

XingBowen 4 May 20, 2022
RefineGNN - Iterative refinement graph neural network for antibody sequence-structure co-design (RefineGNN)

Iterative refinement graph neural network for antibody sequence-structure co-des

Wengong Jin 83 Dec 31, 2022
A static analysis library for computing graph representations of Python programs suitable for use with graph neural networks.

python_graphs This package is for computing graph representations of Python programs for machine learning applications. It includes the following modu

Google Research 258 Dec 29, 2022
The source code of the paper "Understanding Graph Neural Networks from Graph Signal Denoising Perspectives"

GSDN-F and GSDN-EF This repository provides a reference implementation of GSDN-F and GSDN-EF as described in the paper "Understanding Graph Neural Net

Guoji Fu 18 Nov 14, 2022
Some tentative models that incorporate label propagation to graph neural networks for graph representation learning in nodes, links or graphs.

Some tentative models that incorporate label propagation to graph neural networks for graph representation learning in nodes, links or graphs.

zshicode 1 Nov 18, 2021
On Size-Oriented Long-Tailed Graph Classification of Graph Neural Networks

On Size-Oriented Long-Tailed Graph Classification of Graph Neural Networks We provide the code (in PyTorch) and datasets for our paper "On Size-Orient

Zemin Liu 4 Jun 18, 2022
Selene is a Python library and command line interface for training deep neural networks from biological sequence data such as genomes.

Selene is a Python library and command line interface for training deep neural networks from biological sequence data such as genomes.

Troyanskaya Laboratory 323 Jan 1, 2023