# Heterogeneous Graph Transformer

Graph transformer with type-specific weights models large heterogeneous graphs

Ziniu Hu, Yuxiao Dong, Kuansan Wang, Yizhou Sun · arXiv · 2020-3-3

- **Problem** Most graph neural networks assume all nodes and edges share one type, so they cannot model heterogeneous graphs. Earlier heterogeneous models depend on hand-designed meta paths, ignore timing, and do not scale to billion-edge academic graphs.
- **Method** HGT sets attention and message weights by each edge's meta relation.
- **Results** On the Open Academic Graph Paper-Field (L1) task, HGT improves over the baselines by 15–19% in NDCG and 18–21% in MRR.

## Why earlier heterogeneous GNNs fall short

Academic graphs mix object types, and the Open Academic Graph has five node types: papers, authors, institutions, venues and fields. Earlier heterogeneous GNNs usually depend on meta paths designed by hand for each graph type, which demands domain knowledge. In OAG, paper nodes carry text features, institution nodes draw on affiliated scholars, and coauthorship edges differ from citation links.

The graph also changes over time. Venue topics drift across decades, so a model that ignores timing can mix meanings from different eras. Scale is the other obstacle, since OAG holds hundreds of millions of nodes and billions of relationships and earlier heterogeneous GNNs were not built for that size.

The study therefore asks two linked questions: whether attention with node- and edge-type dependent parameters can beat homogeneous and heterogeneous GNNs without hand-designed meta paths, and whether temporal information and Web-scale training can be handled inside the same heterogeneous GNN.

## How one HGT layer forms an update

A general GNN layer splits into attention, message and aggregation operators, and the earlier attention model GAT uses one weight matrix for every node, which assumes that sender and receiver share a feature distribution. HGT keeps this three-step split but replaces the single weight matrix with projections chosen by node type and by edge type, so each edge is handled through its meta relation, the triplet of sender type, edge type and receiver type.

For the attention, the receiver is mapped by a query projection indexed by its own type and the sender by a key projection indexed by the sender type. The two are combined through a matrix tied to the edge type and scaled by a prior over the meta relation, which lets relations of different importance be weighted differently. Each attention head has the form below, and the heads are concatenated before a softmax over all neighbors of each receiver, so the attention weights for a receiver sum to one.

\\\\\[ \\\\text{ATT-head}\_i(s,e,t)=\\\\left(K\_i(s)\\\\,W^{ATT}\_{\\\\phi(e)}\\\\,Q\_i(t)^{\\\\top}\\\\right)\\\\cdot\\\\frac{\\\\mu\_{\\\\langle\\\\tau(s),\\\\phi(e),\\\\tau(t)\\\\rangle}}{\\\\sqrt{d}} \\\\\]

The message is computed per head by projecting the sender with a matrix indexed by the sender type and then multiplying by a matrix indexed by the edge type, so the edge dependency enters the message itself. \\\\\[ \\\\text{MSG-head}\_i(s,e,t)=\\\\text{M-Linear}\_{\\\\tau(s)}\\\\big(H^{(l-1)}\[s\]\\\\big)\\\\,W^{MSG}\_{\\\\phi(e)} \\\\\]

Aggregation at each receiver multiplies every sender message by its attention weight and sums them over the neighbors. The softmax already makes these weights sum to one, so the sum is a weighted average. \\\\\[ H\_e^{(l)}\[t\]=\\\\bigoplus\_{s\\\\in N(t)}\\\\big(\\\\text{Attention}\_{HGT}(s,e,t)\\\\cdot\\\\text{Message}\_{HGT}(s,e,t)\\\\big) \\\\\] A type-specific linear projection of the result, followed by a nonlinearity, is added back to the receiver's previous representation through a residual connection, which keeps the output in the receiver's own type space.

\\\\\[ H^{(l)}\[t\]=\\\\text{A-Linear}\_{\\\\tau(t)}\\\\big(\\\\sigma(H\_e^{(l)}\[t\])\\\\big)+H^{(l-1)}\[t\] \\\\\] Stacking a small number of such layers lets each node draw on nodes of many types that lie several hops away, which is how multi-hop structure reaches the model without explicit meta paths.

## Encoding relative time gaps

