Comparison learning method for improving graph encoder distribution external generalization ability

Through the positive sample matching module and the Mixup adjustment module, combined with the graph isomorphic network and the improved contrast loss function, the problem of insufficient generalization ability of the graph neural network under different data distributions is solved, and the robust feature representation and adaptability improvement in the out-of-distribution scenarios are achieved.

CN120373400APending Publication Date: 2025-07-25TIANJIN UNIV
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202510319425.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-03-18
Publication Date
2025-07-25

AI Technical Summary

Technical Problem

When the existing graph neural network model faces changes in graph attributes and structures under different data distributions, it is difficult to maintain robust generalization capabilities. Especially when the attribute characteristics and topological structure of graph data undergo significant changes, the existing methods have shortcomings in cross-environmental adaptability and information fusion.

Method used

The positive sample matching module and the Mixup adjustment module are used to combine dynamic data enhancement and improved contrast loss objective function, feature encoding is performed through the graph isomorphic network, positive sample pairs of different environment labels of the same task are constructed, and mixed learning is performed in the feature space to optimize the generalization performance of the graph encoder.

Benefits of technology

It significantly improves the feature learning ability of graph encoder in out-of-distribution generalization scenarios, improves the robustness and adaptability of the model in different environments, and can generate excellent graph feature representations for downstream tasks.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120373400A_ABST
    Figure CN120373400A_ABST
Patent Text Reader

Abstract

The invention belongs to the field of graph data analysis and out-of-distribution generalization, and discloses a comparative learning method for improving out-of-distribution generalization ability of a graph encoder. By designing a positive sample matching module, consistency of data pairs from different environment distributions but with the same label in a feature space is established, and the defect that environment information cannot be utilized in a traditional comparative learning method is effectively overcome; through a Mixup adjusting module, the problem that a graph encoder is difficult to train at the initial stage of training is effectively relieved by adopting a sectional learning concept; and finally, through a redesigned contrast loss target, the graph encoder can still extract excellent feature vectors for good generalization performance of downstream tasks in a generalization scene outside distribution. The two modules and one optimization target are trained based on an optimization strategy designed by the invention, and excellent concepts of a contrast learning framework are reserved while environment distribution information is utilized to the greatest extent.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of graph data analysis and out-of-distribution generalization, and relates to a contrastive learning method for improving the out-of-distribution generalization ability of graph encoders, aiming to enhance the generalization ability of graph neural network models in different distribution environments. Background Art

[0002] The problem of graph out-of-distribution generalization is receiving increasing attention. Its core goal is to maintain the robustness and generalization ability of the model in the case of distribution shift between training data and test data. Due to its wide value in practical applications such as social network analysis, bioinformatics, and financial risk control, it has become a research hotspot in the field of graph machine learning in recent years. Current research mainly relies on domain adaptation or invariance learning methods to reduce the differences between different data distributions. However, existing methods still face many challenges when dealing with complex distribution shift situations, especially when the attribute features and topological structures of graph data may change significantly in different environments.

[0003] Existing graph neural networks models face the following three core challenges in out-of-distribution generalization tasks:

[0004] 1. How to solve the problem of changes in graph attribute distributions? Under different data distributions, the same type of nodes or edges may have very different attributes. For example, in a protein-protein interaction network, the characteristics of some proteins in one experimental environment may be significantly different from those in another environment, making it difficult for the model to directly transfer. Existing methods usually rely on fixed attribute representation learning and are difficult to effectively handle this problem of attribute distribution shift.

[0005] 2. How to handle the distribution shift of graph structures? In different data environments, the topological structure of the graph often changes. For example, in a recommendation system, the connection pattern of the user-item interaction network may have different preference distributions due to changes in platforms or market trends. This structural heterogeneity affects the representation learning based on graph neural networks, making it difficult for the model to capture robust features across different environments. Existing methods often rely on fixed graph structures for training and lack the ability to adapt to different environments.

