Graph data learning method and device based on small sample prompt learning and medium
By constructing graph data templates and task templates, heterogeneous graphs are converted into isomorphic graphs, and the pre-trained model is modified using double-layer prompts, the high cost and low efficiency problems of fine-tuning large-scale pre-trained models in the existing technology are solved, and the high cost and low efficiency problems of fine-tuning large-scale pre-trained models are realized. More efficient graph data learning.
Patent Information
- Application Number
- CN202411598341.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-11
- Publication Date
- 2025-02-18
AI Technical Summary
The prior art requires a large number of task-specific labels when fine-tuning large pretrained models, and the data format and samples are always changing, resulting in the model needing to be retrained from start to finish, which is costly and inefficient.
The graph data learning method based on small sample prompt learning is adopted. By constructing graph data templates and task templates, heterogeneous graphs are converted into isoform graphs, and the pre-trained model is modified using double-layer prompts to reduce learning costs and calculation overhead.
It improves the learning efficiency of the model, reduces the dependence on large amounts of label data, can effectively handle the complexity of heterogeneous graphs, and performs well in different tasks.
Smart Images

Figure CN119474467A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of small sample pre-training, and in particular to a graph data learning method, device and medium based on small sample prompt learning. Background Art
[0002] Graph-structured data, as unstructured data, is ubiquitous in real-world scenarios because it can model the relationships between objects, such as campus network nodes, chemical interaction graphs, and social networks. In particular, real-world graph data often involves multiple types of nodes and edges, such as authors, papers, and conferences interacting in various ways in a bibliographic network. These graphs are called heterogeneous graphs or heterogeneous information networks, in contrast to traditional homogeneous graphs that consist of only one type of nodes and edges.
[0003] Pre-training and fine-tuning of models have become a practical alternative to supervised learning. First, the pre-training step exploits unlabeled graphs to learn general, task-independent properties on homogeneous or heterogeneous graphs. Next, the fine-tuning step updates the pre-trained model to adapt it to the downstream task using some task-specific labels. Obviously, these two steps optimize different objectives, creating a gap between pre-training and downstream tasks, which further leads to poor performance. In addition, fine-tuning large pre-trained models can be costly and still requires a large number of task-specific labels to avoid overfitting.
[0004] To address the fine-tuning problem, hint-based learning has gained widespread attention due to its performance. Hint learning aims to extract semantic relevance between downstream tasks and pre-trained models, acting as a bridge to align downstream objectives with pre-trained models. Under this approach, the parameters of the pre-trained model are frozen, and only a lightweight, task-specific hint vector is tuned for the downstream task. Given that there are far fewer learnable parameters in hints than in pre-trained models, hint tuning can be both efficient and effective, especially in few-shot tasks where task-specific labels are very scarce.
[0005] Therefore, the existing technology has the following shortcomings: 1. The existing data learning model requires a large amount of labeled data, and the data collection and labeling work in real scenarios requires a lot of manpower and time costs; 2. The form and samples of data are always changing, and the existing models are trained based on static complete data. If new training data is added, the model needs to be trained from beginning to end. Summary of the invention
[0006] In order to overcome the above technical defects, the present invention provides a graph data learning method, device and medium based on small sample prompt learning, which can improve the learning efficiency of the model.
[0007] In order to solve the above problems, the present invention is implemented according to the following technical solutions:
[0008] A graph data learning method based on small sample prompt learning includes the following steps:
[0009] Build a graph data template to unify the input graph data;
[0010] Build task templates. Based on the graph data template, convert different tasks into similarity calculations between prediction subgraphs to implement the tasks of the graph data template.
[0011] Predict the category label of the sub-image;
[0012] Perform pre-training of the loss function for subgraph similarity and output the model weights of the homogeneous graph GNN / heterogeneous graph HGNN;
[0013] The pre-trained model g(.) is modified using a two-layer prompt.
[0014] As a further improvement of the present invention, the step of constructing the graph data template includes:
[0015] Convert a heterogeneous graph into multiple homogeneous graphs based on node types;
[0016] The isomorphic graph g is merged with multiple isomorphic graphs to obtain the graph data template.
[0017] As a further improvement of the present invention, the heterogeneous graph is defined as Among them, V is the node set, E is the edge set, A is the node type set, R is the edge type set, the node type mapping function Φ: V→A assigns each node to a type in A, and the edge type mapping function E→R assigns each edge to a type in R;
[0018] The step of converting the heterogeneous graph into multiple isomorphic graphs according to the node types to obtain a group of isomorphic graphs includes:
[0019] Assume a node type i∈A and extract a homogeneous subgraph G from the heterogeneous graph G i =(V i , E i ), where V i ={v∈V|Φ(v)=i},E i ={(a, b)∈E|a∈V i ∧b∈V i};
[0020] Transform the heterogeneous graph G into a set of homogeneous graphs {G i :i∈A}.
[0021] As a further improvement of the present invention, the step of merging the isomorphic graph with multiple isomorphic graphs to obtain the graph data template includes:
[0022] Define a homogeneous graph G 0 =(V, E);
[0023] The isomorphic graph G 0 With multiple isomorphic graphs {G i :i∈A} are combined to obtain the graph data template:
[0024] GT(G)=G 0 ∪{G i :i∈A}.
[0025] As a further improvement of the present invention, the step of constructing a task template and converting different tasks into similarities between predicted subgraphs based on the graph data template includes:
[0026] For node-level tasks, each node v is instantiated as a subgraph;
[0027] The embedding vector S of the subgraph v If they are isomorphic, perform a READOUT operation on the subgraph;
[0028] The embedding vector S of the subgraph v If the graph data template GT(S v ) After obtaining several isomorphic graphs, perform READOUT operations on several isomorphic graphs and aggregate them into AGG (S v );
[0029] The node-level task is transformed into predicting the similarity between subgraphs.
[0030] As a further improvement of the present invention, the step of predicting the category label of the sub-graph includes:
[0031] For link prediction tasks, node classification tasks, and graph classification tasks, similarity functions are used to predict the category labels of subgraphs.
[0032] As a further improvement of the present invention, the step of pre-training the loss function of subgraph similarity includes:
[0033] Self-supervised datasets using triplets from pre-trained graphs as loss function.
[0034] As a further improvement of the present invention, the step of modifying the pre-trained model using the double-layer prompt includes:
[0035] Adopt heterogeneous graph hints to modify the aggregation layer input;
[0036] The lightweight hint vector is adjusted while the model weights remain frozen.
[0037] The present invention also provides a computer device, comprising a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other via the communication bus;
[0038] The memory is used to store computer programs;
[0039] The processor is used to implement the above-mentioned graph data learning method when executing the program stored in the memory.
[0040] The present invention also provides one or more computer-readable media having instructions stored thereon, which, when executed by one or more processors, enable the processors to perform the above-mentioned graph data learning method.
[0041] Compared with the prior art, the present invention provides the following beneficial effects: the present invention establishes dual unified templates for isomorphic graphs and heterogeneous graphs and constructs a double-layer prompt framework strategy, thereby improving the learning model of graph data and reducing learning costs and computational overhead. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] Figure 1 The present invention is a flowchart of the graph data learning method. DETAILED DESCRIPTION
[0043] The preferred embodiments of the present invention are described below in conjunction with the accompanying drawings. It should be understood that the preferred embodiments described herein are only used to illustrate and explain the present invention, and are not used to limit the present invention.
[0044] Example 1
[0045] This embodiment provides a graph data learning method based on small sample prompt learning, such as Figure 1 As shown, the steps include:
[0046] S1. Build a graph data template to unify the input graph data to ensure that all subsequent operations are performed under a unified graph data structure, providing a basis for subsequent tasks and subgraph similarity calculations.
[0047] In the specific implementation process, the input graph data includes: heterogeneous graphs and homogeneous graphs; the heterogeneous graph is defined as Among them, V is the node set, E is the edge set, A is the node type set, R is the edge type set, the node type mapping function Φ: V→A assigns each node to a type in A, and the edge type mapping function E→R assigns each edge to a type in R; the sets A and R must satisfy |A|+|R|>2, which means there are multiple node and / or edge types. In addition, the input feature matrix of the node is recorded as X∈R |v|×d , where |V| is the number of nodes and d is the dimension of the feature space.
[0048] A homogeneous graph is a special case of a heterogeneous graph, with the same definition, but |A| = |R| = 1, meaning there is only one node type and one edge type. Heterogeneous graphs are more complex than homogeneous graphs, with multiple types of nodes and edges, and are suitable for data representing diverse and rich relationships; whereas homogeneous graphs are simpler, with only one type of nodes and edges, and are suitable for more uniform data. Heterogeneous graphs are often used in social networks, biological networks, and recommendation systems, where different types of entities and relationships need to be modeled. Homogeneous graphs are often used for simpler network structures, such as basic social networks or molecular structures with uniform relationships.
[0049] Specifically, this embodiment implements the construction of the graph data template through the following steps:
[0050] S11. Heterogeneous graph According to the node type conversion to multiple isomorphic graphs, first, set a node type i∈A, extract an isomorphic subgraph G from the heterogeneous graph G i =(V i , E i ), where V i ={v∈V|Φ(v)=i},E i ={(a, b)∈E|a∈V i ∧b∈V i}; Secondly, transform the heterogeneous graph G into a set of homogeneous graphs {G i :i∈A}.
[0051] V represents a node set; E represents an edge set; A represents a set of node types; R represents a set of edge types; Φ represents a node type mapping function, which maps each node v to a type i, i.e., Φ(v) = i; represents the edge type mapping function, which assigns each edge to a type in the set R;
[0052] S12. Merge the isomorphic graph g with multiple isomorphic graphs to obtain a graph data template, where each isomorphic graph retains a portion of the heterogeneity. In order to retain the interactions between different types, first, define an isomorphic graph G 0 =(V, E); i.e. isomorphic graph G 0 The complete topological structure of the heterogeneous graph G is retained, but the type is not distinguished; then, the process of converting the heterogeneous graph into |A|+1 isomorphic graphs is called graph data template. 0 With multiple isomorphic graphs {Gi :i∈A} merge to get the graph data template GT: GT(G)=G 0 ∪{G i :i∈A}.
[0053] The graph data template unifies the downstream heterogeneous graphs into a homogeneous graph format that may be used in pre-training. When heterogeneous graphs exist in pre-training, the same graph data template can also be applied to these heterogeneous graphs. Through the above steps, the complexity of heterogeneous graphs can be effectively processed and utilized while maintaining their topological structure and the relationship between types, thereby improving the performance of the model in different tasks.
[0054] S2. Build task templates. Based on the graph data template, convert different tasks into similarities between predicted subgraphs. This step converts specific tasks (such as link prediction, node classification, graph classification, etc.) into a similarity calculation problem that can be processed in a unified manner, which is consistent with the unification of the graph data template and ensures that all tasks are performed under a similar framework.
[0055] For node-level tasks such as link prediction (LP) and node classification (NC), each node v is instantiated as a subgraph A common strategy is to use breadth-first search to extract a δ-hop subgraph centered on node v. For the graph classification (GC) task, since its instance is already in the form of a graph, i.e. Directly use the graph instance, that is, the heterogeneous graph G.
[0056] For example, the embedding vector S of subgraph S v If they are isomorphic, perform a READOUT operation on the subgraph;
[0057] For example, the embedding vector S of subgraph S v If the graph data template GT(S v ) After obtaining several isomorphic graphs, perform READOUT operations on several isomorphic graphs and aggregate them into AGG (S v );
[0058]
[0059] in, Represents subgraph S v The READOUT layer of subgraph S is further defined as the aggregation of node features:
[0060] The node-level task is transformed into predicting the similarity between subgraphs:
[0061] READOUT(S)=AGG2({h υ |υ∈V(S)}),
[0062] where hυ represents the embedding of node υ before the READOUT layer, It is a subgraph Then, these three types of tasks (node-level tasks and graph-level tasks) can be reformulated as predicting the similarity between (sub)graph instances.
[0063] S3, based on the task template framework of step S2, predicts the category label of the subgraph and generates the prediction result of the model. It is a reasonable extension immediately following the task template, including three types of tasks: link prediction task, node classification task, and graph classification task.
[0064] 1. For link prediction (LP), given a subgraph S and a node triple (υ, a, b), where (υ, a) is an edge in the graph G, and (υ, b) is not an edge in the graph. This embodiment expects where sim(·,·) is a similarity function, such as cosine similarity.
[0065] 2. For node classification (NC), given a subgraph S and a set of node categories C, and a labeled node set D = {(v1, l1), (v2, l2), ...}, where l i is node v i In the case of k-times learning, each category There are exactly k pairs. (v i , l i =c)∈D For a category C, a node category prototype is constructed, which can be understood as a "virtual" subgraph. Its embedding vector is expressed as Then, for an unlabeled node v j , whose category label is l j It can be predicted as:
[0066]
[0067] 2. For graph classification (GC), given a graph G (homomorphic or heterogeneous) and a set of node categories C, and a labeled graph set D = {(G1, L1), (G2, L2), ...}, where L i It is Figure G i In the case of k-times learning, each category There are exactly k pairs (G i , L i =c)∈D. For a category C, this embodiment also defines a graph category prototype, which is expressed as Then, for an unlabeled graph G j , whose category label is L j It can be predicted as:
[0068]
[0069] Among them, through Represents the embedding representation or feature representation of the i-th subgraph in the graph G. The above method can unify different tasks and use similarity functions and prototype embeddings to predict the category labels of nodes or graphs. This method is not only suitable for link prediction, node classification, and graph classification tasks, but also can effectively learn and predict with a small number of samples.
[0070] S4. Perform pre-training of the loss function for subgraph similarity and output the model weights of the homogeneous graph GNN / heterogeneous graph HGNN. Specifically, pre-training is performed using the Link Prediction (LP) task. In large graph data, abundant links can serve as the basis for self-supervision. This embodiment uses triples to guide the calculation of subgraph similarity, i.e. Based on task templates.
[0071] Typically, several triplets are collected from the pre-trained graph as a self-supervised dataset The pre-training loss function is defined as follows:
[0072]
[0073] Among them, τ is a temperature hyperparameter, Θ represents the model weight of homogeneous graph GNN / heterogeneous graph HGNN. The pre-training stage outputs the trained model weight, that is, These weights will be used in subsequent downstream tasks.
[0074] Step S4 uses the Link Prediction (LP) task to pre-train the model's similarity metric, which is then used for similarity calculations of category predictions in the previous step. Link prediction can provide the model with more training samples and self-supervised learning signals, helping the model to have more accurate representations when learning similarities between graphs and nodes.
[0075] The correlation between step S4 and the annotation of the previous steps lies in the continuity and hierarchical relationship of the tasks. Steps S1 to S3 perform node and graph category prediction, aiming to classify nodes or subgraphs through similarity function sim(·,·) and category annotation. The purpose of step S4 is to pre-train the loss function of graph similarity, which is a more detailed optimization of the model of the previous steps, providing a basis for training the model and ensuring that the model has strong generalization ability and accuracy in similarity calculation.
[0076] S5. Modify the pre-trained model g(.) using dual-layer prompts to narrow the gap caused by task differences and heterogeneity. Specifically, different tasks may focus on different features or different aspects of heterogeneity in the input graph. Therefore, this embodiment proposes dual prompts, including feature prompts for handling feature changes and heterogeneity prompts for handling heterogeneity differences in different tasks.
[0077] Heterogeneous graphs hint at methods for modifying the input to the aggregation layer. Represents a learnable vector for a specific task, serving as a heterogeneous hint for the task. The hint vector has |A|+1 dimensions, where each dimension It aims to weight the i-th subgraph in the graph template GT(·). After applying the graph template, for a subgraph The aggregation layer becomes: This means embedding the subgraph S into a vector S v Generate. Learnable vector p hct Is task specific, each subgraph can be adjusted according to the nature of the task The importance of each subgraph is given by This means that different subgraphs will have different importance in the aggregation process. Each subgraph is processed using the READOUT operation and weighted according to the prompt vector to obtain the embedding vector of the subgraph. This method can dynamically adjust the importance of different subgraphs in a heterogeneous graph, and is particularly suitable for scenarios where feature extraction and weight assignment are required according to specific tasks, such as node classification, link prediction, and graph embedding in neural networks. The method of adjusting the input of the aggregation layer through heterogeneous graph prompts makes it more flexible to adjust the importance of each subgraph according to task requirements when processing complex heterogeneous graphs, thereby improving task performance.
[0078] S22 Method for adjusting dual prompts in downstream tasks. In order to adjust the dual prompts, a loss function based on subgraph similarity is used for pre-training. Suppose in a node classification or graph classification task, there is a labeled training set where each x i is a node or graph, y i ∈Y is x i The class labels in the class set Y. Then, the tip-adjusted loss is defined as:
[0079]
[0080] Among them, the embedding vectors of sub-graphs and category prototypes are is based on the hint vector p feat and p hctDuring cue adaptation, only the lightweight cue vector is adjusted, while the pre-trained weights Θ0 remain frozen without any fine-tuning. This parameter-efficient adaptation method is suitable for scenarios with fewer training examples, such as The case with only a small number of training examples.
[0081] Example 2
[0082] Based on the same inventive concept, this embodiment provides a computer device, including a memory, a processor, and a computer program stored in the memory, wherein the processor executes the computer program to load the liquidation method as described in any one of the embodiments of the present invention.
[0083] Specifically, the computer device includes: a memory and a processor. The memory and the processor are connected via a bus communication. A computer program is stored in the memory. The computer program can be run on the processor to load the graph data learning method in Example 1 of the present invention.
[0084] The memory may include a random access memory (RAM) or a non-volatile memory, such as at least one disk memory. Optionally, the memory may also be at least one storage device located away from the aforementioned processor.
[0085] The above-mentioned processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.
[0086] Example 3
[0087] Based on the same inventive concept, another embodiment of the present invention provides a computer-readable storage medium having a computer program / instruction stored thereon, which loads the liquidation method of the present invention when executed by a processor.
[0088] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.
[0089] Those skilled in the art will appreciate that embodiments of the present invention may be provided as methods, devices, electronic devices, storage media or computer program products. Therefore, embodiments of the present invention may take the form of complete hardware embodiments, complete software embodiments, or embodiments combining software and hardware. Moreover, embodiments of the present invention may take the form of computer program products implemented on one or more computer-usable storage media (including but not limited to disk storage, CDROM, optical storage, etc.) containing computer-usable program codes.
[0090] The above are only preferred embodiments of the present application and are not intended to limit the present application. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present application should be included in the protection scope of the present application.
Claims
1. A graph data learning method based on small sample prompt learning, characterized in that: Includes steps: Build a graph data template to unify the input graph data; Build task templates. Based on the graph data template, convert different tasks into similarity calculations between prediction subgraphs to implement the tasks of the graph data template. Predict the category label of the sub-image; Perform pre-training of the loss function for subgraph similarity and output the model weights of the homogeneous graph GNN / heterogeneous graph HGNN; The pre-trained model is modified with two-layer prompts.
2. The graph data learning method according to claim 1, characterized in that: The step of constructing the graph data template includes: Convert a heterogeneous graph into multiple homogeneous graphs based on node types; The isomorphic graph g is merged with multiple isomorphic graphs to obtain the graph data template.
3. The graph data learning method according to claim 2, characterized in that: Define a heterogeneous graph as Among them, V is the node set, E is the edge set, A is the node type set, R is the edge type set, the node type mapping function Φ: V→A assigns each node to a type in A, and the edge type mapping function Assign each edge to a type in R; The step of converting the heterogeneous graph into multiple isomorphic graphs according to the node types to obtain a group of isomorphic graphs includes: Assume a node type i∈A and extract a homogeneous subgraph G from the heterogeneous graph G i =(V i , E i ), where V i ={v∈V|Φ(v)=i},E i ={(a, b)∈E|a∈V i ∧b∈V i }; Transform the heterogeneous graph G into a set of homogeneous graphs {G i :i∈A}.
4. The graph data learning method according to claim 3, characterized in that: The step of merging the isomorphic graph with a plurality of isomorphic graphs to obtain the graph data template comprises: Define a homogeneous graph G 0 =(V, E); The isomorphic graph G 1 With multiple isomorphic graphs {G i :i∈A} are combined to obtain the graph data template: GT(G)=G 0 ∪{G i :i∈A}。 5. The graph data learning method according to claim 3, characterized in that: The step of constructing a task template and converting different tasks into similarities between predicted subgraphs based on the graph data template includes: For node-level tasks, each node v is instantiated as a subgraph; The embedding vector S of the subgraph v If they are isomorphic, perform a READOUT operation on the subgraph; The embedding vector S of the subgraph v If the graph data template GT(S v ) After obtaining several isomorphic graphs, perform READOUT operations on several isomorphic graphs and aggregate them into AGG (S v ); The node-level task is transformed into predicting the similarity between subgraphs.
6. The graph data learning method according to claim 1, characterized in that: The step of predicting the category label of the sub-graph includes: For link prediction tasks, node classification tasks, and graph classification tasks, similarity functions are used to predict the category labels of subgraphs.
7. The graph data learning method according to claim 1, characterized in that: The step of pre-training the loss function for subgraph similarity includes: Self-supervised datasets using triplets from pre-trained graphs as loss function.
8. The graph data learning method according to claim 1, characterized in that: The step of modifying the pre-trained model using the double-layer prompt includes: Adopt heterogeneous graph cues to modify the aggregation layer input; The lightweight hint vector is adjusted while the model weights remain frozen.
9. A computer device, characterized in that: It includes a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other through the communication bus; The memory is used to store computer programs; The processor is used to implement the graph data learning method as described in any one of claims 1 to 8 when executing the program stored in the memory.
10. One or more computer-readable media having instructions stored thereon, which, when executed by one or more processors, enable the processors to perform the graph data learning method as described in any one of claims 1-8.