Slicing the graph into one subgraph per time slot can drop structural dependencies that cross slots, and a node at one time may depend on edges formed at another time. HGT instead keeps all edges with their timestamps and encodes the time difference between each sender and receiver, which lets nodes and edges from different times interact.

The relative time gap is the receiver's timestamp minus the sender's timestamp, and the encoding is built from fixed sinusoid basis functions followed by a learnable linear projection, so it can take gap values that the training data does not contain. \\\\\[ \\\\text{Base}(\\\\Delta T\_{t,s},2i)=\\\\sin\\\\!\\\\Big(\\\\frac{\\\\Delta T\_{t,s}}{10000^{2i/d}}\\\\Big),\\\\qquad \\\\text{Base}(\\\\Delta T\_{t,s},2i+1)=\\\\cos\\\\!\\\\Big(\\\\frac{\\\\Delta T\_{t,s}}{10000^{(2i+1)/d}}\\\\Big) \\\\\] \\\\\[ \\\\text{RTE}(\\\\Delta T\_{t,s})=\\\\text{T-Linear}\\\\big(\\\\text{Base}(\\\\Delta T\_{t,s})\\\\big) \\\\\] The authors chose the fixed sinusoid part so the encoding can generalize to unseen times and gaps, and the projection is the only learned part of the encoding.

The encoding is added to the sender representation before the layer runs, so the sender carries information about its time offset from the receiver. \\\\\[ \\\\widehat{H}^{(l-1)}\[s\]=H^{(l-1)}\[s\]+\\\\text{RTE}(\\\\Delta T\_{t,s}) \\\\\] Because the encoding is trained end-to-end with the rest of the model, the temporal dependency is learned together with the attention and message weights.

## Sampling sub-graphs for Web-scale training

Full-batch training computes all node representations at every layer, which does not scale to Web-scale graphs, and existing sampling methods can return sub-graphs that are badly unbalanced across node types because degree and count differ widely by type. HGSampling keeps a separate node budget for each node type and draws an equal number of nodes per type, so the sub-graph has similar counts across types.

When a node joins the sample, its neighbors enter the budget of their own types, and each neighbor is credited with the normalized degree of the newly added node. This accumulates a random-walk-like weight on candidates that are strongly tied to the sampled set, and it keeps high-degree nodes from dominating. The sampling probability of a candidate node s of type τ is its squared accumulated budget divided by the squared L2 norm of the budget for that type, which the authors state is variance-reducing following prior work.

\\\\\[ \\\\text{prob}^{(l-1)}\_{\[\\\\tau\]\[s\]}=\\\\frac{B\[\\\\tau\]\[s\]^{2}}{\\\\lVert B\[\\\\tau\]\\\\rVert\_2^{2}} \\\\\] Sampling repeats for L depth, and the adjacency matrix is rebuilt over the sampled nodes, so the sub-graph stays dense enough that little information is lost.

Some nodes, such as conferences, have no fixed time. Their timestamp is inherited from a linked event node, such as the year of a paper published there, during sampling, while event nodes keep their own time. This matters for a conference like WWW, whose topics in 1974 and in 2019 differ, so the timestamp decides which version of the node the model sees.

## Datasets, baselines and training protocol

The main graph is OAG with 178,663,927 nodes and 2,236,196,802 edges, and its papers are dated from 1900 to 2019. Two domain subgraphs, Computer Science (CS) and Medicine (Med), were built from OAG, with 11,732,027 and 51,044,324 nodes respectively.

Node types are paper, author, field, venue and institute. Fields are split into six levels, L0 to L5, and the paper–field edges are kept separate by level. Author order and venue type also create separate relation types, and a self-loop type is added.

Four tasks are used: Paper–Field (L1), Paper–Field (L2) and Paper–Venue as node classification with a softmax output, and Author Disambiguation as link prediction scored by a Neural Tensor Network. Papers before 2015 form the training set, 2015 to 2016 the validation set and 2016 to 2019 the test set, and each model is trained five times, reporting mean and standard deviation under NDCG and MRR.

GCN and GAT serve as homogeneous baselines, and RGCN, HetGNN and HAN as heterogeneous baselines, all run with the HGSampling procedure on OAG. Because feature types are not assumed to share a distribution, each node type gets its own linear adaptation layer before the GNNs, which the authors apply to the baselines too for a fair comparison.