[0006] 3. How to efficiently integrate attribute information and structural information? The attribute information and topological structure of graph data have different degrees of contribution in the OOD generalization task, but existing methods usually adopt simple feature concatenation or weighted fusion methods, ignoring the changes in the importance of these two types of information in different environments. How to adaptively adjust the roles of attribute and structural information in different distributions is the key challenge to improving the generalization ability of the model.

[0007] In response to the above challenges, new solutions are urgently needed to better address cross-platform heterogeneity and make full use of multi-source information, promoting the development of the field of user identity association. Summary of the Invention

[0008] In view of the deficiencies of existing methods in out-of-distribution generalization ability, the present invention proposes a method for enhancing the generalization of graph encoders based on contrastive learning. This method aims to break through the limitation that traditional contrastive learning frameworks are difficult to effectively utilize environmental distribution information, thereby significantly improving the generalization ability of graph encoders, ensuring that they can still learn robust feature representations under different data distributions, and providing a systematic solution.

[0009] The technical solution of the present invention is a contrastive learning method for improving the out-of-distribution generalization ability of graph encoders. Through a positive sample matching module and a Mixup adjustment module, combined with dynamic data augmentation and an improved contrastive loss objective function, the graph encoder has good generalization performance in the out-of-distribution generalization problem.

[0010] The specific implementation steps are as follows:

[0011] S1 Positive sample matching: In view of the objectively existing environmental label attributes in out-of-distribution generalization data, the present invention proposes a method for generating view pairs in a contrastive learning framework based on the same task label but different environmental labels. Specifically, this method constructs positive sample pairs by randomly sampling samples in the training set and combining the information of task labels and environmental labels to improve the generalization ability of the model. In the design of the present invention, the sample data randomly sampled from the training set is represented as where the subscript a represents the task label of the sample, and the superscript 1 represents the environmental label of the sample. Taking the CMNIST dataset as an example, the numbers 0-9 are used as task labels, and the color of the numbers is used as the environmental label. Based on the above sampled samples, the positive sample matcher randomly samples another sample with the same task label a but different environmental label (such as environmental label 6) from the training set according to the information of task label a and environmental label 1 and combines it with to form a positive sample pair. Compared with the method of generating two views as positive sample pairs by data augmentation of a single sample in the traditional contrastive learning framework, the design of the present invention makes full use of the environmental distribution information in the out-of-distribution generalization task, thereby improving the adaptability and generalization ability of the model in different environments.

[0012] S2 Graph data augmentation: Through a series of preset graph data augmentation strategies, such as efficient and parallelizable methods like NodeDropping and Edge Perturbation, the positive sample pairs obtained in S1 Perform random data augmentation separately and obtain the augmented positive sample pairs Among them and respectively represent the graphs obtained after augmenting the original graph data. The significance of this step is to increase the diversity of training data and enhance the robust performance of the model. The present invention provides an optimization strategy based on graph data augmentation to improve the adaptability and robustness of the model to out-of-distribution generalization data. This method performs data augmentation on the positive sample pairs obtained in the S1 stage through a series of preset graph data augmentation strategies to enhance the diversity of training data. Specifically, this method adopts efficient and parallelizable graph data augmentation techniques such as Node Dropping and Edge Perturbation to perform random transformations on the positive sample pairs respectively, to obtain the augmented positive sample pairs Among them and respectively represent the original graph data and the new graphs generated after data augmentation.

[0013] S3 Graph Feature Representation Learning: The present invention follows the core idea of the traditional contrastive learning framework, that is, using a graph neural network model with shared weights (also known as a graph encoder) to perform feature encoding on the augmented sample pairs obtained in the S2 stage to achieve efficient graph feature representation learning. In this method, a Graph Isomorphism Network (GIN) is used as the graph encoder to extract the global feature representation of the graph. As a graph neural network with strong expressive power, GIN can effectively learn the embedding representation of the graph while maintaining the topological structure information. The specific feature extraction process follows the following mathematical expressions:

[0014]

[0015] where the H matrix is the matrix composed of the feature vectors corresponding to each node encoded by the graph neural network model, is the global graph representation obtained after the Readout operation. The Readout function can be aggregation functions such as mean, max, min, etc. For the sample pairs obtained in the S2 step we can obtain the graph feature representation pairs

