Skip to content
ImagineWorld

Heterogeneous Graph Transformer

node_idnode-paper_arxiv-2003.01332_heterogeneous-graph-transformer
node_typenode-paper
schema_profileworld.node_paper.v1
alternate_namesarxiv-2003.01332, hu-dong-wang-sun-hgt-2020, hgt
statusactive
orthogonal_scopemanifold, entropy, authority, state
manifoldworld
entropymedium
authorityguides
stateexternal
domainimagineworld.net
node_interiorrosetta_contract
unisonHGT establishes that parameterizing attention, message passing, and aggregation by meta-relation triplets (source node type, edge type, target node type) achieves superior heterogeneous graph representation with fewer parameters than relation-specific matrices. Constitutionally: typed attention over heterogeneous edges is a load-bearing primitive for the kernel-and-connectome-encoded organism's graph-structured memory and relational inference substrate.
governed_byWORLD-MANIFOLD, CORPUS
constitutional_citationCONSTITUTION
evidence_bundleworld-bundle-paper
compared_byworld-comparison-pillar-e-ai-research-history-and-learning-theory
pillar_membershipE — graph neural networks + heterogeneous information networks + kernel connectome architectural encoding
publication_classarxiv_preprint
paper_titleHeterogeneous Graph Transformer
paper_authorsZiniu Hu, Yuxiao Dong, Kuansan Wang, Yizhou Sun
paper_author_affiliationsUniversity of California, Los Angeles, Microsoft Research, Redmond
paper_abstractRecent years have witnessed the emerging success of graph neural networks (GNNs) for modeling structured data. However, most GNNs are designed for homogeneous graphs, in which all nodes and edges belong to the same types, making them infeasible to represent heterogeneous structures. In this paper, we present the Heterogeneous Graph Transformer (HGT) architecture for modeling Web-scale heterogeneous graphs. To model heterogeneity, we design node- and edge-type dependent parameters to characterize the heterogeneous attention over each edge, empowering HGT to maintain dedicated representations for different types of nodes and edges. To handle dynamic heterogeneous graphs, we introduce the relative temporal encoding technique into HGT, which is able to capture the dynamic structural dependency with arbitrary durations. To handle Web-scale graph data, we design the heterogeneous mini-batch graph sampling algorithm---HGSampling---for efficient and scalable training. Extensive experiments on the Open Academic Graph of 179 million nodes and 2 billion edges show that the proposed HGT model consistently outperforms all the state-of-the-art GNN baselines by 9%--21% on various downstream tasks.
arxiv_id2003.01332
arxiv_urlhttps://arxiv.org/abs/2003.01332
arxiv_categories{"primary":"cs.LG","secondary":["cs.SI","stat.ML"]}
arxiv_v1
arxiv_submitted_at2020-03-03
arxiv_updated_at2020-03-03
peer_review_venueWWW 2020
source_pdforganism/imagineworld/corpus/4_relational-geometry/geometric-graph-learning/by_article/heterogeneous-graph-transformer/source/arxiv-2003.01332.pdf
source_pdf_sha25687337e3f28e6078e8624f22a357c79f0ef2cf5a38f810e1e4b3d5e6679129449
source_latex_archiveorganism/imagineworld/corpus/4_relational-geometry/geometric-graph-learning/by_article/heterogeneous-graph-transformer/source/arxiv-2003.01332.tar.gz
source_latex_archive_sha256fe5436ce1c7a2d6ca8f3d427561f6b07733566130c85f9b51465663bc3e6133f
ocr_sourcearxiv_latex_source
ocr_quality_classverbatim_latex
extraction_toolkimi-k2.6
extraction_pipeline_versionworld-ingest-arxiv-llm-prompt-template-v1.0
extracted_at2026-05-16T10:36:00+00:00
math_preserved_as_latextrue
figures_extractedtrue
references_structurally_parsedfalse
cites_arxiv{"arxiv_id":"1609.02907","title":"GCN: Semi-Supervised Classification with Graph Convolutional Networks","in_sections":["introduction","preliminaries"]}, {"arxiv_id":"1710.10903","title":"GAT: Graph Attention Networks","in_sections":["introduction","preliminaries"]}, {"arxiv_id":"1706.02216","title":"GraphSAGE: Inductive Representation Learning on Large Graphs","in_sections":["introduction","train"]}, {"arxiv_id":"1811.05868","title":"FastGCN: Fast Learning with Graph Convolutional Networks via Importance Sampling","in_sections":["train"]}, {"arxiv_id":"1911.07323","title":"LADIES: Layer-Dependent Importance Sampling for Training Deep and Large Graph Convolutional Networks","in_sections":["train"]}, {"arxiv_id":"1703.06103","title":"R-GCN: Modeling Relational Data with Graph Convolutional Networks","in_sections":["preliminaries"]}, {"arxiv_id":"1810.04805","title":"BERT: Pre-training of Deep Bidirectional Transformers","in_sections":["introduction"]}, {"arxiv_id":"1706.03762","title":"Attention Is All You Need","in_sections":["approach"]}
cites_external
cited_by_arxiv
supersedes
superseded_by
distill_corpus_weight3
distill_corpus_tier0
distill_relevance_gapsgap-11-kernel-connectome-architectural-encoding
distill_relevance_phase_i_guidesi-1-corpus-assembly-methodology
training_signal_rolegnn_heterogeneous_architecture_foundation
training_signal_typetier_0_constitutional_for_graph_neural_networks
pillar_normalizedE-graph
created_at2026-05-16T10:36:00+00:00
updated_at2026-10-14T05:20:09Z
local graph

Authors: Ziniu Hu (UCLA)†, Yuxiao Dong (Microsoft Research), Kuansan Wang (Microsoft Research), Yizhou Sun (UCLA) Emails: [email protected], [email protected], [email protected], [email protected] † This work was done when Ziniu was an intern at Microsoft Research.

