A web API recommendation method based on graph diffusion reconstruction and graph contrastive learning
By employing graph diffusion reconstruction and graph contrastive learning methods, the problems of data sparsity and insufficient relation feature mining in Web API recommendation are solved, resulting in more accurate Web API recommendations.
Patent Information
- Application Number
- CN202411927582.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-25
- Publication Date
- 2025-11-07
- Estimated Expiration
- 2044-12-25
AI Technical Summary
Existing Web API recommendation methods suffer from poor recommendation performance due to data sparsity and insufficient relation feature mining.
We employ graph diffusion reconstruction and graph contrast learning methods. By constructing a Mashup-API call relationship graph, we expand the graph diffusion data and use adaptive graph reconstruction and Light GCN to generate node feature representation vectors. Finally, we generate a recommendation list based on the inner product.
It improved the accuracy of Web API recommendations, solved the problem of sparse historical interaction data, mined deep interaction information, and enhanced recommendation performance.
Smart Images

Figure CN120067432B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to computer technology, in particular to a Web API recommendation method based on graph diffusion reconstruction and graph contrastive learning. BACKGROUND
[0002] Web API (Web Application Programming Interface) is an API service provided through the network, which enables communication and interaction between different applications through providing a unified interface and flexible design style. Mashup is a web application development technology that can mix different types of Web APIs to build new applications. Web API recommendation technology can recommend high-quality Web APIs for Mashup developers from a large number of Web APIs, and is a research hotspot in the current software development field.
[0003] Existing Web API recommendation methods are mainly divided into Web API recommendation methods based on function description documents and Web API recommendation methods based on service history calling information.
[0004] Web API recommendation methods based on function description documents. This kind of method usually uses natural language processing technology to solve the similarity between function description documents to achieve service recommendation. Function description documents are usually manually written by developers, and may not fully and accurately describe the functions of the services. Some Web APIs even do not have function description documents, so the function description information is often not sufficient. In addition, due to the lack of unified specifications for service function description documents, there may be multiple descriptions for the same function, resulting in that the text similarity cannot well reflect the similarity in function. And this kind of method does not consider the interaction and cooperation information between services. Therefore, the method based on function description documents may make poor recommendations.
[0005] Web API recommendation method based on service history calling information. This kind of method usually uses the idea of collaborative filtering, first maps Mashup and API into vector representation, reconstructs the interaction between Mashup and API based on these vectors, and predicts the probability of Mashup calling API. This method considers the interaction information and cooperation information between services, and achieves good results. However, in the process of mapping services into vectors, many methods only focus on other services that have interacted with the service, extract features using direct interaction information between services, miss the mining of deep interaction information, lead to inaccurate feature extraction, and affect the recommendation effect; And this method depends on the historical calling data, however, some Mashup often only calls a small number of APIs, there is a problem of data sparseness, which affects the effect of the final recommendation; When extracting node features by neighborhood aggregation, the vector representation of nodes in the same neighborhood tends to be consistent, leading to the problem of data smoothing, which affects the diversity of node feature vectors and affects the recommendation effect.
[0006] In summary, most service recommendation methods first map Mashup and API into vector representation, predict the probability of Mashup calling API according to the vector representation, and then recommend API, which has the following shortcomings:
[0007] Affected by the problem of data sparseness. The method based on function description information depends on the function description document of the service to estimate the correlation between Mashup and Web API, while the function description document is often limited or even missing; The method based on interaction information depends on the historical interaction data between services to estimate the correlation between Mashup and Web API, due to the sparsity of historical interaction data, resulting in poor final recommendation effect.
[0008] The mining of relationship features is not sufficient. Most Web API recommendation methods only focus on the direct interaction relationship between services, miss the mining of deep interaction information, and there is a problem of data smoothing in feature extraction, leading to inaccurate feature extraction and affecting the recommendation effect. SUMMARY
[0009] The present application aims at the problem that the existing Web API recommendation method faces the problem of data sparseness and insufficient mining of relationship features between services, which leads to low recommendation performance, and proposes a Web API recommendation method based on graph diffusion reconstruction and graph contrast learning. The present application uses graph diffusion and adaptive graph reconstruction model to expand the Mashup-API calling relationship graph, solves the problem of sparsity of historical interaction data between Mashup and API, and improves the accuracy of recommendation.
[0010] The technical means adopted by the present application are as follows:
[0011] A Web API recommendation method based on graph diffusion reconstruction and graph contrastive learning, comprising the following steps:
[0012] S1, obtaining the historical calling information of Mashup and Web API, and constructing a Mashup-API calling relationship graph based on the historical calling information;
[0013] S2, performing graph diffusion-based data augmentation on the Mashup-API calling relationship graph to generate a diffusion matrix of Mashup-API calling relationship;
[0014] S3, reconstructing the diffusion matrix using adaptive graph reconstruction to generate a contrast view;
[0015] S4, obtaining the Mashup-API calling relationship graph and the contrast view, processing the Mashup-API calling relationship graph and the contrast view using the trained Light GCN as a basic graph encoder to generate a final feature representation vector of the node;
[0016] S5, ordering the APIs that meet the Mashup requirements based on the inner product between the feature representation vector of the Mashup node and the feature representation vector of the API node to generate a recommendation list.
[0017] Further, based on the historical calling information, the Mashup-API calling relationship graph is constructed, comprising:
[0018] S101, storing each Mashup and its API list in the form of a dictionary to obtain structured Mashup-API calling information;
[0019] S102, based on the structured Mashup-API information, regarding Mashup and API as nodes, and regarding the calling relationship between Mashup and API as edges, constructing a bipartite graph of the calling relationship between Mashup and API.
[0020] Further, the Mashup-API calling relationship graph is subjected to graph diffusion-based data augmentation to generate a diffusion matrix of Mashup-API calling relationship, comprising:
[0021] S201, representing the Mashup-API calling relationship graph as a sparse graph G:
[0022] G=(V,E),
[0023] wherein V represents a node set, including a Mashup node set M and an API node set N; E represents an edge set;
[0024] S202, convert the sparse graph G into an adjacency matrix A representation, the adjacency matrix A represents the connection relationship between nodes, wherein A[i][j] is 1, indicating that there is an edge between node i and node j, otherwise 0;
[0025] S203, add a self-loop to the adjacency matrix A, and calculate a symmetric transition matrix according to the adjacency matrix after adding the self-loop;
[0026] S204, generate a dense diffusion matrix by random walk on the symmetric transition matrix, and sparsify the dense diffusion matrix based on a preset threshold, thereby obtaining a final diffusion matrix.
[0027] Further, the symmetric transition matrix is generated into a dense diffusion matrix by random walk according to the following formula:
[0028] S=α(I-(1-α)T sym ) -1
[0029] Wherein, α is the probability of random walk, I is the unit matrix, T sym represents the symmetric transition matrix, and:
[0030]
[0031] Wherein, A loop represents the adjacency matrix after adding the self-loop, D loop represents the self-loop matrix, and:
[0032] D loop =diag(A loop ·1)
[0033] A loop =I+A
[0034] Wherein, 1 represents the all-one vector, and diag represents the diagonal matrix.
[0035] Further, the diffusion matrix is reconstructed by adaptive graph reconstruction, thereby generating a comparative view, including:
[0036] S301, extracting the relationship features in the diffusion matrix by using the graph convolutional neural network;
[0037] S302, calculating the distance of each feature Mashup i and each API j in the feature space according to the relationship features of the nodes;
[0038] S303, normalizing the node feature space distance by using the Sigmod function, mapping it between 0 and 1, and obtaining the distance factor θ ij ;
[0039] S304, filtering the distance factor based on a preset threshold, for reconstructing the Mashup-API relationship graph.
[0040] Further, the trained Light GCN is used as a basic graph encoder to process the Mashup-API calling relationship graph and the contrast view, to generate the final feature representation vector of the node, including:
[0041] S401, for the node in the graph, its representation in the l+1 layer is:
[0042]
[0043] wherein and respectively represent the feature vector of API i and the feature vector of Mashup j, l+1 represents the number of propagation layers, N j represents the set of APIs that have interacted with Mashup j, N i represents the set of Mashups that have interacted with API i, |N j represents the number of APIs in N j , |N i represents the number of Mashups in N i ;
[0044] S402, increase the depth of Light GCN, repeat S401 to obtain multiple feature representations of nodes in each layer {h 1 , h 2 ,..., h L};
[0045] S403, perform feature layer combination, superimpose multiple representations of nodes in different layers to obtain the final feature representation:
[0046]
[0047] wherein, h i and h j respectively represent the final feature representation vector of API i and Mashup j, L represents the depth of Light GCN; α l represents the importance parameter of the l-th layer embedding in the final embedding.
[0048] Further, the inner product between the feature representation vector of the Mashup node and the feature representation vector of the API node is calculated according to the following formula:
[0049]
[0050] wherein, h i and hj Let $\mashup_i$ and $\mashup_j$ represent the final feature representation vectors of $API_i$ and $Mashup_j$, respectively.
[0051] Furthermore, the Light GCN employs a joint training strategy during training, training the three sub-tasks—BPR loss, regularization loss, and contrastive loss—separately.
[0052] The objective function for the BPR loss subtask is:
[0053]
[0054] Where j represents the corresponding Mashup, i pos This indicates the API that has interacted with j, i neg This represents the API that has not interacted with j, Θ = {(j, i pos i neg )} represents paired training data. The symbol σ(·) represents the Sigmoid function, λ bpr The regularization strength parameter for BPR loss is used to control the tradeoff between fitting the training data and maintaining generalization ability.
[0055] The objective function of the regularization loss subtask is:
[0056]
[0057] Where, λ reg The regularization strength parameter represents the regularization loss, where n is the number of parameters in the Light GCN model, and ω is the regularization strength parameter. i It is the i-th parameter of the Light GCN model;
[0058] The objective function for the contrast loss subtask is:
[0059]
[0060] Among them, h and h c represents the feature representation vector of the node in the original image and the comparison view, respectively; sim(x,y) represents the cosine similarity between the two vectors x and y; and τ represents the temperature coefficient in the comparison learning.
[0061] Compared with the prior art, the present invention has the following advantages:
[0062] The application provides a Web API recommendation method based on graph diffusion reconstruction and graph contrast learning. BRIEF DESCRIPTION OF DRAWINGS
[0063] In order to make the technical scheme of the embodiments of the present application or the prior art clearer, the drawings needed in the embodiments or the prior art description will be briefly introduced below. Obviously, the drawings in the following description are some embodiments of the present application, and other drawings can be obtained by those skilled in the art without creative labor.
[0064] Figure 1 A flowchart of the Web API recommendation method based on graph diffusion reconstruction and graph contrast learning. DETAILED DESCRIPTION
[0065] In order to make the technical scheme of the embodiments of the present application or the prior art clearer, the drawings needed in the embodiments or the prior art description will be briefly introduced below. Obviously, the drawings in the following description are some embodiments of the present application, and other drawings can be obtained by those skilled in the art without creative labor.
[0066] As shown in Figure 1 The application provides a Web API recommendation method based on graph diffusion reconstruction and graph contrast learning, comprising the following steps:
[0067] S1, obtaining the historical calling information of Mashup and Web API, and constructing a Mashup-API calling relationship graph based on the historical calling information. Specifically, it comprises:
[0068] S101, storing each Mashup and its called API list in the form of a dictionary to obtain structured Mashup-API calling information.
[0069] The information of mashup and API is unstructured, and the original data information is preprocessed first in the application, the interaction information of mashup and API is extracted, and each mashup and the API list called by the mashup is stored in the form of a dictionary to obtain structured mashup-API calling information. The dictionary obtained after preprocessing is D={Mashup1:{API1,...,API k},...,Mashup m :{API i ,...,API j}} and the corresponding mashup set M:{Mashup1,Mashup2,...,Mashup m} and API set N:{API1,API2,...,API n}, where m is the number of mashups, n is the number of APIs, and each API can appear in the calling list corresponding to different mashups.
[0070] S102, based on the structured mashup-API information, the mashup and API are regarded as nodes, the calling relationship between the mashup and the API is regarded as an edge, and a bipartite graph of the calling relationship between the mashup and the API is constructed.
[0071] The interaction relationship is extracted from the structured mashup-API information, and the application constructs a bipartite graph of the calling relationship between the mashup and the API by regarding the mashup and the API as nodes and regarding the calling relationship between the mashup and the API as an edge. In this way, a mashup-API relationship graph represented as G=(V,E) is constructed, V represents the node set in the graph, including the mashup and the API, and E represents the edge set in the graph.
[0072] S2, the mashup-API calling relationship graph is subjected to data augmentation based on graph diffusion, thereby generating a diffusion matrix of the mashup-API calling relationship.
[0073] In order to improve the embedding quality of node feature extraction, graph contrast learning is a very effective solution, which generates contrast views by enhancing image data as auxiliary training signals, and participates in the training of the model together with the original data information. In combination with the data sparsity problem existing in the field of Web API recommendation, the application designs a contrast view generation method based on a graph diffusion model and adaptive graph reconstruction. This step is mainly used for relationship data augmentation based on a graph diffusion model. Specifically, it includes:
[0074] S201, the mashup-API calling relationship graph is represented as a sparse graph G:
[0075] G = (V, E),
[0076] where V represents a node set, including a Mashup node set M and an API node set N; E represents an edge set.
[0077] S202, convert the sparse graph G into an adjacency matrix A representation, which represents the connection relationship between nodes, where A[i][j] is 1, indicating that there is an edge between node i and node j, otherwise 0. The underlying facts are more complex than what the graph captures. For example, molecules can be described by a graph of atoms and bonds, but their potential interactions are much more complex. The graph diffusion convolution model aims to obtain the degree of influence of global node pairs on the target node by simulating the propagation of information, and capture the potential relationship between nodes. The present application uses a graph diffusion model as an encoder for graph reconstruction, to expand the receptive field of the node, so that it can consider the information of more distant neighbor nodes, which helps to learn more complex and global on the Mashup-API relationship graph, to deal with the problem of sparse data. Intuitively, first put all the attention on the target node, and then through the attention of the global propagation, the relationship between the target node and other nodes in the global is reconstructed. The final attention distribution defines the edges from the starting node to other nodes.
[0078] The core calculation of the graph diffusion model is shown in formula (1) and formula (2).
[0079]
[0080] T = AD -1 (2)
[0081] where T defines the transition matrix, D is a diagonal matrix, d ii = å j a ij ; θ k is a coefficient defined by a selectable specific diffusion variable. In this application, the personalized PageRank is used to define the diffusion variable.
[0082] S203, add a self-loop to the adjacency matrix A, and calculate a symmetric transition matrix according to the adjacency matrix after adding the self-loop.
[0083] Add a self-loop, and the calculation is shown in formula (3).
[0084] A loop = I + A (3)
[0085] where I is the identity matrix.
[0086] Calculate the symmetric transition matrix, as shown in formula (4) and formula (5).
[0087] D loop = diag(A loop ·1) (4)
[0088]
[0089] where 1 represents a full one vector, diag represents a diagonal matrix, D loop represents a self-loop matrix, and T sym represents a symmetric transition matrix.
[0090] S204, generating a dense diffusion matrix by random walk on the symmetric transition matrix, and sparsifying the dense diffusion matrix based on a preset threshold, to obtain a final diffusion matrix.
[0091] The random walk generates a diffusion matrix, and the core calculation is shown in formula (6).
[0092] S = a (I - (1 - a) T sym ) -1 (6)
[0093] where a is the probability of random walk. The calculated diffusion matrix S is a dense graph, and a threshold e is set to sparsify S to obtain a final diffusion matrix, which contains the reconstruction of Mashup-API long-distance relationships and underlying complex relationships.
[0094] S3, reconstructing the diffusion matrix by adaptive graph reconstruction to generate a contrast view. This step is mainly used for reconstructing the diffusion matrix based on an adaptive graph reconstruction model. The focus of adaptive graph reconstruction is mainly concentrated on the feature similarity between nodes, that is, the degree of similarity of node attributes. By analyzing and comparing node features, the relationship of the graph can be reshaped, so that the graph structure can more accurately reflect the actual similarity between nodes. The present application reconstructs the diffusion matrix S by adaptive graph reconstruction, so that the generated augmented graph is more in line with the original data distribution law. Traditional adaptive graph reconstruction models are mainly designed for isomorphic graphs. Based on the research on the graph generation model in the past, the present application designs an adaptive graph generation model for bipartite graphs, which is used for the recommendation model proposed in the present application, and specifically includes the following steps:
[0095] S301, extracting relationship features in the diffusion matrix by using a graph convolutional neural network.
[0096] S302, calculating the distance between each feature Mashup i and each API j in the feature space according to the relationship features of the nodes.
[0097] S303, normalizing the node feature space distance by using a Sigmod function, mapping it to between 0 and 1, and obtaining a distance factor θ ij .
[0098] S304, filtering the distance factor based on a preset threshold, for reconstructing the Mashup-API relationship graph. The calculation is as shown in formula (7), formula (8) and formula (9).
[0099]
[0100] wherein, and represent the feature vectors of API i and Mashup j respectively, K represents the dimension of the feature vector, represents the kth dimension value of , d ij is the distance of Mashup and API in the feature space, e ij is the edge between API i and Mashup j.
[0101] Based on the above, the comparative view generation algorithm based on graph diffusion reconstruction is shown in Algorithm 1.
[0102]
[0103]
[0104] S4, obtaining the Mashup-API calling relationship graph and the comparative view, using the trained Light GCN as a basic graph encoder to process the Mashup-API calling relationship graph and the comparative view, and generating the final feature representation vector of the node.
[0105] The adjacency matrix of the Mashup-API relationship graph and the comparative view contains the connection relationship between the nodes. The node features obtained by random initialization are used as the initial node representation. For the Mashup-API bipartite graph designed in the present application, Light GCN is used as a basic graph encoder, the message passing method of Light GCN adopts a simple adjacent matrix weighted sum, does not introduce additional parameters, mainly focuses on the message passing between nodes, and does not use node specific weight parameters, so as to focus on mining the deep interaction information between Mashup and API, and more accurately extract the relationship features between nodes. The same operation is performed on the input two views. Specifically, it includes:
[0106] S401, for the nodes in the graph, the calculation of the representation in the l+1 layer is as shown in formula (10) and formula (11).
[0107]
[0108] wherein and respectively, l+1 denotes the number of propagation layers, N j denotes the set of APIs that have interacted with Mashup j, N i denotes the set of Mashups that have interacted with API i, |N j denotes the number of APIs in N j denotes the number of Mashups in N i denotes the number of Mashups in N i .
[0109] S402, increase the depth of the Light GCN, repeat S401 to obtain multiple feature representations of nodes in each layer {h 1 , h 2 ,..., h L};
[0110] S403, perform feature layer combination, superimpose multiple representations of nodes in different layers to obtain the final feature representation, and calculate as shown in formula (12) and formula (13).
[0111]
[0112] wherein h i and h j respectively represent the final feature representation vectors of API i and Mashup j, L represents the depth of the Light GCN; α l denotes the importance parameter of the embedding of the lth layer in the final embedding, which can be regarded as a hyperparameter to be manually adjusted, or as a model parameter to be automatically optimized. In the experiments of the present application, good performance can be obtained by uniformly setting it to 1 / (L+1).
[0113] Further, the present application also provides a scheme for jointly training the Light GCN.
[0114] According to the joint training strategy, different subtasks are designed: BPR loss, regularization loss and contrast loss.
[0115] In the BPR loss, it is assumed that the observed interaction (compared with the unobserved interaction) should reflect a higher prediction value, and therefore better reflect the association relationship between services. The objective function is defined as shown in formula (14).
[0116]
[0117] wherein j represents the corresponding Mashup, i pos represents the API that has interacted with j, i negdenotes the API with no interaction with j, Θ = {(j, i pos , i neg )} denotes the pair training data. The symbol σ(·) denotes the Sigmod function, λ bpr is the regularization strength parameter of the BPR loss, which is used to control the trade-off between fitting the training data and maintaining the generalization ability of the model.
[0118] The regularization loss is a loss term used to control the model complexity and prevent overfitting. In machine learning and deep learning, the regularization loss is usually used together with the main task loss of the model to balance the relationship between fitting the training data and limiting the model complexity. By penalizing the size or distribution of the model parameters, the model is prevented from performing too well on the training data, leading to poor performance on unseen data. The calculation of the regularization loss function is shown in equation (15).
[0119]
[0120] wherein, wherein, λ reg is the regularization strength parameter of the regularization loss, n is the number of parameters of the Light GCN model, and ω i is the i-th parameter of the Light GCN model.
[0121] In order to train the encoder end-to-end and learn rich node and graph-level representations that are agnostic to downstream tasks, after obtaining the feature representations of the same node from the original graph and the contrast view, the present application uses a contrastive learning loss to maximize the consistency between them, considering the representations of the same node in different views as positive sample pairs and the representations of other nodes as negative sample pairs, maximizing the consistency between positive sample pairs and minimizing the consistency between negative sample pairs during training. The calculation of the contrastive loss function is shown in equation (16).
[0122]
[0123] wherein, h and h c represent the feature representation vectors of the node in the original graph and the contrast view, respectively, sim(x, y) represents the cosine similarity between two vectors x and y, τ represents the temperature coefficient in contrastive learning, which is an important parameter in contrastive learning and affects the ability of the model to learn features and distinguish positive and negative samples. The temperature coefficient is an adjustment parameter in contrastive learning, which controls the sensitivity of the model to positive and negative samples. When the temperature coefficient is large, dividing by the temperature coefficient can reduce the discrimination of positive and negative samples, making the model less sensitive to positive and negative samples. When the temperature coefficient is small, the discrimination of positive and negative samples is amplified, making the model more sensitive to positive and negative samples. Selecting the appropriate temperature coefficient is crucial to the effectiveness of contrastive learning.
[0124] The Adam optimizer is used to adjust the model and update the model parameters.
[0125] In summary, the joint training process of the Web API recommendation model is shown in Algorithm 2.
[0126]
[0127]
[0128] S5, based on the inner product between the feature representation vector of the Mashup node and the feature representation vector of the API node, the API meeting the Mashup requirement is ranked, thereby generating a recommendation list.
[0129] After obtaining the final node features of Mashup and API, the recommendation score prediction is used. The present application adopts inner product to predict the score of candidate API and Mashup, and the calculation is shown in formula (17).
[0130]
[0131] Where j and i represent Mashup and API respectively, h j and h i respectively represent the feature vectors of j and i.
[0132] In order to obtain the final recommendation result, it is necessary to sort the matching score list of Mashup requirement and each Web API in descending order of matching score, and select the top K Web API to form the final recommendation list, wherein K is the recommended number which can be arbitrarily set.
[0133] In order to verify the effectiveness of the proposed method, the present application selects MF (Matrix Factorization), NGCF, GFormer and AdaGCL as baseline methods, and carries out experiment comparison on public data set, and shows the experimental effect through two widely used evaluation indexes.
[0134] (1) Data set
[0135] The experiments of the present application use the most popular online Web API repository PrgrammableWeb (PW) to evaluate the effectiveness of the model. PW is a website that collects metadata about Web APIs and the corresponding applications (e.g. Mashups) that use them. All Web APIs and Mashups are scraped from PW and the interaction information between Web APIs and Mashups is analyzed. This dataset includes 21900 APIs, 6435 Mashups and 13340 interactions between Mashups and APIs. To perform the evaluation, the present application removes Mashups that do not interact with any API and APIs that do not interact with any Mashup, leaving 6298 Mashups and 1069 APIs. Finally, 70% of the interaction records are used as the training set and the remaining 30% are used as the test set.
[0136] (2) Baseline method
[0137] To verify the effectiveness of the method proposed by the present application, the present application performs a comparative test using four advanced methods in the field of Web API recommendation, which include MF, NGCF, GForme and AdaGCL.
[0138] MF: is a ranking-oriented recommendation algorithm proposed for implicit feedback scenarios. This method decomposes a high-dimensional rating matrix into the product of two low-dimensional matrices, thereby capturing the latent features between Mashups and APIs. This method explores the direct interaction of nodes on the Mashup-API bipartite graph (first-order connectivity) and performs API recommendation based on the interaction features.
[0139] NGCF: is a neural network-based collaborative filtering algorithm that models the interaction relationship between Mashups and APIs through a graph neural network. This model uses hidden layers to map the IDs of Mashups and APIs to obtain initialization vectors, and uses the Mashup-API interaction matrix to achieve high-level information interaction and information transmission to obtain the final feature vector, and performs API recommendation based on the feature vector.
[0140] GFormer: is a recommendation model that combines graph neural networks and Transformer structures. The main idea of this model is to apply the attention mechanism of Transformer to graph neural networks to capture long-range dependencies in graph structured data. And based on SSL to automate the self-supervised enhancement process, extract the interaction patterns of Mashup-API and perform API recommendation.
[0141] AdaGCL: a graph representation learning and recommendation method that combines contrastive learning and graph generation techniques. The model uses VGAE and a Gaussian denoising model as a contrastive view generator to generate contrastive views for graph contrastive learning, extracts features using GCN, and performs API recommendation.
[0142] (3) Evaluation index
[0143] In the experiment, the widely used Recall@N and NDCG@N are used to evaluate the effectiveness of the proposed method and the baseline method, which will be introduced respectively.
[0144] Recall@N: represents the proportion of marked items listed in the top N recommendation list, calculated as shown in formula (18).
[0145]
[0146] NDCG@N: a standard for measuring the ranking quality of a recommendation list, considering the hierarchical correlation between positive and negative items in the top N ranking list. The calculation is shown in formula (19).
[0147]
[0148] where S m represents the ideal maximum DCG score that can be achieved for m.
[0149] (4) Experimental environment
[0150] The experimental hardware environment of the present application is a server with NVIDIA GeForce RTX3090; the software environment is Python3.7, and Pytorch is used as a deep learning framework to build a neural network. The embedding size of all models is fixed at 64, and the model depth is set to 5. In the model training stage, the Adam optimizer is used for model optimization, where the batch size is fixed at 512 and the learning rate is set to 0.001.
[0151] (5) Experimental results and comparative analysis
[0152] The proposed service recommendation method (Ours) is compared with four baseline methods in the experiment to verify the effectiveness of the proposed method. Table 1 shows the comparative experimental results of the proposed method and other baseline methods on the PW dataset.
[0153] Table 1 Comparative experimental results on the PW dataset
[0154]
[0155] According to Table 1, it can be seen that the method proposed in the application is always better than the baseline in all cases. More specifically, in the Recall@N index, the method of the application increases the best baseline by 18.14% in comparison; in the NDCG@K index, the method proposed in the application increases the best baseline by 14.28%.
[0156] Among them, the performance of MF is the worst, and the model only explores the first-order interaction relationship of nodes on the Mashup-API bipartite graph. Compared with NGCL, GFormer and AdaGCL show better performance, and both of them are recommendation models based on information network embedding and contrast learning. The node embedding of Mashup and Web API entities is obtained by using the designed contrast view generation method and specific graph neural network model. However, compared with the model proposed in the application, these two models do not work well, because they have deficiencies in data expansion and feature extraction. GFormer uses the global attention mechanism of graph Transformer for feature extraction, but its network structure is too complex, which will introduce more noise in the process of feature extraction. AdaGCL lacks high-order information interaction when expanding data and extracting features. Experiments show that the method of the application can reasonably expand data and accurately extract the relationship features of Mashup and Web API, thereby improving the Web API recommendation effect.
[0157] Finally, it should be noted that: the above embodiments are only used to illustrate the technical solutions of the application, and not to limit them; although the application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that they can still modify the technical solutions recorded in the foregoing embodiments, or make equivalent replacement for part or all of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the scope of the technical solutions of the embodiments of the application.
Claims
1. A Web API recommendation method based on graph diffusion reconstruction and graph contrastive learning, characterized in that, The method comprises the following steps: S1, obtaining historical calling information of Mashup and Web API, and constructing a Mashup-API calling relationship graph based on the historical calling information; S2, performing data expansion based on graph diffusion on the Mashup-API calling relationship graph, thereby generating a diffusion matrix of the Mashup-API calling relationship, comprising: S201, representing the Mashup-API calling relation graph as a sparse graph G : G =(V, E) , wherein V represents a set of nodes, including a set of Mashup nodes M and a set of API nodes N ; E represents a set of edges, S202, Sparse graph G Transform into an adjacency matrix A Representation, adjacency matrix A This represents the connection relationship between nodes, where A [i][j] A value of 1 indicates a node i and nodes j If an edge exists, then the value is 0; otherwise, the value is 0. S203, adding a self-loop to the adjacency matrix A, and calculating a symmetric transition matrix according to the adjacency matrix after the self-loop is added, S204, generating a dense diffusion matrix through random walk on the symmetric transition matrix, and sparsifying the dense diffusion matrix based on a preset threshold, thereby obtaining a final diffusion matrix; S3, reconstructing the diffusion matrix through adaptive graph reconstruction, thereby generating a comparison view, comprising: S301, extracting relationship features in the diffusion matrix through a graph convolutional neural network, S302、Calculate each feature Mashup according to the relationship characteristics of the nodes i and each API j distance in feature space, S303、Utilize Sigmod function to normalize node feature space distance, map to 0 and 1 between, obtain distance factor , S304, screening distance factors based on a preset threshold, which are used for reconstructing the Mashup-API relationship graph; S4, obtaining the Mashup-API calling relationship graph and the comparison view, processing the Mashup-API calling relationship graph and the comparison view by using a trained Light GCN as a basic graph encoder, and generating a final feature representation vector of a node; S5, ordering APIs meeting Mashup requirements based on an inner product between a feature representation vector of a Mashup node and a feature representation vector of an API node, thereby generating a recommendation list.
2. The Web API recommendation method based on graph diffusion reconstruction and graph contrastive learning according to claim 1, characterized in that, The method comprises the following steps: S101, storing each Mashup and a list of APIs called by the Mashup in the form of a dictionary to obtain structured Mashup-API calling information; S102, regarding the Mashups and the APIs as nodes and regarding calling relationships between the Mashups and the APIs as edges, and constructing a bipartite graph of calling relationships between the Mashups and the APIs based on the structured Mashup-API information.
3. The Web API recommendation method based on graph diffusion reconstruction and graph contrastive learning according to claim 1, characterized in that, The symmetric transition matrix is subjected to random walk to generate a dense diffusion matrix according to the following formula: wherein is the probability of a random walk, I is the identity matrix, denotes a symmetric transition matrix and: wherein, denotes the adjacency matrix after adding self-loops, denotes the degree matrix, and: where 1 denotes an all-one vector, diag denotes a diagonal matrix.
4. The Web API recommendation method based on graph diffusion reconstruction and graph contrastive learning according to claim 1, characterized in that, The method comprises the following steps: S401、For the nodes in the figure, it is in the first Layer of representation: wherein and respectively represent the feature vector of API i and the feature vector of Mashup j , l +1 represents the number of propagation layers, represents the set of APIs that have interacted with Mashup j , represents the set of Mashups that have interacted with API i , represents the number of APIs in , the number of Mashups in S402, increase the depth of Light GCN, repeat S401 to obtain multiple feature representations of nodes in each layer ; S403, performing layer combination of features, superimposing multiple representations of a node at different layers, and obtaining a final feature representation: wherein, and respectively represent the API i and Mashup j final feature representation vector, L denotes the depth of the Light GCN; denotes the importance parameter of the embedding of the l layer in the construction of the final embedding.
5. The Web API recommendation method based on graph diffusion reconstruction and graph contrastive learning according to claim 1, characterized in that, The inner product between the feature representation vector of the Mashup node and the feature representation vector of the API node is calculated according to the following formula: wherein, and respectively represent the API i and Mashup j final feature representation vector.
6. The Web API recommendation method based on graph diffusion reconstruction and graph contrastive learning according to claim 1, characterized in that, The Light GCN adopts a joint training strategy during training, and trains three subtasks of BPR loss, regularization loss and contrast loss respectively, The objective function of the BPR loss subtask is: wherein, j represents the corresponding Mashup, represents the API, j with which the Mashup has interacted, represents the API, j with which the Mashup has not interacted, represents the pair-wise training data, the notation represents the function, is a regularization strength parameter for the BPR loss, used to control the trade-off between fitting the training data and preserving the generalization ability of the model; The objective function of the regularization loss subtask is: wherein, denotes a regularization strength parameter for the regularization loss, is the number of parameters of the Light GCN model, is the i-th parameter of the Light GCN model, is the i-th parameter of the Light GCN model. The objective function of the contrast loss subtask is: where, and denote the feature representation vectors of a node in the original and contrast views, respectively, denotes the cosine similarity between two vectors and denotes the temperature coefficient in contrast learning.
Citation Information
Patent Citations
Web API recommendation method based on correlation and compatibility fusion
CN117743678A
Project recommendation method based on graph contrast learning
CN118133882A