[0016] S4 Mixup Adjustment: In the initial stage of training, the graph encoder may have difficulty effectively learning the sample features with the same task labels but different environmental labels, thus affecting the training effect of the model. For example, in the CMNIST dataset, since the color information of nodes is more easily captured by the encoder than the neighborhood relationship of nodes, it is difficult to directly reduce the feature distance between samples with different colors but the same number in the initial stage of training.

[0017] To solve this problem, the present invention proposes a training strategy of stepped learning, which is based on the Mixup technique and mixes the graph feature representations in the feature space to alleviate the optimization difficulty in the initial stage of training. Specifically, this method uses the Mixup technique to interpolate and mix the graph feature representations, and its calculation process is as follows:

[0018]

[0019] where λ mixup is a hyperparameter used to control the difficulty of learning. Initially, λ mixup takes a value greater than 0.5 and less than 1, and gradually decreases as the number of training epochs increases, thereby making gradually tend to After the above operations, we obtain a new pair of graph feature representations

[0020] S5 Optimization of the Contrast Loss Function: The present invention further enhances the ability of the graph encoder to encode graph feature representations with out-of-distribution generalization ability through a redesigned contrast loss objective function. The mathematical expression of the improved contrast loss function is as follows:

[0021]

[0022] where, l i represents the loss of the i-th sample when the mini-batch size is N, y i represents the label corresponding to the i-th sample (represented as a here), represents the feature representation of the i-th sample obtained by the GNN encoder after data augmentation, is the feature representation of the positive sample corresponding to the i-th sample obtained in S5, z b refers to all samples whose task labels are not a. In addition, τ represents the temperature parameter, and sim() represents the cosine similarity function. By performing the gradient descent optimization algorithm on the above contrast loss function, the encoding performance of the graph encoder can be trained.

[0023] Finally, the graph encoder trained by the present invention is capable of encoding graph feature representations with out-of-distribution generalization performance. This feature representation can be applied to a variety of practical scenarios and downstream tasks, such as protein function prediction with unknown distributions, social network user prediction, etc., providing support for the development of related services.

[0024] The present invention uses a positive sample matching module (Pair Selector Module) and a Mixup adjustment module (Mixup Scheduler Module) to train a graph encoder with out-of-distribution generalization ability using a graph contrastive learning framework. Finally, the present invention introduces an improved contrastive loss (Enhanced Contrastive Loss) as the learning objective and performs optimization of the graph feature representation (Optimization of Graph Feature Representation), so as to enable the graph encoder to also generate excellent graph feature representations for downstream tasks in out-of-distribution generalization scenarios. The present invention can provide excellent feature representations and generalization capabilities for downstream graph tasks.

[0025] The specific beneficial effects are as follows:

[0026] The contrastive learning framework of the present invention for improving the out-of-distribution generalization ability of graph neural networks can effectively solve the defects of traditional contrastive learning methods in the utilization of environmental information and improve the generalization ability of graph encoders in different distribution environments.

[0027] The present invention proposes a positive sample matching module. By establishing data pairs from different environmental distributions but with the same task labels, the model maintains consistency in the feature space, thereby making full use of environmental distribution information and improving the robustness of the model in out-of-distribution scenarios. The Mixup adjustment module adopts a segmented learning strategy, optimizing the learning process of the graph encoder through a feature mixing strategy at the initial stage of training to alleviate the optimization difficulty problem caused by differences in environmental label features. In addition, the present invention redesigned the contrastive loss objective. Combining the above optimization strategies, the graph encoder can continuously extract high-quality feature representations in out-of-distribution generalization tasks, improving the adaptability of downstream tasks.

[0028] The present invention significantly improves the feature learning ability of the graph neural network model in out-of-distribution generalization scenarios, enabling it to still have good generalization performance under different environmental distributions. The present invention can be used as a basic module and is widely applied to related tasks such as cross-domain graph data analysis, robust graph representation learning, and adaptive graph neural networks, providing a more generalizable feature representation scheme for downstream applications.