[!warning] Extraction-quality notes (local-LLM ingest) Several repairs were made during cleanup, and some gaps could not be recovered — flagged inline below:

  • Author header was reconstructed from the email handles (only emails survived extraction); only “Ziniu” is named in the source footnote.
  • Missing core section: the main HGT architecture (Heterogeneous Mutual Attention, Heterogeneous Message Passing, Target-Specific Aggregation) appears to be absent from this node — the Heterogeneous Graph Transformer section jumps straight to Relative Temporal Encoding. Flagged where it occurs.
  • No reference list was captured. In-text citations were reconstructed (author + year) from the bibliography-key structure and surrounding prose; treat author-year forms as best-effort.
  • Tables (OAG statistics, results, case study) were rebuilt from garbled ASCII. One probable metric-label swap in the results table is flagged.
  • A [^1] footnote was referenced but its definition was lost; the dangling markers were removed.

Recent years have witnessed the emerging success of graph neural networks (GNNs) for modeling structured data. However, most GNNs are designed for homogeneous graphs, in which all nodes and edges belong to the same types, making them infeasible to represent heterogeneous structures. In this paper, we present the Heterogeneous Graph Transformer (HGT) architecture for modeling Web-scale heterogeneous graphs. To model heterogeneity, we design node- and edge-type dependent parameters to characterize the heterogeneous attention over each edge, empowering HGT to maintain dedicated representations for different types of nodes and edges. To handle dynamic heterogeneous graphs, we introduce the relative temporal encoding technique into HGT, which is able to capture the dynamic structural dependency with arbitrary durations. To handle Web-scale graph data, we design the heterogeneous mini-batch graph sampling algorithm — HGSampling — for efficient and scalable training. Extensive experiments on the Open Academic Graph of 179 million nodes and 2 billion edges show that the proposed HGT model consistently outperforms all the state-of-the-art GNN baselines by 9%–21% on various downstream tasks. The dataset and source code of HGT are publicly available at https://github.com/acbull/pyHGT.

Keywords: Graph Neural Networks; Heterogeneous Information Networks; Representation Learning; Graph Embedding; Graph Attention

Heterogeneous graphs have been commonly used for abstracting and modeling complex systems, in which objects of different types interact with each other in various ways. Some prevalent instances of such systems include academic graphs, Facebook entity graph, LinkedIn economic graph, and broadly the Internet of Things network. For example, the Open Academic Graph (OAG) (Zhang et al., 2019) in Figure 1 contains five types of nodes: papers, authors, institutions, venues (journal, conference, or preprint), and fields, as well as different types of relationships between them.

Figure 1 — Schema and meta relations of the Open Academic Graph (OAG). Given a Web-scale heterogeneous graph, e.g., an academic network, HGT takes only its one-hop edges as input without manually designing meta paths. (No source image in node — schema rendered below.)

flowchart LR
    A["Author"] ---|"P–A (authorship)"| P["Paper"]
    A ---|"A–I (affiliation)"| I["Institute"]
    P ---|"P–V (published at)"| V["Venue<br/>(journal / conference / preprint)"]
    P ---|"P–F (has field)"| F["Field"]
    P -->|"P–P (citation)"| P

Over the past decade, a significant line of research has been explored for mining heterogeneous graphs (Sun & Han, 2012). One of the classical paradigms is to define and use meta paths to model heterogeneous structures, such as PathSim (Sun et al., 2011) and metapath2vec (Dong et al., 2017). Recently, in view of graph neural networks’ (GNNs) success (GCN, Kipf & Welling, 2017; GraphSAGE, Hamilton et al., 2017; GAT, Veličković et al., 2018), there are several attempts to adopt GNNs to learn with heterogeneous networks (Schlichtkrull et al., 2018; Zhang et al., 2019; Wang et al., 2019; graph transformer). However, these works face several issues: First, most of them involve the design of meta paths for each type of heterogeneous graphs, requiring specific domain knowledge; Second, they either simply assume that different types of nodes/edges share the same feature and representation space or keep distinct non-sharing weights for either node type or edge type alone, making them insufficient to capture heterogeneous graphs’ properties; Third, most of them ignore the dynamic nature of every (heterogeneous) graph; Finally, their intrinsic design and implementation make them incapable of modeling Web-scale heterogeneous graphs.

Take OAG for example: First, the nodes and edges in OAG could have different feature distributions, e.g., papers have text features whereas institutions may have features from affiliated scholars, and coauthorships obviously differ from citation links; Second, OAG has been consistently evolving, e.g., 1) the volume of publications doubles every 12 years (Dong et al., 2017), and 2) the KDD conference was more related to database in the 1990s whereas more to machine learning in recent years; Finally, OAG contains hundreds of millions of nodes and billions of relationships, leaving existing heterogeneous GNNs not scalable for handling it.

In light of these limitations and challenges, we propose to study heterogeneous graph neural networks with the goal of maintaining node- and edge-type dependent representations, capturing network dynamics, avoiding customized meta paths, and being scalable to Web-scale graphs. In this work, we present the Heterogeneous Graph Transformer (HGT) architecture to deal with all these issues.

To handle graph heterogeneity, we introduce the node- and edge-type dependent attention mechanism. Instead of parameterizing each type of edges, the heterogeneous mutual attention in HGT is defined by breaking down each edge e=(s,t)e = (s, t) based on its meta relation triplet, i.e., ⟨node type of ss, edge type of ee between ss & tt, node type of tt⟩. Figure 1 illustrates the meta relations of heterogeneous academic graphs. In specific, we use these meta relations to parameterize the weight matrices for calculating attention over each edge. As a result, nodes and edges of different types are allowed to maintain their specific representation spaces. Meanwhile, connected nodes in different types can still interact, pass, and aggregate messages without being restricted by their distribution gaps. Due to the nature of its architecture, HGT can incorporate information from high-order neighbors of different types through message passing across layers, which can be regarded as “soft” meta paths. That said, even if HGT take only its one-hop edges as input without manually designing meta paths, the proposed attention mechanism can automatically and implicitly learn and extract “meta paths” that are important for different downstream tasks.

To handle graph dynamics, we enhance HGT by proposing the relative temporal encoding (RTE) strategy. Instead of slicing the input graph into different timestamps, we propose to maintain all the edges happening in different times as a whole, and design the RTE strategy to model structural temporal dependencies with any duration length, and even with unseen and future timestamps. By end-to-end training, RTE enables HGT to automatically learn the temporal dependency and evolution of heterogeneous graphs.

