Method and apparatus for performing a task with a graph transformer and training a graph transformer
The Multi-sequence attention Graph Transformer (MGT) overcomes the scalability limitations of existing graph transformers by representing graphs as short sequences and employing multi-sequence attention, achieving efficient processing of large graphs with reduced computational and memory costs.
Patent Information
- Application Number
- PCT/CN2023/119979
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Filing Date
- 2023-09-20
- Publication Date
- 2025-07-10
AI Technical Summary
Existing graph transformers (GTs) face scalability issues when dealing with large graphs due to the quadratic time and memory complexities of the full self-attention mechanism, limiting their application to small-scale graphs.
The Multi-sequence attention Graph Transformer (MGT) addresses scalability by representing the graph as multiple short node sequences and performing multi-sequence attention, which includes inter-sequence and intra-sequence attention mechanisms to efficiently handle large graphs.
The MGT framework significantly reduces computational costs and memory requirements, enabling effective processing of large graphs by linearly increasing context size without the burden of quadratic complexity, thus enhancing the scalability and expressiveness of graph transformers.
Smart Images

Figure CN2023119979_10072025_PF_FP_ABST
Abstract
Description
METHOD AND APPARATUS FOR PERFORMING A TASK WITH A GRAPH TRANSFORMER AND TRAINING A GRAPH TRANSFORMERFIELD
[0001] Aspects of the present disclosure relate generally to artificial intelligence, and more particularly, to performing a task using a graph transformer and training a graph transformer.BACKGROUND
[0002] Graph-structured data has been widely used in many real-world applications, such as social networks, biological networks, citation networks, internet of thing (IoT) network, recommendation system, financial system, transaction system, etc. Node classification is an exemplary task on graphs, node analysis is another exemplary task on graphs. Graph neural networks (GNNs) have been widely used to learn representations for graph-structured data. But the expressive power of GNNs is limited by message passing on graphs, which naturally introduces inductive biases.
[0003] The success of Transformer in natural language processing and computer vision have stimulated the passion for generalizing the transformer model to graphs. There have been successful graph transformers (GTs) which perform graph-level tasks on small-scale graphs, e.g., molecular graphs. However, the existing GTs only apply to small-scale graphs since the full self-attention in small graphs is computationally efficient, but the quadratic time and memory complexities of the full self-attention in GTs have prevented the existing GTs from scaling to large graphs for practical applications.SUMMARY
[0004] To address the above problems of the existing GNNs and GTs, the disclosure proposes a Multi-sequence attention Graph Transformer (MGT) that introduces strategies to help GTs address the scalability issue with powerful expressiveness.
[0005] According to an embodiment, there provides a computer implemented method for performing a task. The method comprises: obtaining a plurality of context nodes for a query node from a graph; obtaining a plurality of sequences based on the plurality of context nodes, wherein each of the plurality of sequences includes the query node and a subset of the plurality of context nodes; performing multi-sequence attention for the plurality of sequences to obtain multi-sequence attended feature map; obtaining a message passed feature map for the query node based on the multi-sequence attended feature map; and performing the task based on the message passed feature map of the query node.
[0006] According to an embodiment, there provides a computer implemented method for training a neural network (NN) model for performing a task. The method comprises: obtaining a plurality of context nodes for a query node from a graph; obtaining a plurality of sequences based on the plurality of context nodes, wherein each of the plurality of sequences includes the query node and a subset of the plurality of context nodes; performing multi-sequence attention for the plurality of sequences to obtain multi-sequence attended feature map; obtaining a message passed feature map for the query node based on the multi-sequence attended feature map; performing a prediction related to the task based on the message passed feature map of the query node; generating a first loss based on the prediction and a label of the query node; and updating the NN model based on the first loss.
[0007] According to an embodiment, there provides an apparatus for performing a task. The apparatus comprises: a sequence obtaining module configured for obtaining a plurality of context nodes for a query node from a graph, and obtaining a plurality of sequences based on the plurality of context nodes, wherein each of the plurality of sequences includes the query node and a subset of the plurality of context nodes; a graph transformer configured for performing multi-sequence attention for the plurality of sequences to obtain multi-sequence attended feature map, and obtaining a message passed feature map for the plurality of sequences based on the multi-sequence attended feature map; a task related predictor configured for receiving a message passed feature map for the query node obtained based on the message passed feature map for the plurality of sequences, and performing the task based on the message passed feature map of the query node.
[0008] According to an embodiment, there provides a computer system, which comprises one or more processors and one or more storage devices storing computer-executable instructions that, when executed, cause the one or more processors to perform the operations of the method as mentioned above as well as to perform the operations of the method according to aspects of the disclosure.
[0009] According to an embodiment, there provides one or more computer readable storage media storing computer-executable instructions that, when executed, cause one or more processors to perform the operations of the method as mentioned above as well as to perform the operations of the method according to aspects of the disclosure.
[0010] According to an embodiment, there provides a computer program product comprising computer-executable instructions that, when executed, cause one or more processors to perform the operations of the method as mentioned above as well as to perform the operations of the method according to aspects of the disclosure.
[0011] According to the proposed scalable MGT framework, the disclosure presents the graph structure as multiple short node sequences and performs the multi-sequence attention for the multiple short sequences, so as to alleviate the quadratic complexity of self-attention mechanism in existing graph transformer. To represent a graph as node sequences, the disclosure forms a set of short yet representative sequences for each query node as its context, rather than generating a long and redundant sequence. By limiting the sequence length, the context size can be increased by linearly increasing the number of sequences, overcoming the intolerant quadratic complexity of self-attention mechanism. Furthermore, the disclosure proposes a multi-sequence attention mechanism that can handle these sequences simultaneously, specifically the multi-sequence attention is achieved by a newly-designed inter-sequence attention across the multiple sequences and the intra-sequence attention in each sequence. Different from existing graph transformers operating on an individual sequence, the MGT framework interleaves attention within each of the multiple sequences and across the multiple sequences to extract node representations. By introducing the inter-sequence attention, the MGT framework is enabled with the multi-sequence attention in addition to the intra-sequence attention. Other advantages and enhancements are explained in the description hereafter.BRIEF DESCRIPTION OF THE DRAWINGS
[0012] The disclosed aspects will hereinafter be described in connection with the appended drawings that are provided to illustrate and not to limit the disclosed aspects.
[0013] Fig. 1 is a schematic block diagram illustrating an exemplary GT framework for performing a task according to aspects of the disclosure.
[0014] Fig. 2 is schematic diagram illustrating a simplified depiction of attention matrix of self-attention for a single-sequence according to aspects of the disclosure.
[0015] Fig. 3 is a schematic block diagram illustrating an exemplary MGT framework for performing a task according to aspects of the disclosure.
[0016] Figs. 4A to 4C are schematic diagrams illustrating a simplified depiction of attention matrixes of self-attention for multiple sequences according to aspects of the disclosure.
[0017] Figs. 5 and 6 are schematic block diagrams illustrating exemplary MGT frameworks for performing a task according to aspects of the disclosure.
[0018] Figs. 7 and 8 illustrates exemplary processes for training a NN model including the MGT according to aspects of the disclosure.
[0019] Fig. 9 is a schematic block diagram illustrating an exemplary apparatus for performing a task according to aspects of the disclosure.
[0020] Fig. 10 is a schematic block diagram illustrating an exemplary method for performing a task according to aspects of the disclosure.
[0021] Fig. 11 is a schematic block diagram illustrating an exemplary method for training a NN model according to aspects of the disclosure.
[0022] Fig. 12 is a schematic block diagram illustrating an exemplary computing system according to aspects of the disclosure.DETAILED DESCRIPTION
[0023] The present disclosure will now be discussed with reference to several example implementations. It is to be understood that these implementations are discussed only for enabling those skilled in the art to better understand and thus implement the embodiments of the present disclosure, rather than suggesting any limitations on the scope of the present disclosure.
[0024] Various embodiments will be described in detail with reference to the accompanying drawings. Wherever possible, the same reference numbers will be used throughout the drawings to refer to the same or like parts. References made to particular examples and embodiments are for illustrative purposes, and are not intended to limit the scope of the disclosure.
[0025] The present disclosure describes a method and a system, implemented as computer programs executed on one or more computers, which performs a task by using a graph transformer. As an example, the NN model including the graph transformer and the task related predictor may perform a machine learning task of classifying nodes in a graph, which may for example represents a social network, biological network, citation network, a transaction network recommendation system, financial system, an Internet of Thing (IoT) , etc. As an example, the NN model including the graph transformer and the task related predictor may perform a machine learning task of performing industrial analytics for nodes in a graph. For example, the industrial analytics may be a prediction of usage life of a device, a prediction of wear degree of a device, a prediction of an operation of a device in an IoT, etc., where the device is represented as a node in a graph including multiple nodes corresponding to multiple devices and edges among the nodes. The aspects of the disclosure may be applied in these fields such as the social network, biological network, citation network, recommendation system, financial system, IoT, smart manufacturing, industrial analytics and so on.
[0026] Fig. 1 is a schematic block diagram illustrating an exemplary GT framework for performing a task according to aspects of the disclosure.
[0027] A graph may be an input of the GT framework 100. The graph may be a dataset that contains nodes and edges. The nodes in the graph may represent entities, and the edges represent the connections between nodes. For example, a social network is a graph in which users or particularly user accounts in the network are nodes in the graph. An edge exists when two users are connected in some way. For example, the two users are friends, shares one’s posts, have similar interests, have similar profiles, or the like, then the two users may have a connection which is represented by the edge.
[0028] In an example, the graph may be formulated as G= (A, X) , where A∈ {0, 1} N×N represents the adjacency matrix of the graph G, X∈ {0, 1} N×D represents the feature matrix of the graph G, N is the number of nodes of graph G, D is the dimension of node feature. The adjacency matrix A may represent the connections among the nodes in the graph G, the feature matrix X may represent the features of respective nodes in the graph. The feature of a node may include multiple feature components, the number of which is defined as the dimension of the node feature. For example, for a graph of a social network, the feature components of a node may include age, gender, hobby, career, various actions such as shopping, reading, listening music, and so son. It is appreciated that aspects of the disclosure do not limited to specific values of the elements of the adjacency matrix and the feature matrix.
[0029] As illustrated in Fig. 1, for a query node vq, which may be an input of the GT framework 100, a context C consisting of a set of nodes C (vq) may be sampled from the graph. The set of nodes C (vq) may be referred to as context nodes of the query node vq. In the illustrated example, the context C includes nodes 1 to 12. Various node sampling methods may be utilized or combined for sampling the context nodes. In an embodiment, Personalized PageRank (PPR) and its variants such as Approximate-PPR (Daniel A Spielman and Shang-Hua Teng. A local clustering algorithm for massive graphs and its application to nearly linear time graph partitioning. SIAM Journal on computing, 42 (1) : 1–26, 2013) may be used to derive the context nodes from the graph. For example, the nodes with the top-M (M = 12 in the example of Fig. 1) highest PPR scores may be derived as context nodes C (vq) , i.e., |C (vq) |=M. In another embodiment, random walk method may be used to derive the context nodes from the graph. The random walk method tends to capture more distant neighbor nodes and accordingly capture long-distance dependence than the PPR method. In another embodiment, global sampling methods such as K-nearest neighbor nodes may be used to integrate nodes under different similarity measurements. It is appreciated that any suitable sampling method may be used to sample the context nodes for the query node from the graph.
[0030] A single sequence S may be formed with the query node and the context nodes. in the illustrated example, the sequence S includes the query node 0 and all the context nodes 1 to 12. It is appreciated that the length of the sequence S, i.e., the number of nodes of the sequence S, may be much larger than the illustrated length in a large scale graph. The sequence S may be input into a graph transformer (GT) T, which performs self-attention for the sequence S and output massage passed features MPF of the sequence. It is appreciated the self-attention process is known technique and there may be variants of self-attention methods and any suitable self-attention method or its variant may be used to perform the self-attention for the sequence S. A task related predictor P may perform a task based on the massage passed features MPF of the sequence.
[0031] Fig. 2 is schematic diagram illustrating a simplified depiction of attention scheme of a single-sequence method according to aspects of the disclosure. As illustrated in Fig. 2, taking the sequence S illustrated in Fig. 1 as an example, for the sequence S having 13 nodes, the feature matrix of the sequence S may be a 1×13 matrix where the dimension of the node feature is omitted for sake of simple depiction, that is to say, the sequence S may be simply represented as a 1×13 matrix. The attention matrix 210 of the self-attention for the sequence S may be a 13×13 matrix, where the label S-i (i = 1 to 13) represents the i-th node in the sequence. Then the attention matrix 210 is processed to obtain the attended sequence AS having the same size as the input sequence S. As the size of the attention matrix 210 is quadratic to the sequence size, the computation requirement, such as the computation time, the memory usage and so on, for the self-attention of the sequence S will increase quadratically as the length of the sequence S increases. Assuming there are Nc sampled nodes in total in the sequence S, the computation requirement or computation complexity may be meaning that the computation requirement is proportional to the square of the number of nodes. Accordingly, the quadratic time and memory complexity may limit the scalability of the GT framework 100 to large graph applications.
[0032] Fig. 3 is a schematic block diagram illustrating an exemplary MGT framework for performing a task according to aspects of the disclosure.
[0033] Taking the graph and the query node vq described with reference to Fig. 1 as an example, the graph and the query node vq may be input of the MGT framework 300. The context C consisting of a set of nodes C (vq) related to the query node vq may be sampled from the graph. The context nodes may be softly divided into nsdifferent sequences and each sequence contains nl nodes. There are Nc=nlns sampled nodes in total, and Nc may be used to denote the effective context size. In an embodiment, the above mentioned PPR and its variants such as Approximate-PPR may be used to derive the context nodes from the graph. For example, the nodes with the top-M (M ≥ nlns) highest PPR scores may be derived as context nodes C (vq) , i.e., |C (vq) |=M. In another embodiment, the abovementioned random walk method or the global sampling methods such as K-nearest neighbor nodes may be used to derive the context nodes from the graph. It is appreciated that any suitable sampling method may be used to sample the context nodes for the query node from the graph. Then, the ns sequences of length nl may be sampled from the context nodes C (vq) . In an embodiment, a soft split tactic may be used to balance node distribution in the graph. Particularly, fewer but more impactful neighbor nodes have a higher sampling probability, and each node appears once in a sequence but may appear in multiple sequences. It is appreciated that any suitable sampling method or splitting method may be used to construct the ns sequences.
[0034] To enable the query node vq to attend to all sampled nodes, the query node vq may be additionally added in each sequence In an embodiment, the query node vq may be additionally concatenated at the start of each sequence Then the sampled sequence may be denoted as: where denote the context nodes in the sequence. In the example illustrated in Fig. 3, a context C having 12 context nodes 1 to 12 may be sampled from the graph, and divided into ns=3 sequences of length nl=4. After adding the query node 0 into each sequence, multiple (ns=3) sequences S1, S2 and S3, each having multiple nodes (nl+1=5) , may be obtained.
[0035] The multiple sequences S1, S2 and S3 (ns=3) may be input into an MGT, which is a kind of GT. The MGT may include K transformer layers L1 to LK, which are denoted as MGT L (×K) in Fig. 3, where each MGT layer has similar structure. The feature map of the multiple sequences S1, S2 and S3 are processed in the first MGT layer L1 to obtain output feature map of the multiple sequences S1, S2 and S3. Then the output feature map of the multiple sequences S1, S2 and S3 from the layer L1 is used as the input of the next MGT layer L2. This process performs iteratively and the output feature map of the last MGT lay LK is used as the output of the MGT. The number K of the MGT layers may be larger than one in an embodiment. The number K of the MGT layers may be equal to one in another embodiment.
[0036] The ns node sequences of length nl+1 may be denoted as a sequence set S, i.e., for the query node vq. The input node feature map of the sequence set are extracted from the graph firstly. It is appreciated the term feature map may also be referred to as feature matrix. The input node feature map Xq may be mapped into hidden space using a linear projection and added with the positional encoding that is, the feature map of the ns sequences to be processed by the first MGT layer L1 is: H (0) =Linear (Xq) + P. In an embodiment, the positional encoding may be initialized as the pre-trained Node2vec (Aditya Grover and Jure Leskovec. node2vec: Scalable feature learning for networks. In KDD, pages 855–864, 2016) embedding on the whole graph G. It is appreciated that any existing or suitable positional encoding may be used to implement the positional encoding.
[0037] As illustrated in Fig. 3, the MGT L1 includes an Intra-Sequence Attention (IaSA) module to perform intra-sequence attention for each of the ns node sequences. In an embodiment, the intra-sequence attention for each of the ns node sequences may be implemented by performing self-attention within each node sequence. Any suitable self-attention method or its variant may be used to perform the self-attention.
[0038] Fig. 4A is schematic diagram illustrating a simplified depiction of attention scheme of a multiple-sequence method according to aspects of the disclosure. As illustrated in Fig. 4A, taking the sequences S1 to S3 illustrated in Fig. 3 as an example, for the sequences S1 to S3 each having 5 nodes, the attention matrixes 411 to 413 of the self-attention for the sequences S1 to S3 may be 5×5 matrixes, where the label RiCj (i = 1 to 3, j = 1 to 5) represents the j-th node in the i-th sequence. Then the attention matrixes 411 to 413 are processed to obtain the attended sequences AS1 to AS3 having the same size as the input sequences S1 to S3. Compared to the attention matrix 210 illustrated in Fig. 2, non-zero elements or non-zero sub-matrixes 411 to 413 in the 15×15 attention matrix 410 are restricted to diagonal blocks. Therefore, the computation requirement, such as the computation time, the memory usage and so on, for the self-attention of the ns sequences may be approximately meaning the computation requirement is proportional to context size Nc. In practical applications, for example, by limiting the sequence length nl to a small value (e.g., nl= 32) , the context size will be proportional to the number ns of sequences. Then the computational cost of self-attention for each and every of the sequences grows only linearly to the number ns of the sequences. In this way, the burden from the quadratic complexity as discussed with reference to Fig. 2 can be significantly reduced when increasing the context size.
[0039] Referring back to Fig. 3, taking the MGT L1 as example of MGT Li for description, the MGT L1 includes an Inter-Sequence Attention (IrSA) module to perform inter-sequence attention across the ns sequences. It is observed that the i-th row of sequence set or matrix S represents the i-th sequence and each column of the matrix S contains one sampled node of all the sequences. Based on this observation, the column of the matrix S may be treated as a special sequence, and the IrSA module may perform self-attention for each column, where the node can act as the anchor to incorporate information from other sequences to the sequence Therefore, in an embodiment, the inter-sequence attention across the multiple sentences may be implemented by performing the self-attention for each column of the node matrix consisting of the ns sequences as ns rows. Referring back to the above discussed embodiment, the feature map of the node matrix to be processed by the IaSA module and the IrSA module of the first MGT layer L1 is H (0) .
[0040] In each layer L of MGT, the IaSA module of the MGT L performs self-attention for each of the rows of the input feature map and the IrSA module of the MGT L performs self-attention for each of the columns of the input feature map where the superscript of the input feature map H (i) is omitted for sake of simplicity. The self-attention for the rows and the self-attention for the columns correspond respectively to the intra-sequence attention and the inter-sequence attention and are performed as shown in equation (1) .
[0041] where is the self-attention module, in which Wq, Wk and Wv are query matrix, key matrix and value matrix, which are learnable weighting matrixes. Hintra and Hinter are representations or feature maps containing intra-sequence information and inter-sequence information respectively.
[0042] Referring back to Fig. 4A, in the illustrated example, the feature map Hintra is the feature map of the attended sequences AS1 to AS3 illustrated in Fig. 4A.
[0043] Fig. 4B is schematic diagram illustrating a simplified depiction of attention scheme of a multiple-sequence method according to aspects of the disclosure. As illustrated in Fig. 4B, taking the sequences S1 to S3 illustrated in Fig. 3 as an example, for the sequence set or matrix S having sequences S1 to S3 as rows, the columns of the matrix node S are taken as special sequences SS1 to SS5. The attention matrixes 421 to 425 of the self-attention for the special sequences SS1 to SS5 may be 3×3 matrixes, where the label CjRi (i = 1 to 3, j = 1 to 5) represents the i-th node in the j-th special sequence, which is also the j-th node in the i-th sequence illustrated in Fig. 4A. Then the attention matrixes 421 to 425 are processed to obtain the attended special sequences ASS1 to ASS5 having the same size as the input special sequences SS1 to SS5.
[0044] As illustrated in Fig. 4C, the attention matrixes 421 to 425 are mapped from the matrix 420 to the matrix 410. Compared to the attention matrix 210 illustrated in Fig. 2, non-zero elements or non-zero sub-matrixes 421 to 425 are scattered in the 15×15 attention matrix 410. The computation requirement, such as the computation time, the memory usage and so on, for the self-attention of the (nl+1) special sequences may be approximately meaning the computation requirement is proportional to context size Nc. The attention matrixes 421 to 425 are illustrated together with the attention matrixes 411 to 413 in the matrix 410 as illustrated in Fig. 4C, the inter-sequence attention adds interaction between sequences and reduces the sparsity of the attention matrix 410 in the case of only perform intra-sequence attention as illustrated in Fig. 4A. Therefore, by using the multi-sequence attention including the intra-sequence attention for the multiple sequences and the inter-sequence attention across the multiple sequences in the embodiment of Fig. 3, the MGT may interleave attention within and across multiple sequences, so as to promotes message exchanging among all sampled nodes. The inter-sequence attention also brings additional computational costs. The overall time and memory complexity of MGT is that is, It is still very efficient compared to using a single sequence since small nl and ns can produce a large number of samples in the context C (vq) . Particularly, the time and memory complexity is much smaller than the time and memory complexity for the single sequence attention method as illustrated in Fig. 1 when the context size is large, allowing the MGT to be easier to scale to large graphs for practical applications.
[0045] Referring back to Fig. 3, the MGT L such as MGT L1 includes a gating module G.In an embodiment, the gating module G may implement node-wise gating to adaptively combine the intra-sequence attended feature map Hintra and the inter-sequence attended feature map Hinter . The gating module G packs the two feature maps in the node feature dimension and project them linearly to obtain the gate weight as shown in equation (2) : u=σ (Hintra, Hinter, Hintra -Hinter) (2)
[0046] where σ (□) =Sigmoid (□Wg) , is a learnable matrix.
[0047] The gate weights u output by the gating module G are applied to the inter-sequence attended feature map Hinter by means of dot production as illustrated in Fig. 3 to obtain the gated inter-sequence attended feature map u·Hinter, which is then added with the intra-sequence attended feature map Hintra to obtain the multi-sequence attended feature map Hintra +u·Hinter. It is observed that the intra-sequence attended feature map Hintra plays a more crucial role in prediction while the inter-sequence attended feature map Hinter serves as an auxiliary. Thereby the gating is only applied to the inter-sequence attended feature map Hinter to adaptively decide its contribution in the illustrated embodiment. Then, a feed-forward network (FFN) sub-layer FFN (□) =μ (□W1+□b1) □W2+b2 is applied to the multi- sequence attended feature map as shown in equation (3) . Hout=FFN (Hintra +u·Hinter) (3)
[0048] The output feature map Hout may be referred to as message passed feature map output by the MGT layer L. The message passed feature map Hout output by the first MGT layer L1 may be used as the input feature map of the next MGT layer L2, and similarly the message passed feature map Hout output by the i-th MGT layer Li may be used as the input feature map of the next MGT layer Li+1, where i is smaller than K, and the message passed feature map Hout output by the K-th MGT layer LK may be the final message passed feature map Hout of the MGT. The final message passed feature map Hout of the MGT includes ns rows corresponding to the ns sequences, and ns different representations of the query node may be obtained from the final message passed feature map Hout. In the illustrated example where the query node is placed at the first position of each sequence, the first item of each sequence is taken from the message passed feature map Hout to obtain ns different representations of the query node, which may be referred to as the message passed feature maps of the query node, for example, the h1, h2, h3 illustrated in Fig. 3.
[0049] Then the task related predictor P infers a task result based on each message passed feature maps hi of the query node. Then the ns predictions are ensembled to obtain the predicted result of the task. For example, the ns predictions are averaged to obtain the predicted result of the task. In an embodiment, the predictor may be implemented by a multi-layer perception (MLP) module and the task may be node classification. In an embodiment, the predictor may perform a machine learning task of performing industrial analytics for nodes in a graph. For example, the industrial analytics may be a prediction of usage life of a device, a prediction of wear degree of a device, a prediction of an operation of a device, etc., where the device is represented as a node in a graph including multiple nodes corresponding to multiple devices and edges among the nodes. The aspects of the disclosure may be applied in these fields such as the social network, biological network, citation network, IoT network, recommendation system, financial system, smart manufacturing, industrial analytics and so on.
[0050] Fig. 5 is a schematic block diagrams illustrating exemplary MGT framework for performing a task according to aspects of the disclosure.
[0051] Same labels in Fig. 5 denote same or corresponding elements illustrated in Fig. 3. The MGT framework 500 is different from MGT framework 300 in that MGT framework 500 does not include the gating module G of MGT framework 500. In other words, the inter-sequence attended feature map Hinter is added with the intra-sequence attended feature map Hintra to obtain the multi-sequence attended feature map Hintra +Hinter. Other parts of the MGT framework are same as that of Fig. 3 and are not described in detail.
[0052] Fig. 6 is a schematic block diagrams illustrating exemplary MGT framework for performing a task according to aspects of the disclosure.
[0053] Same labels in Fig. 6 denote same or corresponding elements illustrated in Figs. 3 and 5. The MGT framework 600 includes an MSA module, which obtains a message passed feature map for the plurality of sequences based on the plurality of sequences (e.g., S1 to S3) . The MSA module performs multi-sequence attention for the plurality of sequences to obtain multi-sequence attended feature map and obtains a message passed feature map for the plurality of sequences based on the multi-sequence attended feature map. In an embodiment, the MSA module may only perform intra-sequence attention for each of the plurality of sequences while not performing inter-sequence attention across the plurality of sequences. The intra-sequence attended feature map Hintra may be used as the multi-sequence attended feature map, which may be further processed by the MSA module (e.g., the FFN module of the MSA) to obtain the message passed feature map for the plurality of sequences. In an embodiment, MSA module may be implemented using the structure of Fig. 3, that is, the MSA module may include the IaSA module, the IrSA module, the Gating module G and the FFN module of MGT framework 300. In an embodiment, MSA module may be implemented using the structure of Fig. 5, that is, the MSA module may include the IaSA module, the IrSA module, and the FFN module of MGT framework 500. It is appreciated that the MSA module of MGT framework 600 may be implemented by using other suitable structures in other embodiments.
[0054] Fig. 7 illustrates an exemplary process for training a NN model including the MGT according to aspects of the disclosure.
[0055] Same labels in Fig. 7 denote same or corresponding elements illustrated in Figs. 3 and 5-6. The NN model 700 may be one of the MGT frameworks 300, 500 and 600. As described with reference to Figs. 3, 5-6, the task related predictor P infers a task result based on each message passed feature maps hi of the query node. Then the ns predictions are ensembled to obtain the predicted result of the task. During the training stage of the NN model 700, the ns predictions may be used to determine a supervised loss as shown in Equation (4) :
[0056] Where denotes the prediction of hi, denotes the label of the query node in the training dataset.
[0057] Then the supervised loss, which is shown as L1 in Fig. 7, is used to update the NN model 700. It is appreciated the supervised loss is commonly used loss for training NN models based on training data set. For example, the training data set may include the graph, the query node and annotated label of the query node. The known AdamW optimizer may be used to update the NN model 700 based on the loss.
[0058] Fig. 8 illustrates an exemplary process for training a NN model including the MGT according to aspects of the disclosure.
[0059] Same labels in Fig. 8 denote same or corresponding elements illustrated in Figs. 3 and 5-7. The NN model 800 may be one of the MGT frameworks 300, 500 and 600. As described with reference to Figs. 3, 5-6, Representation alignment. The ns sequences are all derived from the context C (vq) for the same query node vq. Hence their ns representations or feature maps all partly describe the semantic and structural characteristics of the context C (vq) . They are expected to be closer in the semantic feature space and make similar downstream predictions. Based on this observation, consistency between the ns representations may be encouraged to eliminate the effects of randomness from node sampling. Specifically, alignment of the representations in representation space may be enforced by optimizing the objective based on the alignment loss as shown in Equation (5) :
[0060] Where is the average of the ns representations sim (·, ·) denotes the similarity metric such as cosine similarity, for example, the similarity value lies in [-1, 1] .
[0061] As the larger capacity of the transformers than GNNs would increase the training difficulty, in the embodiment, the alignment loss may relieve the overfitting phenomenon in training and improve the generalization, thus promoting efficacy.
[0062] Then the supervised loss, which is shown as L1 in Fig. 8 or 7, and the alignment loss, which is shown as L2 in Fig. 8, are used to update the NN model 700. The known AdamW optimizer may be used to update the NN model 800 based on the loss. The two losses may be fused with a coefficient as shown in Equation (6) :
[0063] Fig. 9 is a schematic block diagram illustrating an exemplary apparatus for performing a task according to aspects of the disclosure.
[0064] The apparatus 900 includes a sequence obtaining module 910, a graph transformer 920, and a task related predictor 930. The sequence obtaining module 910 is configured for obtaining a plurality of context nodes for a query node from a graph, and obtaining a plurality of sequences based on the plurality of context nodes. Each of the plurality of sequences includes the query node and a subset of the plurality of context nodes. The graph transformer 920 is configured for performing multi-sequence attention for the plurality of sequences to obtain multi-sequence attended feature map, and obtaining a message passed feature map for the plurality of sequences based on the multi-sequence attended feature map. The task related predictor 930 is configured for receiving a message passed feature map for the query node obtained based on the message passed feature map for the plurality of sequences, and performing the task based on the message passed feature map of the query node.
[0065] In an embodiment, the graph transformer 920 may include an intra-sequence attention module and an inter-sequence attention module. The intra-sequence attention module is configured for performing intra-sequence attention for each of the plurality of sequences to obtain intra-sequence attended feature map for the plurality of sequences. The inter-sequence attention module is configured for performing inter-sequence attention across the plurality of sequences to obtain inter-sequence attended feature map for the plurality of sequences. And the graph transformer 920 is configured for obtaining the multi-sequence attended feature map based on the intra-sequence attended feature map and the inter-sequence attended feature map.
[0066] In an embodiment, the intra-sequence attention module is configured for performing the intra-sequence attention by performing self-attention for nodes in each of the plurality of sequences. The inter-sequence attention module is configured for performing inter-sequence attention by performing self-attention for nodes in each column of a matrix composed of the plurality of sequences, wherein each of the plurality of sequences being a row of the matrix, nodes at same positions of the plurality of sequences being a column of the matrix.
[0067] In an embodiment, the graph transformer 920 may include a gating module. the gating module is configured for performing gating to the inter-sequence attended feature map to obtain gated inter-sequence attended feature map. And the graph transformer 920 is configured for obtaining the multi-sequence attended feature map based on the intra-sequence attended feature map and the gated inter-sequence attended feature map. In an embodiment, the gating is a node-wise gating performed with a gating function, the gating function is configured to obtain gating weights for respective nodes of the plurality of sequences based on the intra-sequence attended feature map and the inter-sequence attended feature map.
[0068] In an embodiment, the apparatus 900 includes an extraction module configured for extracting the message passed feature map for the query node based on the message passed feature map for the plurality of sequences. In an embodiment, the query node is placed at a fixed position of each of the plurality of sequences, the extraction module extracts the message passed feature map for the query node based on the fixed position. In an embodiment, the fixed position is the first position of each of the plurality of sequences.
[0069] In an embodiment, the sequence obtaining module 910 is configured for obtaining the plurality of context nodes by using one of a Personalized PageRank (PPR) method, a random walk method and a K-nearest neighbors method based on the query node. In an embodiment, the sequence obtaining module 910 is configured for obtaining the plurality of sequences by softly distributing the plurality of context nodes into the plurality of sequences, wherein a single node can appear only once in one sequence but can appear in more than one sequence.
[0070] In an embodiment, the graph transformer 920 comprises K transformer layers, each layer performs the performing multi-sequence attention for the plurality of sequences and the obtaining a message passed feature map for the plurality of sequences iteratively, wherein the output of a transformer layer is used as the input of the next transformer layer, wherein K is more than one or K is one. The graph transformer 920 is configured for obtaining the message passed feature map for the query node based on the message passed feature map for the plurality of sequences output by the last one of the K transformer layers.
[0071] In an embodiment, the graph transformer 920 is configured for performing the multi-sequence attention based on an input feature map of the plurality of sequences, wherein the input feature map of the first one of the K transformer layers is obtained based on the graph features of the nodes of the plurality of sequences and positional encoding features of the nodes of the plurality of sequences, wherein the input feature map of the k-th one of the K transformer layers is the message passed feature map for the plurality of sequences output by the (k-1) -th one of the K transformer layers, wherein k is larger than one.
[0072] In an embodiment, the task related predictor 930 is configured for performing a prediction of a classification or analysis for the query node. It is appreciated that the task may be any industrial task that can be processed based on graph structured data, such as the exampled tasks in the above as well as other suitable tasks.
[0073] Fig. 10 is a schematic block diagram illustrating an exemplary computer implemented method for performing a task according to aspects of the disclosure.
[0074] At step 1010, a plurality of context nodes may be obtained for a query node from a graph.
[0075] At step 1020, a plurality of sequences may be obtained based on the plurality of context nodes, wherein each of the plurality of sequences includes the query node and a subset of the plurality of context nodes. In an embodiment, the query node is placed at a fixed position of each of the plurality of sequences, for example, the fixed position is the first position of each of the plurality of sequences.
[0076] At step 1030, multi-sequence attention for the plurality of sequences may be performed to obtain multi-sequence attended feature map.
[0077] At step 1040, a message passed feature map for the query node may be obtained based on the multi-sequence attended feature map.
[0078] At step 1050, the task may be performed based on the message passed feature map of the query node.
[0079] In an embodiment, at step 1030, intra-sequence attention for each of the plurality of sequences may be performed to obtain intra-sequence attended feature map for the plurality of sequences, inter-sequence attention across the plurality of sequences may be performed to obtain inter-sequence attended feature map for the plurality of sequences, and the multi-sequence attended feature map may be obtained based on the intra-sequence attended feature map and the inter-sequence attended feature map.
[0080] In an embodiment, at step 1030, the intra-sequence attention for each of the plurality of sequences may be performed by performing self-attention for nodes in each of the plurality of sequences, the inter-sequence attention across the plurality of sequences may be performed by performing self-attention for nodes in each column of a matrix composed of the plurality of sequences, wherein each of the plurality of sequences being a row of the matrix, nodes at same positions of the plurality of sequences being a column of the matrix.
[0081] In an embodiment, at step 1030, gating to the inter-sequence attended feature map may be performed to obtain gated inter-sequence attended feature map, and the multi-sequence attended feature map may be obtained based on the intra-sequence attended feature map and the gated inter-sequence attended feature map. In an embodiment, the gating is a node-wise gating performed with a gating function, the gating function is configured to obtain gating weights for respective nodes of the plurality of sequences based on the intra-sequence attended feature map and the inter-sequence attended feature map.
[0082] In an embodiment, at step 1040, a message passed feature map for the plurality of sequences may be obtained based on the multi-sequence attended feature map, and the message passed feature map for the query node may be obtained based on the message passed feature map for the plurality of sequences.
[0083] In an embodiment, at step 1010, the plurality of context nodes for the query node may be obtained from the graph by using one of a Personalized PageRank (PPR) method, a random walk method and a K-nearest neighbors method based on the query node.
[0084] In an embodiment, at step 1020, the plurality of sequences may be obtained by softly distributing the plurality of context nodes into the plurality of sequences, wherein a single node can appear only once in one sequence but can appear in more than one sequence.
[0085] In an embodiment, the method 1000 may be performed by using a neural network (NN) model including a graph transformer and a task related predictor.
[0086] In an embodiment, the graph transformer comprises K transformer layers, each layer performs the performing multi-sequence attention for the plurality of sequences and the obtaining a message passed feature map for the plurality of sequences iteratively, wherein the output of a transformer layer is used as the input of the next transformer layer, wherein K is more than one or K is one. At step 1040, the message passed feature map for the query node may be obtained based on the message passed feature map for the plurality of sequences output by the last one of the K transformer layers.
[0087] In an embodiment, at step 1030, the multi-sequence attention for the plurality of sequences may be performed based on an input feature map of the plurality of sequences, wherein the input feature map of the first one of the K transformer layers is obtained based on the graph features of the nodes of the plurality of sequences and positional encoding features of the nodes of the plurality of sequences, wherein the input feature map of the k-th one of the K transformer layers is the message passed feature map for the plurality of sequences output by the (k-1) -th one of the K transformer layers, wherein k is larger than one.
[0088] In an embodiment, at step 1050, a prediction of a classification or analysis for the query node may be performed as the task. In an embodiment, the graph representing one of a social network, a citation network, a transaction network, a financial network and an IoT network.
[0089] Fig. 11 is a schematic block diagram illustrating an exemplary computer implemented method for training a NN model according to aspects of the disclosure.
[0090] At step 1110, a plurality of context nodes for a query node may be obtained from a graph.
[0091] At step 1120, a plurality of sequences may be obtained based on the plurality of context nodes, wherein each of the plurality of sequences includes the query node and a subset of the plurality of context nodes.
[0092] At step 1130, multi-sequence attention for the plurality of sequences may be performed to obtain multi-sequence attended feature map.
[0093] At step 1140, a message passed feature map for the query node may be obtained based on the multi-sequence attended feature map.
[0094] At step 1150, a prediction related to the task may be performed based on the message passed feature map of the query node.
[0095] At step 1160, a first loss may be generated based on the prediction and a label of the query node.
[0096] At step 1170, the NN model may be updated based on the first loss.
[0097] In an embodiment, at step 1160, a second loss may be generated based on the message passed feature map for the query node. At step 1170, the NN model may be updated based on the first loss and the second loss. The first loss may be the supervised loss illustrated in Figs. 7 and 8, and the second loss may be the alignment loss illustrated in Fig. 8.
[0098] Fig. 12 is a schematic block diagram illustrating an exemplary computing system according to aspects of the disclosure. The computing system 1200 may comprise at least one processor 1210. The computing system 1200 may further comprise at least one storage device 1220. The storage device 1220 may store computer-executable instructions that, when executed, cause the processor 1210 to perform any operations according to the embodiments of the present disclosure as described in connection with Figs. 1-11.
[0099] The embodiments of the present disclosure may be embodied in a computer-readable medium such as non-transitory computer-readable medium. The non-transitory computer-readable medium may comprise instructions that, when executed, cause one or more processors to perform any operations according to the embodiments of the present disclosure as described in connection with Figs. 1-11.
[0100] The embodiments of the present disclosure may be embodied in a computer program product comprising computer-executable instructions that, when executed, cause one or more processors to perform any operations according to the embodiments of the present disclosure as described in connection with Figs. 1-11.
[0101] It should be appreciated that all the operations in the methods described above are merely exemplary, and the present disclosure is not limited to any operations in the methods or sequence orders of these operations, and should cover all other equivalents under the same or similar concepts.
[0102] It should also be appreciated that all the modules in the apparatuses described above may be implemented in various approaches. These modules may be implemented as hardware, software, or a combination thereof. Moreover, any of these modules may be further functionally divided into sub-modules or combined together.
[0103] The previous description is provided to enable any person skilled in the art to practice the various aspects described herein. Various modifications to these aspects will be readily apparent to those skilled in the art, and the generic principles defined herein may be applied to other aspects. Thus, the claims are not intended to be limited to the aspects shown herein. All structural and functional equivalents to the elements of the various aspects described throughout the present disclosure that are known or later come to be known to those of ordinary skill in the art are expressly incorporated herein by reference and are intended to be encompassed by the claims.
Claims
1.A computer implemented method for performing a task, comprising:obtaining a plurality of context nodes for a query node from a graph;obtaining a plurality of sequences based on the plurality of context nodes, wherein each of the plurality of sequences includes the query node and a subset of the plurality of context nodes;performing multi-sequence attention for the plurality of sequences to obtain multi-sequence attended feature map;obtaining a message passed feature map for the query node based on the multi-sequence attended feature map; andperforming the task based on the message passed feature map of the query node.2.The method of claim 1, wherein the performing multi-sequence attention for the plurality of sequences comprising:performing intra-sequence attention for each of the plurality of sequences to obtain intra-sequence attended feature map for the plurality of sequences;performing inter-sequence attention across the plurality of sequences to obtain inter-sequence attended feature map for the plurality of sequences;obtaining the multi-sequence attended feature map based on the intra-sequence attended feature map and the inter-sequence attended feature map.3.The method of claim 2, wherein the performing intra-sequence attention for each of the plurality of sequences comprising: performing self-attention for nodes in each of the plurality of sequences;wherein the performing inter-sequence attention across the plurality of sequences comprising: performing self-attention for nodes in each column of a matrix composed of the plurality of sequences, wherein each of the plurality of sequences being a row of the matrix, nodes at same positions of the plurality of sequences being a column of the matrix.4.The method of claim 2, wherein the obtaining the multi-sequence attended feature map comprising:performing gating to the inter-sequence attended feature map to obtain gated inter-sequence attended feature map;obtaining the multi-sequence attended feature map based on the intra-sequence attended feature map and the gated inter-sequence attended feature map.5.The method of claim 4, wherein the gating is a node-wise gating performed with a gating function, the gating function is configured to obtain gating weights for respective nodes of the plurality of sequences based on the intra-sequence attended feature map and the inter-sequence attended feature map.6.The method of claim 1, wherein the obtaining a message passed feature map for the query node comprising:obtaining a message passed feature map for the plurality of sequences based on the multi-sequence attended feature map;obtaining the message passed feature map for the query node based on the message passed feature map for the plurality of sequences.7.The method of claim 1, wherein the obtaining a plurality of context nodes for a query node from a graph comprising: obtaining the plurality of context nodes by using one of a Personalized PageRank (PPR) method, a random walk method and a K-nearest neighbors method based on the query node.8.The method of claim 1, wherein the query node is placed at a fixed position of each of the plurality of sequences.9.The method of claim 1, wherein the method is performed by using a neural network (NN) model including a graph transformer and a task related predictor.10.The method of claim 6, wherein the graph transformer comprises K transformer layers, each layer performs the performing multi-sequence attention for the plurality of sequences and the obtaining a message passed feature map for the plurality of sequences iteratively, wherein the output of a transformer layer is used as the input of the next transformer layer, wherein K is more than one or K is one,wherein the obtaining the message passed feature map for the query node based on the message passed feature map for the plurality of sequences comprising: obtaining the message passed feature map for the query node based on the message passed feature map for the plurality of sequences output by the last one of the K transformer layers.11.The method of claim 10, wherein the performing multi-sequence attention for the plurality of sequences comprising: performing the multi-sequence attention based on an input feature map of the plurality of sequences, wherein the input feature map of the first one of the K transformer layers is obtained based on the graph features of the nodes of the plurality of sequences and positional encoding features of the nodes of the plurality of sequences, wherein the input feature map of the k-th one of the K transformer layers is the message passed feature map for the plurality of sequences output by the (k-1) -th one of the K transformer layers, wherein k is larger than one.12.The method of claim 1, wherein the performing the task comprising: performing a prediction of a classification or analysis for the query node.13.The method of claim 1, wherein the graph representing one of a social network, a citation network, a transaction network, a financial network, and an Internet of Thing (IoT) network.14.A computer implemented method for training a NN model for performing a task, comprising:obtaining a plurality of context nodes for a query node from a graph;obtaining a plurality of sequences based on the plurality of context nodes, wherein each of the plurality of sequences includes the query node and a subset of the plurality of context nodes;performing multi-sequence attention for the plurality of sequences to obtain multi-sequence attended feature map;obtaining a message passed feature map for the query node based on the multi-sequence attended feature map;performing a prediction related to the task based on the message passed feature map of the query node;generating a first loss based on the prediction and a label of the query node; andupdating the NN model based on the first loss.15.The method of claim 14, further comprising:generating a second loss based on the message passed feature map for the query node; andupdating the NN model based on the first loss and the second loss.16.An apparatus for performing a task, comprising:a sequence obtaining module configured for obtaining a plurality of context nodes for a query node from a graph, and obtaining a plurality of sequences based on the plurality of context nodes, wherein each of the plurality of sequences includes the query node and a subset of the plurality of context nodes;a graph transformer configured for performing multi-sequence attention for the plurality of sequences to obtain multi-sequence attended feature map, and obtaining a message passed feature map for the plurality of sequences based on the multi-sequence attended feature map;a task related predictor configured for receiving a message passed feature map for the query node obtained based on the message passed feature map for the plurality of sequences, and performing the task based on the message passed feature map of the query node.17.A computer system, comprising:one or more processors; andone or more storage devices storing computer-executable instructions that, when executed, cause the one or more processors to perform the operations of the method of one of claims 1-15.18.One or more computer readable storage media storing computer-executable instructions that, when executed, cause one or more processors to perform the operations of the method of one of claims 1-15.