[0029] By performing gradient descent optimization algorithm on the above contrast loss function, the encoding performance of the graph encoder can be trained, and the graph encoder trained by the present invention has the ability to encode graph feature representations with out-of-distribution generalization performance. BRIEF DESCRIPTION OF THE DRAWINGS

[0030] Figure 1 This is the training model structure of the present invention.

[0031] Figure 2 This is the program flowchart of the present invention. DETAILED DESCRIPTION OF THE INVENTION

[0032] The present invention will be further described below with reference to the accompanying drawings.

[0033] S1 Positive sample matching: In view of the objectively existing environmental label attributes in out-of-distribution generalization data, the present invention proposes a method for generating contrast learning framework view pairs based on the same task label but different environmental labels. Specifically, this method constructs positive sample pairs by randomly sampling samples in the training set and combining the information of task labels and environmental labels to improve the generalization ability of the model. As Figure 1 shown, assuming the batch size is N and the input sample set is The positive sample matcher first parses the task label y i and environmental label e i of each sample. For example, for the sample it is parsed to obtain Subsequently, the positive sample matcher uses the random selection strategy (random.choice) in Python to process in parallel from the training set to obtain positive samples matching each input sample, forming a new sample sequence where for any sample pair it is required to satisfy and Finally, the positive sample matcher returns a sequence of matching sample pairs of length N:

[0034]

[0035] S2 Graph data augmentation: Through a series of preset graph data augmentation strategies, such as node dropping (NodeDropping), edge perturbation (Edge Perturbation) and other methods that can be efficiently processed in parallel, the sequence of positive sample pairs obtained in S1 is respectively subjected to random data augmentation processing, and an enhanced sequence of positive sample pairs is obtained. As Figure 1 shown, the node dropping operation randomly deletes any node in the graph. Specifically, the program determines how many nodes will be deleted in a data augmentation according to the preset hyperparameter aug_ratio. For any graph The node discarding operation randomly selects the index values of the nodes to be deleted, and then synchronously processes the node matrix V and the edge matrix E to achieve the node discarding operation. The same applies to edge perturbation. As Figure 1 shown, the node discarding operation aims to enhance the robustness of the graph by randomly deleting some nodes. Specifically: Let the graph where V is the set of nodes and E is the set of edges; Set the proportion of nodes to be deleted according to the hyperparameter aug_ratio; Randomly select the node indices that meet the proportion, and synchronously update the node matrix V and the edge matrix E to complete the node deletion operation. Similarly, the edge perturbation operation changes the topological structure of the graph by adding or deleting some edges, making the model more adaptable. Its specific steps are similar to the node discarding operation: Randomly select the edge indices to be perturbed; Determine the number of edges to be added or deleted according to aug_ratio; Synchronously update the edge matrix E to ensure the connectivity of the graph.

[0036] S3 Graph Feature Representation Learning: The present invention follows the core idea of the traditional contrastive learning framework, that is, using a graph neural network model with shared weights (also known as a graph encoder) to perform feature encoding on the augmented sample pairs obtained in the S2 stage to achieve efficient graph feature representation learning. In this method, a Graph Isomorphism Network (GIN) is used as the graph encoder to extract the global feature representation of the graph. Specifically, the GIN encoder consists of multiple GINConv computational levels, and each level contains the following core operations:

[0037] a) Linear transformation (nn.Linear): Perform a linear mapping on the input graph node features, and transform them into a high-dimensional feature space to enhance the feature expression ability;

[0038] b) Batch normalization (nn.BatchNorm1d): Normalize the mapped features to stabilize the training process and improve the training speed;

[0039] c) Nonlinear activation (nn.ReLU): Use ReLU as the activation function to introduce nonlinear features and enhance the expression ability of the model;

[0040] d) Multi-layer feature extraction (nn.Sequential): By stacking multiple GINConv structures, the graph encoder can capture deeper feature information, thereby extracting the global graph features.

[0041] After completing the node-level feature extraction, the present invention further introduces a Readout layer for obtaining the global feature representation of the graph. This layer uses the global_mean_pool aggregation function to globally summarize all node features. The specific steps are as follows: Assume that the node feature matrix after the GIN encoder is H = {h1, h2, …, h n}, where h i represents the feature vector of the i-th node, and n is the total number of nodes in the graph; the global_mean_pool aggregation function obtains the global feature representation according to the following formula