To handle Web-scale graph data, we design the first heterogeneous sub-graph sampling algorithm — HGSampling — for mini-batch GNN training. Its main idea is to sample heterogeneous sub-graphs in which different types of nodes are with similar proportions, since the direct usage of existing (homogeneous) GNN sampling methods, such as GraphSAGE (Hamilton et al., 2017), FastGCN, and LADIES, results in highly imbalanced ones regarding to both node and edge types. In addition, it is also designed to keep the sampled sub-graphs dense for minimizing the loss of information. With HGSampling, all the GNN models, including our proposed HGT, can train and infer on arbitrary-size heterogeneous graphs.

We demonstrate the effectiveness and efficiency of the proposed Heterogeneous Graph Transformer on the Web-scale Open Academic Graph comprised of 179 million nodes and 2 billion edges spanning from 1900 to 2019, making this the largest-scale and longest-spanning representation learning yet performed on heterogeneous graphs. Additionally, we also examine it on domain-specific graphs: the computer science and medicine academic graphs. Experimental results suggest that HGT can significantly improve various downstream tasks over state-of-the-art GNNs as well as dedicated heterogeneous models by 9%–21%. We further conduct case studies to show the proposed method can indeed automatically capture the importance of implicit meta paths for different tasks.

In this section, we introduce the basic definition of heterogeneous graphs with network dynamics and review the recent development on graph neural networks (GNNs) and their heterogeneous variants. We also highlight the difference between HGT and existing attempts on heterogeneous graph neural networks.

Heterogeneous graphs (Sun & Han, 2012) (a.k.a., heterogeneous information networks) are an important abstraction for modeling relational data for many real-world complex systems. Formally, it is defined as:

Heterogeneous Graph. A heterogeneous graph is defined as a directed graph G=(V,E,A,R)G = (\mathcal{V}, \mathcal{E}, \mathcal{A}, \mathcal{R}) where each node v∈Vv \in \mathcal{V} and each edge e∈Ee \in \mathcal{E} are associated with their type mapping functions τ(v):V→A\tau(v): V \rightarrow \mathcal{A} and ϕ(e):E→R\phi(e): E \rightarrow \mathcal{R}, respectively.

Meta Relation. For an edge e=(s,t)e = (s, t) linked from source node ss to target node tt, its meta relation is denoted as ⟨τ(s),ϕ(e),τ(t)⟩\langle \tau(s), \phi(e), \tau(t) \rangle. Naturally, ϕ(e)−1\phi(e)^{-1} represents the inverse of ϕ(e)\phi(e). The classical meta path paradigm (Sun et al., 2011; Sun et al., 2012; Sun & Han, 2012) is defined as a sequence of such meta relation.

Notice that, to better model real-world heterogeneous networks, we assume that there may exist multiple types of relations between different types of nodes. For example, in OAG there are different types of relations between the author and paper nodes by considering the authorship order, i.e., “the first author of”, “the second author of”, and so on.

Dynamic Heterogeneous Graph. To model the dynamic nature of real-world (heterogeneous) graphs, we assign an edge e=(s,t)e = (s, t) a timestamp TT, when node ss connects to node tt at TT. If ss appears for the first time, TT is also assigned to ss. ss can be associated with multiple timestamps if it builds connections over time.

In other words, we assume that the timestamp of an edge is unchanged, denoting the time it is created. For example, when a paper published on a conference at time TT, TT will be assigned to the edge between the paper and conference nodes. On the contrary, different timestamps can be assigned to a node accordingly. For example, the conference node “WWW” can be assigned any year. WWW@1994 means that we are considering the first edition of WWW, which focuses more on internet protocol and Web infrastructure, while WWW@2020 means the upcoming WWW, which expands its research topics to social analysis, ubiquitous computing, search & IR, privacy and society, etc.

There have been significant lines of research on mining heterogenous graphs, such as node classification, clustering, ranking and representation learning (Sun & Han, 2012; Sun et al., 2011; Sun et al., 2012; Dong et al., 2017), while the dynamic perspective of HGs has not been extensively explored and studied.

Recent years have witnessed the success of graph neural networks for relational data (GCN, Kipf & Welling, 2017; GAT, Veličković et al., 2018; GraphSAGE, Hamilton et al., 2017). Generally, a GNN can be regarded as using the input graph structure as the computation graph for message passing (Gilmer et al., 2017), during which the local neighborhood information is aggregated to get a more contextual representation. Formally, it has the following form:

General GNN Framework. Suppose Hl[t]H^{l}[t] is the node representation of node tt at the ll-th GNN layer, the update procedure from the (l-1)(l\text{-}1)-th layer to the ll-th layer is:

Hl[t]←Aggregate∀s∈N(t),;∀e∈E(s,t)(Extract(Hl−1[s];,Hl−1[t],,e))H^{l}[t] \gets \underset{\forall s \in N(t),; \forall e \in E(s,t)}{\text{Aggregate}} \bigg( \text{Extract}\Big( H^{l-1}[s];, H^{l-1}[t],, e \Big) \bigg)

where N(t)N(t) denotes all the source nodes of node tt and E(s,t)E(s,t) denotes all the edges from node ss to tt.

The most important GNN operators are Extract(⋅\cdot) and Aggregate(⋅\cdot). Extract(⋅\cdot) represents the neighbor information extractor. It extract useful information from source node’s representation Hl−1[s]H^{l-1}[s], with the target node’s representation Hl−1[t]H^{l-1}[t] and the edge ee between the two nodes as query. Aggregate(⋅\cdot) gather the neighborhood information of souce nodes via some aggregation operators, such as mean, sum, and max, while more sophisticated pooling and normalization functions can be also designed.

Various (homogeneous) GNN architectures have been proposed following this framework. Kipf et al. (GCN) propose graph convolutional network (GCN), which averages the one-hop neighbor of each node in the graph, followed by a linear projection and non-linear activation operations. Hamilton et al. propose GraphSAGE that generalizes GCN’s aggregation operation from average to sum, max and a RNN unit. Veličković et al. propose graph attention network (GAT) by introducing the attention mechanism into GNNs, which allows GAT to assign different importance to nodes within the same neighborhood.