Hidden size is 256, multi-head models use 8 heads, and every GNN keeps 3 layers. Models are optimized with AdamW and a cosine annealing schedule for 200 epochs, and the checkpoint with the lowest validation loss is reported. The default settings from GNN literature were used without tuning.

## Accuracy against five baselines

In Table 2, the full HGT model has the highest mean in the reported NDCG and MRR rows for the tasks and graphs covered.

On OAG Paper–Field (L1), the full model reaches NDCG .615±.084 and MRR .702±.081. Its relative gains over the baselines on this task are 15–19% in NDCG and 18–21% in MRR, where each gain is the performance gap divided by the baseline score.

HAN is the strongest baseline in most cases, and the average relative NDCG improvement of HGT over HAN is 11% on CS, 10% on Med and 8% on OAG. Averaged over the four tasks and the three large graphs, HGT is 20% above GCN, GAT, RGCN, HetGNN and HAN. The abstract summarises the gains over all baselines as 9–21%.

## Parameter count and batch time

Among the heterogeneous baselines it has fewer parameters than RGCN, HetGNN and HAN, but its batch time is higher than RGCN and HetGNN, so the authors' description of comparable batch time holds only against HAN and the other heterogeneous models with larger batch time. The authors read these numbers as evidence that modeling edges by their meta relation generalizes well at lower resource cost.

## What removing each component costs

Two components are switched off separately: heterogeneous weight parameterization (Heter) and relative temporal encoding (RTE), giving the variants HGT+RTE−Heter, HGT−RTE+Heter and HGT−RTE−Heter alongside the full HGT+RTE+Heter. Their parameter counts are 7.44M for HGT+RTE−Heter...

Removing heterogeneous weight parameterization (HGT+RTE−Heter) drops performance by 4% relative to the full model. Removing relative temporal encoding (HGT−RTE+Heter) drops performance by 2% relative to the full model. The drops are read as showing that parameterizing by meta relation and using relative temporal encoding both matter for the model, since removing either lowers performance.

A baseline with one weight matrix per relation was also considered, but it had too many parameters for the available GPU memory, so it could not be trained. The authors read this as showing that meta-relation parameterization reaches competitive accuracy with fewer resources.

## Venue similarity over time

The study takes 100 computer science conferences with the highest citations, gives each one timestamps 2000, 2010 and 2020, and ranks the others by Euclidean distance between the HGT representations. The analysis focuses on WWW, KDD and NeurIPS and lists the five nearest venues at each timestamp.

For WWW the nearest venues in 2000 are SIGMOD, VLDB, NSDI, GLOBECOM and SIGIR, and in 2020 they are KDD, GLOBECOM, SIGIR, WSDM and SIGMOD. The authors interpret the shift as WWW moving toward data mining and information retrieval venues.

For KDD the nearest venues move from SIGMOD, ICDE, ICDM, CIKM and VLDB in 2000 to NeurIPS, SIGMOD, WWW, AAAI and EMNLP in 2020. The authors also note that NeurIPS in 2020 is closest to ICLR, which they describe as a newly organized deep learning conference.

The learned attention also points to meta relation sequences. The three strongest are read as the meta paths PVP, PFP and IAP, which the model finds without manual design.

## Limitations

The baselines were run with default settings and were not tuned. The unique-weight-per-relation baseline was not optimized because the experimental setting did not have enough GPU memory. The experiments cover OAG and its CS and Med subgraphs, so no other kind of heterogeneous graph was tested. The temporal evidence is one qualitative table of venue neighbors, and the authors leave generation of heterogeneous graphs and pre-training for scarce labels to future work.

## Paper info