[0042]

[0043] The above process can process all input graphs of S2 in parallel and obtain the sample feature representation sequence

[0044]

[0045] S4 Mixup adjustment: The present invention proposes a training strategy of stepped learning, which is based on the Mixup technique and alleviates the optimization difficulty in the initial stage of training by mixing graph feature representations in the feature space. As Figure 1 shown, for each pair of sample feature pairs we can obtain a new fused feature according to the interpolation formula to replace and form a new sample feature pair Specifically, the hyperparameter λ mixup will be automatically adjusted according to the following rules:

[0046]

[0047] After the above operations, we obtain the new sample feature representation sequence after Mixup fusion

[0048]

[0049] S5 Contrast loss function optimization: The present invention further enhances the learning ability of the graph encoder for the graph feature representation with out-of-distribution generalization ability by redesigning the contrast loss objective function. The feature representation sequence obtained in S4 is used to calculate the loss of each sample to optimize the generalization effect of the model. In the process of similarity calculation, this method uses the torch.einsum function for efficient calculation and combines the mask technology to achieve parallel contrast loss calculation. Specifically:

[0050] Calculate the similarity matrix where S ijDenote the similarity between sample i and sample j;

[0051] Construct a mask matrix where M ij = 1 if and only if y i ≠ y j , that is, the task labels of the two samples are different, otherwise M ij = 0;

[0052] Apply the mask matrix to the similarity matrix through matrix multiplication S⊙M (Hadamard product) to effectively filter out sample pairs with the same task label, thereby ensuring that only the similarities between samples of different categories are calculated during the contrastive learning process and optimizing the training efficiency. The final total loss is jointly composed of the contrastive loss and the cross-entropy loss (CE loss) to ensure the stability and classification ability of the model in out-of-distribution generalization tasks.

[0053] The total loss expression is: L total = L contrastive + L CE , where represents the classification loss of the downstream task classifier. Through the optimization of the above total loss function, this method can synchronously optimize the performance of the graph encoder and the performance of the downstream task MLP classifier.

[0054] Figure 2 is the program flow chart of the present invention.

[0055] Finally, the present invention optimizes the feature learning mechanism of the graph neural network, enhances its adaptability in out-of-distribution generalization scenarios, and improves the robustness of feature representation through an adaptive contrastive learning strategy, significantly improving the generalization ability of the model under different environmental distributions. This technology can be used as a basic module and is widely applied to tasks such as cross-domain graph data analysis, robust graph representation learning, and adaptive graph neural networks, providing a more stable and generalizable feature representation scheme for downstream applications.

[0056] Here, three specific cases will be used to illustrate the application scenarios of the present invention:

[0057] (1) HIV is a real-world molecular dataset provided by MoleculeNet, containing 41,127 samples. Each sample is represented as a molecular graph, where nodes represent atoms and edges correspond to chemical bonds. The goal of this task is to predict the potential of molecules to inhibit the replication of the human immunodeficiency virus (HIV). In terms of domain division, HIV-scaffold uses the Bemis-Merck scaffold, which defines the two-dimensional structural core of the molecule. HIV-size divides the dataset based on the number of nodes in the molecular graph. Neither the above scaffold nor the size division method affects the assignment of task labels to molecules, so they can be used for dividing environmental labels to construct out-of-distribution generalization tasks.

[0058] (2) Motif is a synthetic dataset containing 30,000 samples, inspired by Spurious-Motif, and is designed to test the model's ability to handle structural changes. In this dataset, the only factor determining the label is a specific structure (motif). Motif-size divides the dataset for environmental labels according to the number of nodes.

[0059] (3) CMNIST is a semi-artificial dataset containing 70,000 samples for multi-class classification tasks. This dataset is converted from the MNIST database using hyperpixel technology. CMNIST-color divides the domain according to the colors of the nodes that make up the digits. This dataset is mainly used to test the ability of out-of-distribution generalization algorithms to handle feature shifts.