Recently, studies have attempted to extend GNNs for modeling heterogeneous graphs. Schlichtkrull et al. (2018) propose the relational graph convolutional networks (RGCN) to model knowledge graphs. RGCN keeps a distinct linear projection weight for each edge type. Zhang et al. (2019) present the heterogeneous graph neural networks (HetGNN) that adopts different RNNs for different node types to integrate multi-modal features. Wang et al. (2019) extend graph attention networks by maintaining different weights for different meta-path-defined edges. They also use high-level semantic attention to differentiate and aggregate information from different meta paths.

Though these methods have shown to be empirically better than the vanilla GCN and GAT models, they have not fully utilized the heterogeneous graphs’ properties. All of them use either node type or edge type alone to determine GNN weight matrices. However, the node or edge counts of different types can vary greatly. For relations that don’t have sufficient occurrences, it’s hard to learn accurate relation-specific weights. To address this, we propose to consider parameter sharing for a better generalization. Given an edge e=(s,t)e = (s,t) with its meta relation as ⟨τ(s),ϕ(e),τ(t)⟩\langle \tau(s), \phi(e), \tau(t) \rangle, if we use three interaction matrices to model the three corresponding elements τ(s),ϕ(e)\tau(s), \phi(e), and τ(t)\tau(t) in the meta relation, then the majority of weights could be shared. For example, in “the first author of” and “the second author of” relationships, their source and target node types are both author to paper, respectively. In other words, the knowledge about author and paper learned from one relation could be quickly transferred and adapted to the other one. Therefore, we integrate this idea with the powerful Transformer-like attention architecture, and propose Heterogeneous Graph Transformer.

To summarize, the key differences between HGT and existing attempts include:

  • Instead of attending on node or edge type alone, we use the meta relation ⟨τ(s),ϕ(e),τ(t)⟩\langle \tau(s), \phi(e), \tau(t) \rangle to decompose the interaction and transform matrices, enabling HGT to capture both the common and specific patterns of different relationships using equal or even fewer parameters.
  • Different from most of the existing works that are based on customized meta paths, we rely on the nature of the neural architecture to incorporate high-order heterogeneous neighbor information, which automatically learns the importance of implicit meta paths.
  • Most previous works don’t take the dynamic nature of (heterogeneous) graphs into consideration, while we propose the relative temporal encoding technique to incorporate temporal information by using limited computational resources.
  • None of the existing heterogeneous GNNs are designed for and experimented with Web-scale graphs, we therefore propose the heterogeneous Mini-Batch graph sampling algorithm designed for Web-scale graph training, enabling experiments on the billion-scale Open Academic Graph.

[!warning] Extraction gap The core HGT architecture subsections — Heterogeneous Mutual Attention, Heterogeneous Message Passing, and Target-Specific Aggregation, with their defining equations — do not appear in this node. The text below resumes at the Relative Temporal Encoding component, which references the (missing) architecture described “by far.”

Figure 2 — Relative Temporal Encoding (RTE) to model graph dynamics. Nodes are associated with timestamps T(⋅)T(\cdot). After the RTE process, the temporal-augmented representations are fed to the HGT model. (No source image in node.)

By far, we present HGT — a graph neural network for modeling heterogeneous graphs. Next, we introduce the Relative Temporal Encoding (RTE) technique for HGT to handle graph dynamic.

The traditional way to incorporate temporal information is to construct a separate graph for each time slot. However, such a procedure may lose a large portion of structural dependencies across different time slots. Meanwhile, the representation of a node at time tt might rely on edges that happen at other time slots. Therefore, a proper way to model dynamic graphs is to maintain all the edges happening at different times and allow nodes and edges with different timestamps to interact with each other.

In light of this, we propose the Relative Temporal Encoding (RTE) mechanism to model the dynamic dependencies in heterogeneous graphs. RTE is inspired by Transformer’s positional encoding method (Vaswani et al., 2017; Shaw et al., 2018), which has been shown successful to capture the sequential dependencies of words in long texts.

Specifically, given a source node ss and a target node tt, along with their corresponding timestamps T(s)T(s) and T(t)T(t), we denote the relative time gap ΔT(t,s)=T(t)−T(s)\Delta T(t,s) = T(t) - T(s) as an index to get a relative temporal encoding RTE(ΔT(t,s))\text{RTE}(\Delta T(t,s)). Noted that the training dataset will not cover all possible time gaps, and thus RTE\text{RTE} should be capable of generalizing to unseen times and time gaps. Therefore, we adopt a fixed set of sinusoid functions as basis, with a tunable linear projection T-Linear:Rd→Rd\text{T-Linear}: \mathbb{R}^{d} \rightarrow \mathbb{R}^{d} as RTE\text{RTE}:

Base(ΔT(t,s),,2i)=sin⁡!(ΔTt,s,/,100002id) Base(ΔT(t,s),,2i+1)=cos⁡!(ΔTt,s,/,100002i+1d) RTE(ΔT(t,s))=T-Linear(Base(ΔTt,s))\begin{aligned} \text{Base}\big(\Delta T(t,s),, 2i\big) &= \sin!\Big(\Delta T_{t,s} ,/, 10000^{\frac{2i}{d}}\Big) \ \text{Base}\big(\Delta T(t,s),, 2i+1\big) &= \cos!\Big(\Delta T_{t,s} ,/, 10000^{\frac{2i+1}{d}}\Big) \ \text{RTE}\big(\Delta T(t,s)\big) &= \text{T-Linear}\Big( \text{Base}(\Delta T_{t,s}) \Big) \end{aligned}

Finally, the temporal encoding relative to the target node tt is added to the source node ss’ representation as follows:

H^(l−1)[s]=H(l−1)[s]+RTE(ΔT(t,s))\widehat{H}^{(l-1)}[s] = H^{(l-1)}[s] + \text{RTE}\big(\Delta T(t,s)\big)

In this way, the temporal augmented representation H^(l−1)\widehat{H}^{(l-1)} will capture the relative temporal information of source node ss and target node tt. The RTE procedure is illustrated in Figure 2.

Figure 3 — HGSampling with Inductive Timestamp Assignment. (Source image not embedded: figures/sample.png)