- **Authors**: Ziniu Hu, Yuxiao Dong, Kuansan Wang, Yizhou Sun
- **Venue**: arXiv · Preprint
- **First published**: 2020-3-3
- **Added**: 2026-11-13
- **Updated**: 2020-3-3
- **Version**: v1
- **arXiv**: 2003.01332
- **Category**: cs.LG · cs.SI · stat.ML
- **Original paper terms**: [arXiv non-exclusive 1.0](https://arxiv.org/licenses/nonexclusive-distrib/1.0/)
- **What we show**: Paper info and commentary

[Original paper ↗](https://arxiv.org/abs/2003.01332v1) · [PDF ↗](https://arxiv.org/pdf/2003.01332v1)

AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.

## Quote from the paper

Ziniu Hu, Yuxiao Dong, Kuansan Wang, Yizhou Sun (2020). Heterogeneous Graph Transformer. arXiv:2003.01332v1. https://arxiv.org/abs/2003.01332v1

**BibTeX**

```
@misc{hu2020heterogeneous,
  title = {{Heterogeneous Graph Transformer}},
  author = {Ziniu Hu and Yuxiao Dong and Kuansan Wang and Yizhou Sun},
  year = {2020},
  eprint = {2003.01332},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2003.01332v1}
}
```

## Other paper commentary

- [Deep Learning on Graphs: A Survey](https://refivu.com/en/papers/2184aed4-7bc8-45a4-81a9-0ad60f8dc1c1-deep-learning-on-graphs-a-survey.md)
- [Graph Embedding Techniques, Applications, and Performance: A Survey](https://refivu.com/en/papers/eeed1384-bf87-452c-b3b1-9ecc6ce7d43b-graph-embedding-techniques-applications-and-performance-a.md)
- [Session-based Recommendation with Graph Neural Networks](https://refivu.com/en/papers/62d7225d-cbaa-40dd-937a-e1fda19d331d-session-based-recommendation-with-graph-neural-networks.md)
- [RotatE: Knowledge Graph Embedding by Relational Rotation in Complex Space](https://refivu.com/en/papers/6cf7532c-a2b4-4553-a534-0482af8548e2-rotate-knowledge-graph-embedding-by-relational-rotation-in.md)
- [A Comprehensive Survey of Graph Embedding: Problems, Techniques and Applications](https://refivu.com/en/papers/ec23e11b-6984-4611-aa20-93a65865b536-a-comprehensive-survey-of-graph-embedding-problems.md)
- [Graph Neural Networks for Social Recommendation](https://refivu.com/en/papers/3f172e45-3e51-4657-9b43-76ed2fb286e9-graph-neural-networks-for-social-recommendation.md)
- [Fast Underwater Image Enhancement for Improved Visual Perception](https://refivu.com/en/papers/3952933f-2406-4db3-9d2c-43621581b5b2-fast-underwater-image-enhancement-for-improved-visual.md)
- [Kindling the Darkness: A Practical Low-light Image Enhancer](https://refivu.com/en/papers/e0950d09-0e10-4409-aac5-8ad757e499cc-kindling-the-darkness-a-practical-low-light-image.md)
- [Zero-Shot Learning -- A Comprehensive Evaluation of the Good, the Bad and the Ugly](https://refivu.com/en/papers/b2424a9a-08ad-4ff8-86b0-d8e0b3d11aaf-zero-shot-learning-a-comprehensive-evaluation-of-the.md)
- [Deep Generative Image Models using a Laplacian Pyramid of Adversarial Networks](https://refivu.com/en/papers/bb403729-1f3c-4c78-a4d7-1f9c9ea6cd8f-deep-generative-image-models-using-a-laplacian-pyramid.md)
- [Deep Convolutional Networks on Graph-Structured Data](https://refivu.com/en/papers/b94a76bd-69b6-41d9-9dc2-a50ec07493aa-deep-convolutional-networks-on-graph-structured-data.md)
- [Wider or Deeper: Revisiting the ResNet Model for Visual Recognition](https://refivu.com/en/papers/92402cc1-8a47-44e2-ab4e-68cd6d212e9b-wider-or-deeper-revisiting-the-resnet-model-for.md)

## Terms in this paper

- [Transformer](https://refivu.com/en/terms/48e8be2570bc-transformer)
- [MRR](https://refivu.com/en/terms/3d251a2fd6a5-mrr)
- [NDCG](https://refivu.com/en/terms/4758d58c5780-ndcg)
- [Graph Convolutional Networks (GCN)](https://refivu.com/en/terms/789810032eb2-graph-convolutional-networks-gcn)
- [HGSampling](https://refivu.com/en/terms/8b9d75350bee-hgsampling)
- [Neural Tensor Network](https://refivu.com/en/terms/a924108e0b3d-neural-tensor-network)

---

AI-written text can contain mistakes. [Refivu](https://refivu.com/en/papers/f71bb06f-968c-4006-81b4-63b69f07a087-heterogeneous-graph-transformer)
