← Open Source
acbull

pyHGT

Code for "Heterogeneous Graph Transformer" (WWW'20), which is based on pytorch_geometric.

Model DevelopmentArchitectureDomain-specific trainingPython
Open on GitHub
Momentum
+0stars in 24 hours0.0%
936
Stars
173
Forks
+1
This week
6
Contributors
Created 2020-02-21 · Updated 2026-10-10 · #12529 today
Top developers
acbullconferencesubsnash4

acbull/pyHGT is ranked 12,529 with 936 stars.

Same-category comparison

acbull/pyHGT is ranked 12,529 among these 8 peers; baal-org/baal is ranked 12,530.

Same-category comparison
NameRankMetrics
qiaoguan/deep-ctr-prediction12,517
Language:
Python
Stars:
938
Forks:
277
Farama-Foundation/Shimmy12,519
Language:
Python
Stars:
937
Forks:
32
Description:
PettingZoo and Gymnasium bindings for popular reinforcement learning environments outside of Farama.
eaplatanios/tensorflow_scala12,521
Language:
Scala
Stars:
937
Forks:
89
Description:
TensorFlow API for the Scala Programming Language.
mnicnc404/CartoonGan-tensorflow12,524
Language:
Python
Stars:
937
Forks:
238
Description:
Generate your own cartoon-style images with CartoonGAN (CVPR 2018), powered by TensorFlow 2.0 Alpha.
baal-org/baal12,530
Language:
Python
Stars:
936
Forks:
91
Description:
Bayesian active learning library for research and industrial usecases.
ImprintLab/Medical-SAM212,540
Language:
Python
Stars:
934
Forks:
139
Description:
Medical SAM 2: Segment 3D Medical Images Via Segment Anything Model 2.
benedekrozemberczki/graph2vec12,541
Language:
Python
Stars:
934
Forks:
165
Description:
A parallel implementation of "graph2vec: Learning Distributed Representations of Graphs" (MLGWorkshop 2017).
eric-yyjau/pytorch-superpoint12,544
Language:
Jupyter Notebook
Stars:
934
Forks:
194
Description:
Superpoint Implemented in PyTorch: https://arxiv.org/abs/1712.07629.
Key parameters and specifications
Key parameters and specifications
ParameterValue
LanguagePython
CategoryModel Development
SubcategoryArchitecture, Domain-specific training
Stars936
Forks173
Contributors6
Created date2020-02-21
Updated date2026-10-10
Stars in 1 day0
Stars in 7 days1
Rank12,529
Previous rank12,452
Rank change-77
7-day stars rank10,411
Previous 7-day stars rank10,464
7-day stars rank change53
Total stars rank11,718
Previous total stars rank11,701
Total stars rank change-17
CountryUSA
README summary

Heterogeneous Graph Transformer (HGT) Alternative reference Deep Graph Library (DGL) implementation Heterogeneous Graph Transformer is a graph neural network architecture that can deal with large-scale heterogeneous and dynamic graphs. You can see our WWW 2020 paper “**Heterogeneous Graph Transformer**” for more details. This implementation of HGT is based on Pytorch Geometric API Overview The most important files in this projects are as follow: conv. py: The core of our model, implements the transformer-like heterogeneous graph convolutional layer. py

: The wrap of different model components. : The data structure of heterogeneous graph. DataFrame; Stores adjacency matrix in Graph. : The sampling algorithm for heterogeneous graph. Each iteration samples a fixed number of nodes per type. All the sampled nodes are within the region of already sampled nodes, with sampling probability as the square of relative degree. py: The training and validation script for a specific downstream task. : The sampling function for a given task. Remember to mask out existing link within

the graph to avoid information leakage. : Conduct sampling in parallel with multiple processes, which can seamlessly coordinate with model training. Setup This implementation is based on pytorch_geometric. To run the code, you need the following dependencies: Pytorch 1. 3 gensim sklearn tqdm dill pandas You can simply run to install all the necessary packages. OAG DataSet Our current experiments are conducted on Open Academic Graph (OAG). For easiness of usage, we split and preprocess the whole dataset into different

granularity: all **CS papers (8. You can download the preprocessed graph via this link. If you want to directly process from raw data, you can download via this link. After downloading it, run to extract features and store them in our data structure. You can also use our code to process other heterogeneous graph, as long as you load them into our data structure in data. Usage Execute the following scripts to train on paper-field (L2) classification task using

HGT: Conducting other two tasks are similar. There are some key options of this scrips: : Choose corresponding model for training. and : The depth and width of sampled graph. If the model exceeds the GPU memory, can consider reduce their number; if one wants to train a deeper GNN model, consider adding these numbers. : The number of process to parallely conduct sampling. If one has a machine with large memory, can consider adding this number to reduce batch prepartion time. : The

number of time to reuse a sampled batch for training. If the training time is much smaller than sampling time, can consider adding this number. The details of other optional hyperparameters can be found in train_*. Citation Please consider citing the following paper when using our code for your application.

Frequently asked questions

How many stars and forks are recorded?

acbull/pyHGT has 936 stars and 173 forks.

What is the repository rank?

acbull/pyHGT is ranked 12,529.

What language and category are recorded?

acbull/pyHGT has 936 stars, uses Python and belongs to Model Development.

Which repository is closest in rank?

acbull/pyHGT is compared with baal-org/baal, ranked 12,530 with 936 stars.

README

Heterogeneous Graph Transformer (HGT)

Alternative reference Deep Graph Library (DGL) implementation

Heterogeneous Graph Transformer is a graph neural network architecture that can deal with large-scale heterogeneous and dynamic graphs.

You can see our WWW 2020 paper “Heterogeneous Graph Transformer” for more details.

This implementation of HGT is based on Pytorch Geometric API

Overview

The most important files in this projects are as follow:

  • conv.py: The core of our model, implements the transformer-like heterogeneous graph convolutional layer.
  • model.py: The wrap of different model components.
  • data.py: The data interface and usage.
    • class Graph: The data structure of heterogeneous graph. Stores feature in Graph.node_feature as pandas.DataFrame; Stores adjacency matrix in Graph.edge_list as dictionay.
    • def sample_subgraph: The sampling algorithm for heterogeneous graph. Each iteration samples a fixed number of nodes per type. All the sampled nodes are within the region of already sampled nodes, with sampling probability as the square of relative degree.
  • train_*.py: The training and validation script for a specific downstream task.
    • def *_sample: The sampling function for a given task. Remember to mask out existing link within the graph to avoid information leakage.
    • def prepare_data: Conduct sampling in parallel with multiple processes, which can seamlessly coordinate with model training.

Setup

This implementation is based on pytorch_geometric. To run the code, you need the following dependencies:

You can simply run pip install -r requirements.txt to install all the necessary packages.

OAG DataSet

Our current experiments are conducted on Open Academic Graph (OAG). For easiness of usage, we split and preprocess the whole dataset into different granularity: all CS papers (8.1G), all ML papers (1.9G), all NN papers (0.6G) spanning from 1900-2020. You can download the preprocessed graph via this link.

If you want to directly process from raw data, you can download via this link. After downloading it, run preprocess_OAG.py to extract features and store them in our data structure.

You can also use our code to process other heterogeneous graph, as long as you load them into our data structure class Graph in data.py. Refer to preprocess_OAG.py for a demonstration.

Usage

Execute the following scripts to train on paper-field (L2) classification task using HGT:

python3 train_paper_field.py --data_dir PATH_OF_DATASET --model_dir PATH_OF_SAVED_MODEL --conv_name hgt

Conducting other two tasks are similar. There are some key options of this scrips:

  • conv_name: Choose corresponding model for training. By default we use HGT.
  • --sample_depth and --sample_width: The depth and width of sampled graph. If the model exceeds the GPU memory, can consider reduce their number; if one wants to train a deeper GNN model, consider adding these numbers.
  • --n_pool: The number of process to parallely conduct sampling. If one has a machine with large memory, can consider adding this number to reduce batch prepartion time.
  • --repeat: The number of time to reuse a sampled batch for training. If the training time is much smaller than sampling time, can consider adding this number.

The details of other optional hyperparameters can be found in train_*.py.

Citation

Please consider citing the following paper when using our code for your application.

@inproceedings{hgt,
  author    = {Ziniu Hu and
               Yuxiao Dong and
               Kuansan Wang and
               Yizhou Sun},
  title     = {Heterogeneous Graph Transformer},
  booktitle = {{WWW} '20: The Web Conference 2020, Taipei, Taiwan, April 20-24, 2020},
  pages     = {2704--2710},
  publisher = {{ACM} / {IW3C2}},
  year      = {2020},
  url       = {https://doi.org/10.1145/3366423.3380027},
  doi       = {10.1145/3366423.3380027},
  timestamp = {Wed, 06 May 2020 12:56:16 +0200},
  biburl    = {https://dblp.org/rec/conf/www/HuDWS20.bib},
  bibsource = {dblp computer science bibliography, https://dblp.org}
}
Nearby in the ranking
Similar items