In this section, we present HGT’s strategies for training Web-scale heterogeneous graphs with dynamic information, including an efficient Heterogeneous Mini-Batch Graph Sampling algorithm — HGSampling — and an inductive timestamp assignment method.

The full-batch GNN (Kipf & Welling, 2017) training requires the calculation of all node representations per layer, making it not scalable for Web-scale graphs. To address this issue, different sampling-based methods (Hamilton et al., 2017; FastGCN; Chen et al., 2018; LADIES) have been proposed to train GNNs on a subset of nodes. However, directly using them for heterogeneous graphs is prone to get sub-graphs that are extremely imbalanced regarding different node types, due to that the degree distribution and the total number of nodes for each type can vary dramatically.

To address this issue, we propose an efficient Heterogeneous Mini-Batch Graph Sampling algorithm — HGSampling — to enable both HGT and traditional GNNs to handle Web-scale heterogeneous graphs. HGSampling is able to 1) keep a similar number of nodes and edges for each type and 2) keep the sampled sub-graph dense to minimize the information loss and reduce the sample variance.

Algorithm 1 outlines the HGSampling algorithm. Its basic idea is to keep a separate node budget B[τ]B[\tau] for each node type τ\tau and to sample an equal number of nodes per type with an importance sampling strategy to reduce variance. Given node tt already sampled, we add all its direct neighbors into the corresponding budget with Algorithm 2, and add tt‘s normalized degree to these neighbors in the budget-update line, which will then be used to calculate the sampling probability. Such normalization is equivalent to accumulate the random walk probability of each sampled node to its neighborhood, avoiding the sampling being dominated by high-degree nodes. Intuitively, the higher such value is, the more a candidate node is correlated with the currently sampled nodes, and thus should be given a higher probability to be sampled.

After the budget is updated, we then calculate the sampling probability in Algorithm 1 (the probability line), where we calculate the square of the cumulative normalized degree of each node ss in each budget. As proved in (LADIES), using such sampling probability can reduce the sampling variance. Then, we sample nn nodes in type τ\tau by using the calculated probability, add them into the output node set, update its neighborhood to the budget, and remove it out of the budget (sampling lines). Repeating such procedure for LL times, we get a sampled sub-graph with LL depth from the initial nodes. Finally, we reconstruct the adjacency matrix among the sampled nodes. By using the above algorithm, the sampled sub-graph contains a similar number of nodes per type (based on the separate node budget), and is sufficiently dense to reduce the sampling variance (based on the normalized degree and importance sampling), making it suitable for training GNNs on Web-scale heterogeneous graphs.

Algorithm 1 — Heterogeneous Mini-Batch Graph Sampling (HGSampling)

Input: Adjacency matrix A for each ⟨τ(s), φ(e), τ(t)⟩ relation pair;
output node set OS; sample number n per node type; sample depth L.
Output: Sampled node set NS; sampled adjacency matrix Â.
NS ← OS # initialize sampled node set as output node set
Initialize an empty Budget B storing nodes for each node type with normalized degree
for t ∈ NS do
Add-In-Budget(B, t, A, NS) # add neighbors of t to B
for l ← 1 to L do
for source node type τ ∈ B do
for source node s ∈ B[τ] do
prob^(l-1)[τ][s] ← B[τ][s]² / ‖B[τ]‖₂² # (line:prob) sampling prob. per source s of type τ
Sample n nodes {t_i}_{i=1..n} from B[τ] using prob^(l-1)[τ]
for t ∈ {t_i}_{i=1..n} do # (line:samp)
OS[τ].add(t) # add node t to output node set
Add-In-Budget(B, t, A, NS) # add neighbors of t to B
B[τ].pop(t) # (line:end) remove sampled node t from Budget
Reconstruct the sampled adjacency matrix  among the sampled nodes OS from A
return OS and Â

Algorithm 2 — Add-In-Budget

Input: Budget B storing nodes for each type with normalized degree; added node t;
adjacency matrix A for each ⟨τ(s), φ(e), τ(t)⟩ relation pair; sampled node set NS.
Output: Updated Budget B.
for each possible source node type τ and edge type φ do
D̂_t ← 1 / len( A_⟨τ, φ, τ(t)⟩[t] ) # normalized degree of added node t w.r.t. ⟨τ, φ, τ(t)⟩
for source node s in A_⟨τ, φ, τ(t)⟩[t] do
if s has not been sampled (s ∉ NS) then # (line:check)
if s has no timestamp then
s.time ← t.time # (line:time) inductively inherit timestamp
B[τ][s] ← B[τ][s] + D̂_t # (line:update) add candidate s to budget with t's normalized degree
return Updated Budget B

Till now we have assumed that each node tt is assigned with a timestamp T(t)T(t). However, in real-world heterogeneous graphs, many nodes are not associated with a fixed time. Therefore, we need to assign different timestamps to it. We denote these nodes as plain nodes. For example, the WWW conference is held in both 1974 and 2019, and the WWW node in these two years has dramatically different research topics. Consequently, we need to decide which timestamp(s) to attach to the WWW node.

There also exist event nodes in heterogeneous graphs that have an explicit timestamp associated with them. For example, the paper node should be associated with its publication behavior and therefore attached to its publication date.

We propose an inductive timestamp assignment algorithm to assign plain nodes timestamps based on event nodes that they are linked with. The algorithm is shown in Algorithm 2 (the timestamp-inherit line). The idea is that plan nodes inherit the timestamps from event nodes. We examine whether the candidate source node is an event node. If yes, like a paper published at a specific year, we keep its timestamp for capturing temporal dependency. If no, like a conference that can be associated with any timestamp, we inductively assign the associated node’s timestamp, such as the published year of its paper, to this plain node. In this way, we can adaptively assign timestamps during the sub-graph sampling procedure.

Table 1 — Open Academic Graph (OAG) statistics. P–A, P–F, P–V, A–I, and P–P denote the edges between paper and author, paper and field, paper and venue, author and institute, and the citation links between two papers.

