SlowGuess/NeurIPS_2023_OCR huggingface dataset:
Zhaocheng Zhu $^{1,2,*}$ , Xinyu Yuan $^{1,2,*}$ , Mikhail Galkin $^{3,\dagger}$ , Sophie Zhonneux $^{1,2}$ , Ming Zhang $^{4}$ , Maxime Gazeau $^{5}$ , Jian Tang $^{1,6,7}$
<sup>1</sup>Mila - Québec AI Institute, <sup>2</sup>University of Montréal
<sup>3</sup>Intel AI Lab, <sup>4</sup>Peking University, <sup>5</sup>LG Electronics AI Lab
$^{6}$ HEC Montréal, CIFAR AI Chair
Reasoning on large-scale knowledge graphs has been long dominated by embedding methods. While path-based methods possess the inductive capacity that embeddings lack, their scalability is limited by the exponential number of paths. Here we present A*Net, a scalable path-based method for knowledge graph reasoning. Inspired by the A* algorithm for shortest path problems, our A*Net learns a priority function to select important nodes and edges at each iteration, to reduce time and memory footprint for both training and inference. The ratio of selected nodes and edges can be specified to trade off between performance and efficiency. Experiments on both transductive and inductive knowledge graph reasoning benchmarks show that A*Net achieves competitive performance with existing state-of-the-art path-based methods, while merely visiting  $10\%$  nodes and  $10\%$  edges at each iteration. On a million-scale dataset ogbl-wikikg2, A*Net not only achieves a new state-of-the-art result, but also converges faster than embedding methods. A*Net is the first path-based method for knowledge graph reasoning at such scale.
Reasoning, the ability to apply logic to draw new conclusions from existing facts, has been long pursued as a goal of artificial intelligence [32, 20]. Knowledge graphs encapsulate facts in relational edges between entities, and serve as a foundation for reasoning. Reasoning over knowledge graphs is usually studied in the form of knowledge graph completion, where a model is asked to predict missing triplets based on observed triplets in the knowledge graph. Such a task can be used to not only populate existing knowledge graphs, but also improve downstream applications like multi-hop logical reasoning [34], question answering [5] and recommender systems [53].
One challenge central to knowledge graph reasoning is the scalability of reasoning methods, as many real-world knowledge graphs [2, 44] contain millions of entities and
Figure 1: Validation MRR w.r.t. training time on ogbl-wikikg2 (1 A100 GPU). A*Net achieves state-of-the-art performance and the fastest convergence.
triplets. Typically, large-scale knowledge graph reasoning is solved by embedding methods [6, 42, 38], which learn an embedding for each entity and relation to reconstruct the structure of the knowledge
*Equal contribution. Code is available at https://github.com/DeepGraphLearning/ASstarNet
†Work done while at Mila - Québec AI Institute.
(a) Path-based reasoning
(b) Exhaustive search
Figure 2: (a) Given a query  $(a, Mother, ?)$ , only a few important paths (showed in red) are necessary for reasoning. Note that paths can go in the reverse direction of relations. (b) Exhaustive search algorithm (e.g., Path-RNN, PathCon) enumerates all paths in exponential time. (c) Bellman-Ford algorithm (e.g., NeuralLP, DRUM, NBFNet, RED-GNN) computes all paths in polynomial time, but needs to propagate through all nodes and edges. (d) A*Net learns a priority function to select a subset of nodes and edges at each iteration, and avoids exploring all nodes and edges.
(c) Bellman-Ford
(d)  $\mathbf{A}^*$
graph. Due to its simplicity, embedding methods have become the de facto standard for knowledge graphs with millions of entities and triplets. With the help of multi-GPU embedding systems [57, 56], they can further scale to knowledge graphs with billions of triplets.
Another stream of works, path-based methods [28, 31, 11, 58], predicts the relation between a pair of entities based on the paths between them. Take the knowledge graph in Fig. 2(a) as an example, we can prove that  $\text{Mother}(a, f)$  holds, because there are two paths  $a \xrightarrow{\text{Father}} b \xrightarrow{\text{Wife}} f$  and  $a \xleftarrow{\text{Brother}} c \xrightarrow{\text{Mother}} f$ . As the semantics of paths are purely determined by relations rather than entities, path-based methods naturally generalize to unseen entities (i.e., inductive setting), which cannot be handled by embedding methods. However, the number of paths grows exponentially w.r.t. the path length, which hinders the application of path-based methods on large-scale knowledge graphs.
Here we propose A*Net to tackle the scalability issue of path-based methods. The key idea of our method is to search for important paths rather than use all possible paths for reasoning, thereby reducing time and memory in training and inference. Inspired by the A* algorithm [22] for shortest path problems, given a head entity  $u$  and a query relation  $q$ , we compute a priority score for each entity to guide the search towards more important paths. At each iteration, we select  $K$  nodes and  $L$  edges according to their priority, and use message passing to update nodes in their neighborhood. Due to the complex semantics of knowledge graphs, it is hard to use a handcrafted priority function like the A* algorithm without a significant performance drop (Tab. 6a). Instead, we design a neural priority function based on the node representations at the current iteration, which can be end-to-end trained by the objective function of the reasoning task without any additional supervision.
We verify our method on 4 transductive and 2 inductive knowledge graph reasoning datasets. Experiments show that A*Net achieves competitive performance against state-of-the-art path-based methods on FB15k-237, WN18RR and YAGO3-10, even with only  $10\%$  of nodes and  $10\%$  edges at each iteration (Sec. 4.2). To verify the scalability of our method, we also evaluate A*Net on ogbl-wikikg2, a million-scale knowledge graph that is 2 magnitudes larger than datasets solved by previous path-based methods. Surprisingly, with only  $0.2\%$  nodes and  $0.2\%$  edges, our method outperforms existing embedding methods and establishes new state-of-the-art results (Sec. 4.2) as the first non-embedding method on ogbl-wikikg2. By adjusting the ratios of selected nodes and edges, one can trade off between performance and efficiency (Sec. 4.3). A*Net also converges significantly faster than embedding methods (Fig. 1), which makes it a promising model for deployment on large-scale knowledge graphs. Additionally, A*Net offers interpretability that embeddings do not possess. Visualization shows that A*Net captures important paths for reasoning (Sec. 4.4).
Knowledge Graph Reasoning A knowledge graph  $\mathcal{G} = (\mathcal{V},\mathcal{E},\mathcal{R})$  consists of sets of entities (nodes)  $\mathcal{V}$ , facts (edges)  $\mathcal{E}$  and relation types  $\mathcal{R}$ . Each fact is a triplet  $(x,r,y)\in \mathcal{V}\times \mathcal{R}\times \mathcal{V}$ , which indicates a relation  $r$  from entity  $x$  to entity  $y$ . The task of knowledge graph reasoning aims at answering queries like  $(u,q,?)$  or  $(?,q,u)$ . Without loss of generality, we assume the query is
$(u,q,?)$ , since  $(?,q,u)$  equals to  $(u,q^{-1},?)$  with  $q^{-1}$  being the inverse of  $q$ . Given a query  $(u,q,?)$ , we need to predict the answer set  $\mathcal{V}_{(u,q,?)}$ , such that  $\forall v \in \mathcal{V}_{(u,q,?)}$  the triplet  $(u,q,v)$  should be true.
Path-based Methods Path-based methods [28, 31, 11, 58] solve knowledge graph reasoning by looking at the paths between a pair of entities in a knowledge graph. For example, a path  $a \xrightarrow{Father} b \xrightarrow{Wife} f$  may be used to predict Mother $(a, f)$  in Fig. 2(a). From a representation learning perspective, path-based methods aim to learn a representation  $h_q(u, v)$  to predict the triplet  $(u, q, v)$  based on all paths  $\mathcal{P}_{u \rightsquigarrow v}$  from entity  $u$  to entity  $v$ . Following the notation in [58] $^3$ ,  $h_q(u, v)$  is defined as
$$
\boldsymbol {h} _ {q} (u, v) = \bigoplus_ {P \in \mathcal {P} _ {u \sim v}} \boldsymbol {h} _ {q} (P) = \bigoplus_ {P \in \mathcal {P} _ {u \sim v}} \bigotimes_ {(x, r, y) \in P} \boldsymbol {w} _ {q} (x, r, y) \tag {1}
$$
where  $\bigoplus$  is a permutation-invariant aggregation function over paths (e.g., sum or max),  $\otimes$  is an aggregation function over edges that may be permutation-sensitive (e.g., matrix multiplication) and  $\pmb{w}_q(x,r,y)$  is the representation of triplet  $(x,r,y)$  conditioned on the query relation  $q$ .  $\bigotimes$  is computed before  $\bigoplus$ . Typically,  $\pmb{w}_q(x,r,y)$  is designed to be independent of the entities  $x$  and  $y$ , which enables path-based methods to generalize to the inductive setting. However, it is intractable to compute Eqn. 1, since the number of paths usually grows exponentially w.r.t. the path length.
Path-based Reasoning with Bellman-Ford algorithm To reduce the time complexity of path-based methods, recent works [50, 35, 58, 54] borrow the Bellman-Ford algorithm [4] from shortest path problems to solve path-based methods. Instead of enumerating each possible path, the Bellman-Ford algorithm iteratively propagates the representations of  $t - 1$  hops to compute the representations of  $t$  hops, which achieves a polynomial time complexity. Formally, let  $h_q^{(t)}(u,v)$  be the representation of  $t$  hops. The Bellman-Ford algorithm can be written as
$$
\boldsymbol {h} _ {q} ^ {(0)} (u, v) \leftarrow \mathbb {1} _ {q} (u = v) \tag {2}
$$
$$
\boldsymbol {h} _ {q} ^ {(t)} (u, v) \leftarrow \boldsymbol {h} _ {q} ^ {(0)} (u, v) \oplus \bigoplus_ {(x, r, v) \in \mathcal {E} (v)} \boldsymbol {h} _ {q} ^ {(t - 1)} (u, x) \otimes \boldsymbol {w} _ {q} (x, r, v) \tag {3}
$$
where  $\mathbb{1}_q$  is a learnable indicator function that defines the representations of 0 hops  $h_q^{(0)}(u,v)$ , also known as the boundary condition of the Bellman-Ford algorithm.  $\mathcal{E}(v)$  is the neighborhood of node  $v$ . Despite the polynomial time complexity achieved by the Bellman-Ford algorithm, Eqn. 3 still needs to visit  $|\mathcal{V}|$  nodes and  $|\mathcal{E}|$  edges to compute  $h_q^{(t)}(u,v)$  for all  $v \in \mathcal{V}$  in each iteration, which is not feasible for large-scale knowledge graphs.
A* Algorithm A* algorithm [22] is an extension of the Bellman-Ford algorithm for shortest path problems. Unlike the Bellman-Ford algorithm that propagates through every node uniformly, the A* algorithm prioritizes propagation through nodes with higher priority according to a heuristic function specified by the user. With an appropriate heuristic function, A* algorithm can reduce the search space of paths. Formally, with the notation from Eqn. 1, the priority function for node  $x$  is
$$
s (x) = d (u, x) \otimes g (x, v) \tag {4}
$$
where  $d(u, x)$  is the length of current shortest path from  $u$  to  $x$ , and  $g(x, v)$  is a heuristic function estimating the cost from  $x$  to the target node  $v$ . For instance, for a grid-world shortest path problem (Fig. 4(a)),  $g(x, v)$  is usually defined as the  $L_{1}$  distance from  $x$  to  $v$ ,  $\otimes$  is the addition operator, and  $s(x)$  is a lower bound for the shortest path length from  $u$  to  $v$  through  $x$ . During each iteration, the  $\mathrm{A}^*$  algorithm prioritizes propagation through nodes with smaller  $s(x)$ .
We propose A*Net to scale up path-based methods with the A* algorithm. We show that the A* algorithm can be derived from the observation that only a small set of paths are important for reasoning (Sec. 3.1). Since it is hard to handcraft a good priority function for knowledge graph reasoning (Tab. 6a), we design a neural priority function, and train it end-to-end for reasoning (Sec. 3.2).
$^3 \oplus$  and  $\otimes$  are binary operations (akin to  $+$ ,  $\times$ ), while  $\oplus$  and  $\otimes$  are n-ary operations (akin to  $\sum$ ,  $\prod$ ).
3.1 Path-based Reasoning with  $\mathbf{A}^*$  Algorithm
As discussed in Sec. 2, the Bellman-Ford algorithm visits all  $|\mathcal{V}|$  nodes and  $|\mathcal{E}|$  edges. However, in real-world knowledge graphs, only a small portion of paths is related to the query. Based on this observation, we introduce the concept of important paths. We then show that the representations of important paths can be iteratively computed with the  $\mathrm{A}^*$  algorithm under mild assumptions.
Important Paths for Reasoning Given a query relation and a pair of entities, only some of the paths between the entities are important for answering the query. Consider the example in Fig. 2(a), the path  $a \xrightarrow{Friend} d \xrightarrow{Mother} e \xrightarrow{Friend} f$  cannot determine whether  $f$  is an answer to  $Mother(a, ?)$  due to the use of the Friend relation in the path. On the other hand, kinship paths like  $a \xrightarrow{Father} b \xrightarrow{Wife} f$  or  $a \xleftarrow{Brother} c \xrightarrow{Mother} f$  are able to predict that  $Mother(a, f)$  is true. Formally, we define  $\mathcal{P}_{u \sim v|q} \subseteq \mathcal{P}_{u \sim v}$  to be the set of paths from  $u$  to  $v$  that is important to the query relation  $q$ . Mathematically, we have
$$
\boldsymbol {h} _ {q} (u, v) = \bigoplus_ {P \in \mathcal {P} _ {u \sim v}} \boldsymbol {h} _ {q} (P) \approx \bigoplus_ {P \in \mathcal {P} _ {u \sim v | q}} \boldsymbol {h} _ {q} (P) \tag {5}
$$
In other words, any path  $P \in \mathcal{P}_{u \rightsquigarrow v} \setminus \mathcal{P}_{u \rightsquigarrow v|q}$  has negligible contribution to  $h_q(u, v)$ . In real-world knowledge graphs, the number of important paths  $|\mathcal{P}_{u \rightsquigarrow v|q}|$  may be several orders of magnitudes smaller than the number of paths  $|\mathcal{P}_{u \rightsquigarrow v}|$  [11]. If we compute the representation  $h_q(u, v)$  using only the important paths, we can scale up path-based reasoning to large-scale knowledge graphs.
Iterative Computation of Important Paths Given a query  $(u,q,?)$ , we need to discover the set of important paths  $\mathcal{P}_{u\rightsquigarrow v|q}$  for all  $v\in \mathcal{V}$ . However, it is challenging to extract important paths from  $\mathcal{P}_{u\rightsquigarrow v}$  since the size of  $\mathcal{P}_{u\rightsquigarrow v}$  is exponentially large. Our solution is to explore the structure of important paths and compute them iteratively. We first show that we can cover important paths with iterative path selection (Eqn. 6 and 7). Then we approximate iterative path selection with iterative node selection (Eqn. 8).
Notice that paths in  $\mathcal{P}_{u\sim v}$  form a tree structure (Fig. 3). On the tree, a path is not important if any
Figure 3: The colored paths are important paths  $\mathcal{P}_{u\rightsquigarrow v|q}$ , while the solid paths are the superset  $\hat{\mathcal{P}}_{u\rightsquigarrow v|q}$  used in Eqn. 7.
prefix of this path is not important for the query. For example, in Fig. 2(a),  $a \xrightarrow{Friend} d \xrightarrow{Mother} e \xrightarrow{Friend} f$  is not important, as its prefix  $a \xrightarrow{Friend} d$  is not important for the query Mother. Therefore, we assume there exists a path selection function  $m_q: 2^{\mathcal{P}} \mapsto 2^{\mathcal{P}}$  that selects important paths from a set of paths given the query relation  $q$ .  $2^{\mathcal{P}}$  is the set of all subsets of  $\mathcal{P}$ . With  $m_q$ , we construct the following set of paths  $\hat{\mathcal{P}}_{u \rightsquigarrow v|q}^{(t)}$  iteratively
$$
\hat {\mathcal {P}} _ {u \rightsquigarrow v | q} ^ {(0)} \leftarrow \{(u, \text {s e l f l o o p}, v) \} \text {i f} u = v \text {e l s e} \varnothing \tag {6}
$$
$$
\hat {\mathcal {P}} _ {u \sim v | q} ^ {(t)} \leftarrow \bigcup_ {\substack {x \in \mathcal {V} \\ (x, r, v) \in \mathcal {E} (v)}} \left\{P + \{(x, r, v) \} \Bigg | P \in m _ {q} \left(\hat {\mathcal {P}} _ {u \sim v | q} ^ {(t - 1)}\right) \right\} \tag{7}
$$
where  $P + \{(x,r,v)\}$  concatenates the path  $P$  and the edge  $(x,r,v)$ . The paths  $\hat{\mathcal{P}}_{u\rightsquigarrow v|q}^{(t)}$  computed by the above iteration is a superset of the important paths  $\mathcal{P}_{u\rightsquigarrow v|q}^{(t)}$  of length  $t$  (see Thm. A.1 in App. A). Due to the tree structure of paths, the above iterative path selection still requires exponential time. Hence we further approximate iterative path selection with iterative node selection, by assuming paths with the same length and the same stop node can be merged. The iterative node selection replacing Eqn. 7 is (see Prop. A.3 in App. A)
$$
\hat {\mathcal {P}} _ {u \rightsquigarrow v | q} ^ {(t)} \leftarrow \bigcup_ {\substack {x \in n _ {u q} ^ {(t - 1)} (\mathcal {V})\\(x, r, v) \in \mathcal {E} (v)}} \left\{P + \{(x, r, v) \} \Big | P \in \hat {\mathcal {P}} _ {u \rightsquigarrow x | q} ^ {(t - 1)} \right\} \tag{8}
$$
where  $n_{uq}^{(t)}:2^{\nu}\mapsto 2^{\nu}$  selects ending nodes of important paths of length  $t$  from a set of nodes.
Reasoning with A* Algorithm Eqn. 8 iteratively computes the set of important paths  $\hat{\mathcal{P}}_{u\sim v|q}$ . In order to perform reasoning, we need to compute the representation  $h_q(u,v)$  based on the important paths, which can be achieved by an iterative process similar to Eqn. 8 (see Thm. A.4 in App. A)
$$
\boldsymbol {h} _ {q} ^ {(t)} (u, v) \leftarrow \boldsymbol {h} _ {q} ^ {(0)} (u, v) \oplus \bigoplus_ {\substack {x \in n _ {u q} ^ {(t - 1)} (\mathcal {V}) \\ (x, r, v) \in \mathcal {E} (v)}} \boldsymbol {h} _ {q} ^ {(t - 1)} (u, x) \otimes \boldsymbol {w} _ {q} (x, r, v) \tag{9}
$$
Eqn. 9 is the  $\mathbf{A}^*$  iteration (Fig. 2(d)) for path-based reasoning. Note the  $\mathbf{A}^*$  iteration uses the same boundary condition as Eqn. 2. Inspired by the classical  $\mathbf{A}^*$  algorithm, we parameterize  $n_{uq}^{(t)}(\mathcal{V})$  with a node priority function  $s_{uq}^{(t)}: \mathcal{V} \mapsto [0,1]$  and select top- $K$  nodes based on their priority. However, there does not exist an oracle for the priority function  $s_{uq}^{(t)}(x)$ . We will discuss how to learn the priority function  $s_{uq}^{(t)}(x)$  in the following sections.
3.2 Path-based Reasoning with A*Net
Both the performance and the efficiency of the  $\mathrm{A}^*$  algorithm heavily rely on the heuristic function. While it is straightforward to use  $L_{1}$  distance as the heuristic function for grid-world shortest path problems, it is not clear what a good priority function for knowledge graph reasoning is due to the complex relation semantics in knowledge graphs. Indeed, our experiments suggest that handcrafted priority functions largely hurt the performance of path-based methods (Tab. 6a). In this section, we discuss a neural priority function, which can be end-to-end trained by the reasoning task.
Neural Priority Function To design the neural priority function  $s_{uq}(x)$ , we draw inspiration from the priority function in the A* algorithm for shortest path problems (Eqn. 4). The priority function has two terms  $d(u, x)$  and  $g(x, v)$ , where  $d(u, x)$  is the current distance from node  $u$  to  $x$ , and  $g(x, v)$  estimates the remaining distance from node  $x$  to  $v$ .
(a)  $\mathbf{A}^*$  algorithm in a grid world
(b) A*Net on a knowledge graph
Figure 4: (a) A* algorithm computes the current distance  $d(u, x)$  (blue), estimates the remaining distance  $g(x, v)$  (orange), and prioritizes shorter paths. (b) A*Net computes the current representations  $h_q^{(t)}(u, x)$  (blue), estimates the remaining representations  $g([h_q^{(t)}(u, x), q])$  (orange) based on the query  $q$  (green), and prioritizes paths more relevant to the query.
From a representation learning perspective, we need to learn a representation  $s_{uq}(x)$  to predict the priority score  $s_{uq}(x)$  for each node  $x$ . Inspired by Eqn. 4, we use the current representation  $\pmb{h}_q^{(t)}(u,x)$  to represent  $d^{(t)}(u,x)$ . However, it is challenging to find a representation for  $g^{(t)}(x,v)$ , since we do not know the answer entity  $v$  beforehand. Noticing that in the A* algorithm, the target node  $v$  can be expressed by the source node plus a displacement (Fig. 4(a)), we reparameterize the answer entity  $v$  with the head entity  $u$  and the query relation  $q$  in A*Net. By replacing  $g^{(t)}(x,v)$  with another function  $g^{(t)}(u,x,q)$ , the representation  $s_{uq}(x)$  is parameterized as
$$
\boldsymbol {s} _ {u q} ^ {(t)} (x) = \boldsymbol {h} _ {q} ^ {(t)} (u, x) \otimes \boldsymbol {g} ([ \boldsymbol {h} _ {q} ^ {(t)} (u, x), \boldsymbol {q} ]) \tag {10}
$$
where  $g(\cdot)$  is a feed-forward network that outputs a vector representation and  $[\cdot, \cdot]$  concatenates two representations. Intuitively, the learned representation  $q$  captures the semantic of query relation  $q$ , which serves the goal for answering query  $(u, q, ?)$ . The function  $g([\pmb{h}_q^{(t)}(u, x), \pmb{q}])$  compares the current representation  $h_q^{(t)}(u, x)$  with the goal  $q$  to estimate the remaining representation (Fig. 4(b)). If  $h_q^{(t)}(u, x)$  is close to  $q$ , the remaining representation will be close to 0, and  $x$  is likely to be close to the correct answer. The final priority score is predicted by
$$
s _ {u q} ^ {(t)} (x) = \sigma \left(f \left(s _ {u q} ^ {(t)} (x)\right)\right) \tag {11}
$$
where  $f(\cdot)$  is a feed-forward network and  $\sigma$  is the sigmoid function that maps the output to [0, 1].
Learning To learn the neural priority function, we incorporate it as a weight for each message in the  $\mathbf{A}^*$  iteration. For simplicity, let  $\mathcal{X}^{(t)} = n_{uq}^{(t - 1)}(\mathcal{V})$  be the nodes we try to propagate through at  $t$ -th iteration. We modify Eqn. 9 to be
$$
\boldsymbol {h} _ {q} ^ {(t)} (u, v) \leftarrow \boldsymbol {h} _ {q} ^ {(0)} (u, v) \oplus \bigoplus_ {\substack {x \in \mathcal {X} ^ {(t)} \\ (x, r, v) \in \mathcal {E} (v)}} s _ {u q} ^ {(t - 1)} (x) \left(\boldsymbol {h} _ {q} ^ {(t - 1)} (u, x) \otimes \boldsymbol {w} _ {q} (x, r, v)\right) \tag{12}
$$
Eqn. 12 encourages the model to learn larger weights  $s_{uq}^{(t)}(x)$  for nodes that are important for reasoning. In practice, as some nodes may have very large degrees, we further select top-  $L$  edges from the neighborhood of  $n_{uq}^{(t - 1)}(\mathcal{V})$  (see App. B). A pseudo code of A*Net is illustrated in Alg. 1. Note the top-  $K$  and top-  $L$  functions are not differentiable.
Nevertheless, it is still too challenging to train the neural priority function, since we do not know the ground truth for important paths, and there is no direct supervision for the priority function. Our solution is to share the weights between the priority function and the predictor for the reasoning task. The intuition is that the reasoning task can be viewed as a weak supervision for the priority function. Recall that the goal of  $s_{uq}^{(t)}(x)$  is to determine whether there exists an important path from  $u$  to  $x$  (Eqn. 8). In the reasoning task, any positive answer entity must be present on at least one important path, while negative answer entities are less likely to be on important paths. Our ablation experiment demonstrates that sharing weights improve the performance of neural priority function (Tab. 6b). Following [38], A*Net is trained to minimize the binary cross entropy loss over triplets
$$
\mathcal {L} = - \log p (u, q, v) - \sum_ {i = 1} ^ {n} \frac {1}{n} \log \left(1 - p \left(u _ {i} ^ {\prime}, q, v _ {i} ^ {\prime}\right)\right) \tag {13}
$$
where  $(u,q,v)$  is a positive sample and  $\{(u_i',q,v_i')\}_{i=1}^n$  are negative samples. Each negative sample  $(u_i,q,v_i)$  is generated by corrupting the head or the tail in a positive sample.
Efficient Implementation with Padding-Free Operations Modern neural networks heavily rely on batched execution to unleash the parallel capacity of GPUs. While Alg. 1 is easy to implement for a single sample  $(u, q, ?)$ , it is not trivial to batch A*Net for multiple samples. The challenge is that different samples may have very different sizes for nodes  $\mathcal{V}^{(t)}$  and edges  $\mathcal{E}^{(t)}$ . A common approach is to pad the set of nodes or edges to a predefined constant, which would severely counteract the acceleration brought by A*Net.