[0060] Table 1

[0061]

[0062] In the table, GCLOOD is the abbreviated name of the present invention, and its performance has been compared with many existing technologies on the dataset. Generally speaking, the present invention has achieved better performance than existing methods on multiple baselines, reflecting the technological progress of the present invention.

Claims

1. A contrastive learning method for improving the out-of-distribution generalization ability of graph encoders, characterized in that, Through the positive sample matching module and the Mixup adjustment module, combined with dynamic data augmentation and an improved contrast loss objective function, the specific implementation steps are as follows: S1 Positive sample matching: Randomly sample samples in the training set, and construct positive sample pairs by combining the information of task labels and environment labels; S2 Graph data augmentation: Through the graph data augmentation strategy, perform data augmentation on the positive sample pairs obtained in the S1 stage to improve the diversity of training data; S3 Graph feature representation learning: Follow the core idea of the traditional contrast learning framework, that is, use a graph neural network model with shared weights to encode the features of the augmented sample pairs obtained in the S2 stage to achieve efficient graph feature representation learning; S4 Mixup adjustment: Adopt a training strategy of stepped learning. Based on the Mixup technology, mix the graph feature representations in the feature space to alleviate the optimization difficulties in the initial stage of training; S5 Optimization of the contrast loss function: Further strengthen the ability of the graph encoder to encode graph feature representations with out-of-distribution generalization ability through a redesigned contrast loss objective function. The mathematical expression of the improved contrast loss function is as follows: where, l i represents the loss of the i-th sample when the mini-batch size is N, y i represents the label corresponding to the i-th sample (manifested as a here), represents the feature representation of the i-th sample obtained by the GNN encoder after data augmentation, is the feature representation of the positive sample corresponding to the i-th sample obtained in S5, z b refers to the samples of all task labels except a; in addition, τ represents the temperature parameter, and sim() represents the cosine similarity function; Train the encoding performance of the graph encoder through the gradient descent optimization algorithm for the above contrast loss function.

2. A contrastive learning method for improving the out-of-distribution generalization ability of a graph encoder according to claim 1, wherein The specific steps of S1 are as follows: The sample data randomly sampled from the training set is represented as where the subscript a represents the task label of the sample, and the superscript "1" represents the environmental label of the sample. Based on the above sampled samples, the positive sample matcher randomly samples another sample from the training set that has the same task label a but a different environmental label according to the information of the task label a and the environmental label "1". For example, the environmental label "6", and combines it with to form a positive sample pair 3. A contrastive learning method for improving the out-of-distribution generalization ability of a graph encoder according to claim 2, characterized in that, The specific steps of S2 are as follows: Using the graph data augmentation techniques of Node Dropping and Edge Perturbation, perform random transformations on the positive sample pairs respectively to obtain the augmented positive sample pairs Among them, and respectively represent the original graph data and the new graphs generated after data augmentation.

4. A contrastive learning method for improving the out-of-distribution generalization ability of a graph encoder according to claim 1, characterized in that In step S3, a graph isomorphism network is used as the graph encoder to extract the global feature representation of the graph. As a graph neural network with strong expressive ability, GIN can effectively learn the embedding representation of the graph while maintaining the topological structure information; The specific feature extraction process follows the following mathematical expression: where the H matrix is a matrix composed of the feature vectors corresponding to each node encoded by the graph neural network model, is the global graph representation obtained after the Readout operation, and the Readout function can be mean, max, or min aggregation functions; For the sample pairs obtained in step S2 Obtain the graph feature representation pairs 5. A contrastive learning method for improving the out-of-distribution generalization ability of a graph encoder according to claim 1, characterized in that, In step S4, the Mixup technology is used to interpolate and mix the graph feature representations, and its calculation process is as follows: where λ mixup The hyperparameter is used to control the difficulty of learning. Initially, λ mixup will take a value greater than 0.5 and less than 1, and gradually decrease as the number of training epochs increases, thereby making gradually tend to After the above operations, a new pair of graph feature representations is obtained

Citation Information

Cited By

  • Comparison learning molecular property prediction method based on anti-fact and large language model

    CN121506292A