Dataset#nodes#edges#papers#authors#fields#venues#institutes#P–A#P–F#P–V#A–I#P–P
CS11,732,027107,263,8115,597,6055,985,759119,53727,43316,93115,571,61447,462,5595,597,6067,190,48031,441,552
Med51,044,324451,468,37521,931,58728,779,507289,93025,04418,25685,620,479149,728,48321,931,58828,779,507165,408,318
OAG178,663,9272,236,196,80289,606,25788,364,081615,22853,07325,288300,853,688657,049,40589,606,258167,449,9331,021,237,518

In this section, we evaluate the proposed Heterogeneous Graph Transformer on three heterogeneous academic graph datasets. We conduct the Paper-Field prediction, Paper-Venue prediction, and Author Disambiguation tasks. We also take case studies to demonstrate how HGT can automatically learn and extract meta paths that are important for downstream tasks.

To examine the performance of the proposed model and its real-world applications, we use the Open Academic Graph (OAG) (Sinha et al., 2015; Tang et al., 2008; Zhang et al., 2019) as our experimental basis. OAG consists of more than 178 million nodes and 2.236 billion edges — the largest publicly available heterogeneous academic dataset. In addition, all papers in OAG are associated with their publication dates, spanning from 1900 to 2019.

To test the generalization of the proposed model, we also construct two domain-specific subgraphs from OAG: the Computer Science (CS) and Medicine (Med) academic graphs. The graph statistics are listed in Table 1, in which P–A, P–F, P–V, A–I, and P–P denote the edges between paper and author, paper and field, paper and venue, author and institute, and the citation links between two papers.

Both the CS and Med graphs contain tens of millions of nodes and hundreds of millions of edges, making them at least one magnitude larger than the other CS (e.g., DBLP) and Med (e.g., Pubmed) academic datasets that are commonly used in existing heterogeneous GNN and heterogeneous graph mining studies. Moreover, the three datasets used are far more distinguishable than previously wide-adopted small citation graphs used in GNN studies, such as Cora, Citeseer, and Pubmed (GCN, Kipf & Welling, 2017; GAT, Veličković et al., 2018), which only contain thousands of nodes.

There are totally five node types: ‘Paper’, ‘Author’, ‘Field’, ‘Venue’, and ‘Institute’. The ‘Field’ nodes in OAG are categorized into six levels from L0L_0 to L5L_5, which are organized with a hierarchical tree. Therefore, we differentiate the ‘Paper–Field’ edges corresponding to the field level.

In addition, we differentiate the different author orders (i.e., the first author, the last one, and others) and venue types (i.e., journal, conference, and preprint) as well. Finally, the ‘Self’ type corresponds to the self-loop connection, which is widely added in GNN architectures. Except the ‘Self’ relationship, which are symmetric, all other relation types ϕ\phi have a reverse relation type ϕ−1\phi^{-1}.

Tasks and Evaluation. We evaluate the HGT model on four different real-world downstream tasks: the prediction of Paper–Field (L1L_1), Paper–Field (L2L_2), and Paper–Venue, and Author Disambiguation. The goal of the first three node classification tasks is to predict the correct L1L_1 and L2L_2 fields that each paper belongs to or the venue it is published at, respectively. We use different GNNs to get the contextual node representation of the paper and use a softmax output layer to get its classification label. For author disambiguation, we select all the authors with the same name and their associated papers. The task is to conduct link prediction between these papers and candidate authors. After getting the paper and author node representations from GNNs, we use a Neural Tensor Network to get the probability of each author-paper pair to be linked.

For all tasks, we use papers published before the year 2015 as the training set, papers between 2015 and 2016 for validation, and papers between 2016 and 2019 as testing. We choose NDCG and MRR, which are two widely adopted ranking metrics (Li, 2014; and standard learning-to-rank literature), as the evaluation metrics. All models are trained for 5 times and, the mean and standard variance of test performance are reported.

Baselines. We compare HGT with two classes of state-of-art graph neural networks. All baselines as well as our own model, are implemented via the PyTorch Geometric (PyG) package.

The first class of GNN baselines is designed for homogeneous graphs, including:

  • Graph Convolutional Networks (GCN) (Kipf & Welling, 2017), which simply averages the neighbor’s embedding followed by linear projection. We use the implementation provided in PyG.
  • Graph Attention Networks (GAT) (Veličković et al., 2018), which adopts multi-head additive attention on neighbors. We use the implementation provided in PyG.

The second class considered is several dedicated heterogeneous GNNs as baselines, including:

  • Relational Graph Convolutional Networks (RGCN) (Schlichtkrull et al., 2018), which keeps a different weight for each relationship, i.e., a relation triplet. We use the implementation provided in PyG.
  • Heterogeneous Graph Neural Networks (HetGNN) (Zhang et al., 2019), which adopts different Bi-LSTMs for different node type for aggregating neighbor information. We re-implement this model in PyG following the authors’ official code.
  • Heterogeneous Graph Attention Networks (HAN) (Wang et al., 2019) design hierarchical attentions to aggregate neighbor information via different meta paths. We re-implement this model in PyG following the authors’ official code.

In addition, to systematically analyze the effectiveness of the two major components of HGT, i.e., Heterogeneous weight parameterization (Heter) and Relative Temporal Encoding (RTE), we conduct an ablation study, comparing with models that remove these components. Specifically, we use −Heter-\text{Heter} to denote models that uses the same set of weights for all meta relations, and use −RTE-\text{RTE} to denote models that doesn’t include relative temporal encoding. By considering all the permutations, we have: HGT(−Heter, −RTE), HGT(−Heter, +RTE), HGT(+Heter, −RTE), and HGT(+Heter, +RTE).

We use our HGSampling algorithm proposed in Web-scale HGT Training for all baseline GNNs to handle the large-scale OAG graph. To avoid data leakage, we remove out the links we aim to predict (e.g., the Paper-Field link as the label) from the sub-graph.

Input Features. As we don’t assume the feature of each node type belongs to the same distribution, we are free to use the most appropriate features to represent each type of nodes. For each paper, we use a pre-trained XLNet (XLNet; Wolf et al., 2019) to get the representation of each word in its title. We then average them weighted by each word’s attention to get the title representation for each paper. The initial feature of each author is then simply an average of his/her published papers’ representations. For the field, venue, and institute nodes, we use the metapath2vec model (Dong et al., 2017) to train their node embeddings by reflecting the heterogeneous network structures.

The homogeneous GNN baselines assume the node features belong to the same distribution, while our feature extraction doesn’t fulfill this assumption. To make a fair comparison, we add an adaptation layer between the input features and all used GNNs. This module simply conducts different linear projections for nodes of different types. Such a procedure can be regarded to map heterogeneous data into the same distribution, which is also adopted in literature (Zhang et al., 2019; Wang et al., 2019).

Implementation Details. We use 256 as the hidden dimension throughout the neural networks for all baselines. For all multi-head attention-based methods, we set the head number as 8. All GNNs keep 3 layers so that the receptive fields of each network are exactly the same. All baselines are optimized via the AdamW optimizer (Loshchilov & Hutter, 2019) with the Cosine Annealing Learning Rate Scheduler (Loshchilov & Hutter, 2017). For each model, we train it for 200 epochs and select the one with the lowest validation loss as the reported model. We use the default parameters used in GNN literature and donot tune hyper-parameters.

We summarize the experimental results of the proposed model and baselines on three datasets in Table 2. All experiments for the four tasks are evaluated in terms of NDCG and MRR.

Table 2 — Experimental results of different methods over the three datasets. Tasks: PF-L1 = Paper–Field (L1L_1), PF-L2 = Paper–Field (L2L_2), PV = Paper–Venue, AD = Author Disambiguation. The four HGT variants are: GT⁻⁻ = HGT(−Heter,−RTE), GT⁻⁺ = HGT(−Heter,+RTE), GT⁺⁻ = HGT(+Heter,−RTE), and HGT = HGT(+Heter,+RTE) (full model). Bold marks the best per row.

Model size and speed (dataset-independent):

GCNRGCNGATHetGNNHANGT⁻⁻GT⁻⁺GT⁺⁻HGT
# of parameters1.69M8.80M1.69M8.41M9.45M3.12M3.88M7.44M8.20M
Batch time0.46s1.24s0.97s1.35s2.27s1.11s1.14s1.48s1.50s

CS dataset:

TaskMetricGCNRGCNGATHetGNNHANGT⁻⁻GT⁻⁺GT⁺⁻HGT
PF-L1NDCG.608±.062.603±.065.622±.071.612±.063.618±.058.662±.051.689±.042.705±.036.718±.014
PF-L1MRR.679±.069.683±.056.694±.065.689±.060.691±.051.751±.036.779±.027.799±.023.823±.019
PF-L2NDCG.344±.021.322±.053.357±.058.346±.071.352±.051.362±.048.371±.043.379±.047.403±.041
PF-L2MRR.353±.053.340±.061.382±.057.373±.051.388±.065.394±.072.397±.064.414±.076.439±.078
PVNDCG.406±.081.412±.076.437±.082.431±.074.449±.072.456±.069.461±.066.468±.074.473±.054
PVMRR.215±.066.216±.105.239±.089.245±.069.254±.074.258±.085.265±.090.275±.089.288±.088
ADNDCG.826±.039.835±.042.864±.051.850±.056.859±.053.867±.048.875±.046.886±.048.894±.034
ADMRR.661±.045.665±.054.694±.052.668±.061.688±.049.703±.036.712±.032.727±.038.732±.038

Med dataset:

TaskMetricGCNRGCNGATHetGNNHANGT⁻⁻GT⁻⁺GT⁺⁻HGT
PF-L1NDCG.560±.056.571±.061.584±.076.598±.068.607±.054.654±.048.667±.045.683±.037.709±.029
PF-L1MRR.465±.055.470±.082.493±.069.509±.054.575±.057.620±.066.642±.062.659±.055.688±.048
PF-L2NDCG.334±.035.337±.051.344±.063.342±.048.350±.059.359±.053.365±.047.374±.050.384±.046
PF-L2MRR.337±.061.343±.063.370±.058.373±.061.379±.052.385±.071.397±.069.408±.071.417±.074
PVNDCG.377±.059.383±.062.388±.065.412±.057.416±.068.421±.083.432±.078.446±.083.445±.085
PVMRR.211±.045.217±.058.244±.091.259±.072.271±.056.277±.081.282±.085.288±.074.291±.062
ADMRR †.776±.042.779±.048.828±.044.824±.058.834±.056.838±.047.844±.041.864±.043.871±.040
ADNDCG †.614±.051.625±.049.663±.046.659±.061.667±.053.683±.055.691±.046.708±.041.718±.043

† For the Med Author Disambiguation rows, the source lists MRR before NDCG (the reverse of the CS/OAG blocks) and the magnitudes are inverted relative to those blocks (where NDCG > MRR). The metric labels here may be swapped in the source; values are reproduced exactly as given.

OAG dataset:

TaskMetricGCNRGCNGATHetGNNHANGT⁻⁻GT⁻⁺GT⁺⁻HGT
PF-L1NDCG.508±.141.511±.128.534±.103.543±.084.544±.096.571±.089.578±.086.595±.089.615±.084
PF-L1MRR.556±.136.565±.105.610±.096.616±.076.622±.092.649±.081.657±.078.675±.082.702±.081
PF-L2NDCG.318±.074.328±.046.339±.049.336±.062.342±.051.350±.045.354±.046.358±.052.367±.048
PF-L2MRR.322±.067.332±.052.348±.045.350±.053.358±.049.362±.057.369±.058.371±.064.378±.071
PVNDCG.302±.066.313±.051.317±.057.309±.071.327±.062.334±.058.341±.059.353±.064.355±.062
PVMRR.194±.070.193±.047.196±.052.192±.059.214±.067.229±.061.233±.060.243±.048.247±.061
ADNDCG.738±.042.755±.048.797±.044.803±.058.821±.056.835±.043.841±.041.847±.043.852±.048
ADMRR.612±.064.619±.057.645±.063.649±.052.660±.049.668±.059.674±.058.683±.066.688±.054

The results show that in terms of both metrics, the proposed HGT significantly and consistently outperforms all baselines for all tasks on all datasets. Take, for example, the Paper–Field (L1L_1) classification task on OAG, HGT achieves relative performance gains over baselines by 15%–19% in terms of NDCG and 18%–21% in terms of MRR (i.e., the performance gap divided by the baseline performance). When compared to HAN — the best baseline for most of the cases, the average relative NDCG improvements of HGT on the CS, Med and OAG datasets are 11%, 10% and 8%, respectively.

Overall, we observe that on average, HGT outperforms GCN, GAT, RGCN, HetGNN, and HAN by 20% for the four tasks on all three large-scale datasets. Moreover, HGT has fewer parameters and comparable batch time than all the heterogeneous graph neural network baselines, including RGCN, HetGNN, and HAN. This suggests that by modeling heterogeneous edges according to their meta relation schema, we are able to have better generalization with fewer resource consumption.

Ablation Study. The core component in HGT are the heterogeneous weight parameterization (Heter) and Relative Temporal Encoding (RTE). To further analyze their effects, we conduct an ablation study by removing them from HGT. Specifically, the model that removes heterogeneous weight parameterization, i.e., HGT(−Heter, +RTE), drops 4% of performance compared with the full model HGT(+Heter, +RTE). By removing RTE (i.e., HGT(+Heter, −RTE)), the performance has a 2% drop. The ablation study shows the significance of parameterizing with meta relations and using Relative Temporal Encoding.

In addition, we also try to implement a baseline that keeps a unique weight matrix for each relation. However, such a baseline contains too many parameters so that our experimental setting doesn’t have enough GPU memory to optimize it. This also indicates that using the meta relation to parameterize weight matrices can achieve competitive performance with fewer resources.

To further evaluate how Relative Temporal Encoding (RTE) can help HGT to capture graph dynamics, we conduct a case study showing the evolution of conference topic. We select 100 conferences in computer science with the highest citations, assign them three different timestamps, i.e., 2000, 2010 and 2020, and construct sub-graphs initialized by them. Using a trained HGT, we can get the representations for these conferences, with which we can calculate the euclidean distances between them. We select WWW, KDD, and NeurIPS as illustration. For each of them, we pick the top-5 most similar conferences (i.e., the one with the smallest euclidean distance) to show how the conference’s topics evolve over time.

As shown in Table 3, these venues’ relationships have changed from 2000 to 2020. For example, WWW in 2000 was more related to some database conferences, i.e., SIGMOD and VLDB, and some networking conferences, i.e., NSDI and GLOBECOM. However, WWW in 2020 would become more related to some data mining and information retrieval conferences (KDD, SIGIR, and WSDM), in addition to SIGMOD and GLOBECOM. Also, KDD in 2000 was more related to traditional database and data mining venues, while in 2020 it will tend to correlate with a variety of topics, i.e. machine learning (NeurIPS), database (SIGMOD), Web (WWW), AI (AAAI), and NLP (EMNLP). Additionally, our HGT model can capture the difference brought by new conferences. For example, NeurIPS in 2020 would relate with ICLR, which is a newly organized deep learning conference. This case study shows that the relative temporal encoding can help capture the temporal evolution of the heterogeneous academic graphs.

Table 3 — Temporal evolution of conference similarity.

VenueTimeTop-5 most similar venues
WWW2000SIGMOD, VLDB, NSDI, GLOBECOM, SIGIR
WWW2010GLOBECOM, KDD, CIKM, SIGIR, SIGMOD
WWW2020KDD, GLOBECOM, SIGIR, WSDM, SIGMOD
KDD2000SIGMOD, ICDE, ICDM, CIKM, VLDB
KDD2010ICDE, WWW, NeurIPS, SIGMOD, ICML
KDD2020NeurIPS, SIGMOD, WWW, AAAI, EMNLP
NeurIPS2000ICCV, ICML, ECCV, AAAI, CVPR
NeurIPS2010ICML, CVPR, ACL, KDD, AAAI
NeurIPS2020ICML, CVPR, ICLR, ICCV, ACL

To illustrate how the incorporated meta relation schema can benefit the heterogeneous message passing process, we pick the schema that has the largest attention value in each of the first two HGT layers and plot the meta relation attention hierarchy tree in Figure 4. For example, to calculate a paper’s representation,

  • ⟨Paper, is_published_at, Venue, is_published_at⁻¹, Paper⟩,
  • ⟨Paper, has_L2_field_of, Field, has_L5_field_of⁻¹, Paper⟩,
  • and ⟨Institute, is_affiliated_with⁻¹, Author, is_first_author_of, Paper⟩

are the three most important meta relation sequences, which can be regarded as meta paths PVP, PFP, and IAP, respectively. Note that these meta paths and their importance are automatically learned from the data without manual design. Another example of calculating an author node’s representation is shown on the right. Such visualization demonstrates that Heterogeneous Graph Transformer is capable of implicitly learning to construct important meta paths for specific downstream tasks, without manual customization.

Figure 4 — Hierarchy of the learned meta relation attention. (Source image not embedded: picture/meta2.png)

In this paper, we propose the Heterogeneous Graph Transformer (HGT) architecture for modeling Web-scale heterogeneous and dynamic graphs. To model heterogeneity, we use the meta relation ⟨τ(s),ϕ(e),τ(t)⟩\langle \tau(s), \phi(e), \tau(t) \rangle to decompose the interaction and transform matrices, enabling the model to have the similar modeling capacity with fewer resources. To capture graph dynamics, we present the relative temporal encoding (RTE) technique to incorporate temporal information using limited computational resources. To conduct efficient and scalable training of HGT on Web-scale data, we design the heterogeneous Mini-Batch graph sampling algorithm — HGSampling. We conduct comprehensive experiments on the Open Academic Graph, and show that the proposed HGT model can capture both heterogeneity and outperforms all the state-of-the-art GNN baselines on various downstream tasks.

In the future, we will explore whether HGT is able to generate heterogeneous graphs, e.g., predict new papers and their titles, and whether we can pre-train HGT to benefit tasks with scarce labels.

Acknowledgements. We would like to thank Xiaodong Liu for helpful discussions. This work is partially supported by NSF III-1705169, NSF CAREER Award 1741634, NSF #1937599, Okawa Foundation Grant, and Amazon Research Award.